fpdf

fpdf fpdi 操作pdf文件 写入中文汉字

徘徊边缘 提交于 2020-08-11 04:31:25
  今天给公司做一个线上合同签约功能,用户签约后 生成pdf版的文件 。网上搜了搜大概都是用fpdf进行操作的 , 通过fpdi 可以进行读取pdf模板。 在通过继承fpdf 操作现有的pdf文档 。 功能很简单,用户手写用页面canvas生成图片,图片保存png到服务器 。然后粘贴图片到对应的pdf模板上。 但是在实际操作上就出现了问题。国外的fpdf 对中文支持并不是很好,在pdf上加入中文汉字的时候,会出现乱码。 而且他只提供文件夹中的几种字体。而且这几种字体都是英文字体,所以无法正常支持汉字的写入。 下面说一下具体的解决方案: 1. https://github.com/DCgithub21/cd_FPDF 下载代码  2. 将上一步的源码放入vendor中 3. 修改composer源码 修改 fpdi中的 fpdfTpl.php 将他基础的fpdf类改成 咱们刚才引入的代码 而之前引入的代码再继承fpdf   4.编写相关代码    /* * * 合成pdf * @param $sgin_img * @param $order_sn * @return string * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException * @throws \setasign\Fpdi

tFPDF generates an empty pdf file

浪子不回头ぞ 提交于 2020-05-29 13:04:48
问题 I am trying to generate a PDF file in PHP using the tFPDF library. I started with FPDF and it worked fine except that the UTF-8 characters were garbled. After some searching, I found that one could implement tFPDF to include UTF-8 characters in a PDF file. But all my attempts have resulted in an empty file that cannot be opened--0 KB file written to my hard drive and "There's a problem with the file format" message when I double click it. Here is my code. I'm getting no PHP errors in the

tFPDF generates an empty pdf file

安稳与你 提交于 2020-05-29 13:01:51
问题 I am trying to generate a PDF file in PHP using the tFPDF library. I started with FPDF and it worked fine except that the UTF-8 characters were garbled. After some searching, I found that one could implement tFPDF to include UTF-8 characters in a PDF file. But all my attempts have resulted in an empty file that cannot be opened--0 KB file written to my hard drive and "There's a problem with the file format" message when I double click it. Here is my code. I'm getting no PHP errors in the

Background Color inside a cell is not changing in fpdf

大城市里の小女人 提交于 2020-05-23 12:56:04
问题 Im using fpdf to generate a pdf file for my reports and Im new to this. I want to change the fill color inside a cell but whenever I reloaded the page, nothing hapeens, It still the same white fill color. Here is my code : <?php require("fpdf/fpdf.php"); $pdf = new FPDF('P','pt','Letter'); $pdf->SetFillColor(230,230,230); $pdf->SetTitle("Title Here"); $pdf -> AddPage(); $pdf -> SetFont('Arial','',12); ?> What is wrong with my code? I followed the proper way of setting the fill color but

FPDF: Output PDF using AJAX

一笑奈何 提交于 2020-04-30 07:47:52
问题 I have a PHP file where I generate a PDF file using FPDF. If I execute that file, it generates and loads the pdf file on browser. However when I try to generate the PDF file using a button and by using AJAX it does not work. I am using AJAX since I need to post some variables to PHP to make a query in the database before generating the PDF file. I looked for solutions on internet but I still do not know how to achieve this. I want to load the pdf on browser, not download it PHP: $pdf->Output(

FPDF: Output PDF using AJAX

血红的双手。 提交于 2020-04-30 07:44:31
问题 I have a PHP file where I generate a PDF file using FPDF. If I execute that file, it generates and loads the pdf file on browser. However when I try to generate the PDF file using a button and by using AJAX it does not work. I am using AJAX since I need to post some variables to PHP to make a query in the database before generating the PDF file. I looked for solutions on internet but I still do not know how to achieve this. I want to load the pdf on browser, not download it PHP: $pdf->Output(

PDF.js实现在线展示pdf文件

久未见 提交于 2020-04-09 19:42:38
PDF.js是一个使用HTML5构建的可移植文档格式库。 PDF.js官网: http://mozilla.github.io/pdf.js/ 下载下来的压缩包包含两个文件夹:build和web,打开web文件夹下的viewer.html,就能看到PDF的预览效果了。 预览的PDF文件是位于viewer.html同目录下的compressed.tracemonkey-pldi-09.pdf, 而设置加载这个文件的地方是:与viewer.html同目录下的viewer.js的DEFAULT_URL属性,修改这个属性的值就能够预览不同的文件,中英文的pdf文件都能成功预览。 中文展示:修改viewer.html中的文件 <link rel="resource" type="application/l10n" href="locale/zh-CN/viewer.properties"> 需要添加MIME,否则会报404 .net core 添加方式 修改 Configure 中的 UseStaticFiles //添加MIME var provider = new FileExtensionContentTypeProvider(); provider.Mappings[".properties"] = "application/octet-stream"; app

用Python将多张图片合并成一PDF文件

懵懂的女人 提交于 2020-02-27 12:42:47
先前条件 需要安装两模块: fpdf 、 PIL pip install fpdf pip install PIL 放码过来 from fpdf import FPDF from PIL import Image import os def makePdf(pdfFileName, listPages): cover = Image.open(listPages[0]) width, height = cover.size pdf = FPDF(unit = "pt", format = [width, height]) for page in listPages: pdf.add_page() pdf.image(page, 0, 0) pdf.output(pdfFileName, "F") makePdf("result.pdf", [imgFileName for imgFileName in os.listdir('.') \ if imgFileName.endswith("png")]) 参考文献 Create PDF from a list of images 来源: oschina 链接: https://my.oschina.net/jallenkwong/blog/3163725

Multiple PDFs in Loop with FPDF

試著忘記壹切 提交于 2020-02-07 12:26:35
问题 I have a FDPF function that creates a standard PDF for various parts of the website. It simply takes some data in, creates a multi page PDF and returns the PDF object e.g. function pdfBuild($orderData) { class PDF extends FPDF { // Page header function Header() { // Logo $this->Image('logo.png',10,6,30); // Arial bold 15 $this->SetFont('Arial','B',15); // Move to the right $this->Cell(80); // Title //$this->Cell(80,10,'Game Sheet',1,0,'C'); // Line break $this->Ln(20); } // Page footer

Multiple PDFs in Loop with FPDF

怎甘沉沦 提交于 2020-02-07 12:21:56
问题 I have a FDPF function that creates a standard PDF for various parts of the website. It simply takes some data in, creates a multi page PDF and returns the PDF object e.g. function pdfBuild($orderData) { class PDF extends FPDF { // Page header function Header() { // Logo $this->Image('logo.png',10,6,30); // Arial bold 15 $this->SetFont('Arial','B',15); // Move to the right $this->Cell(80); // Title //$this->Cell(80,10,'Game Sheet',1,0,'C'); // Line break $this->Ln(20); } // Page footer