Join multiple PDF files into a single page PDF - positioned join using PHP [closed]

倖福魔咒の 提交于 2019-12-06 22:36:54

问题


This is not an attempt to join separate PDFs to one single PDF with multiple pages. It is an attempt to create a single page PDF from few other PDFs that already exists. I need to do this using PHP and the server is CentOS.

I am already generating a set of single page PDF files based on individual templates (Using FPDF). The requirement is to allow the user to mix and match existing PDF files and position them together to create a single PDF.

My current attempt is to convert the PDFs to images (using ghostscript) and use the output jpegs to create the final PDF using FPDF. While this is possible, the quality of the PDF is compromised a little during conversion.

I would like to know if there is a better solution that we can use?

UPDATE

The solution doesn't have to be PHP. It most probably wont be. I'm certainly up for any commandline tool that can do the job. Example command would be as follows:

$ newtool -o outfile.pdf -s WidthXHeight -i in1.pdf in2.pdf in2.pdf -g p1Xp2 p3Xp4 p5Xp6

Above is an example only - not a real command - I just wish if a tool has that kind of functionality. Specify set of input files and their positions on the output file.


回答1:


I've done this in the past with a combination of Ghostscript (to position an existing PDF page on a larger empty PDF page) and pdftk (to overlay/merge two equally-sized PDF pages into a new one).

Have a look at these answers (@Superuser.com) to get an idea how this works:

  • Convert PDF 2 sides per page to 1 side per page
  • Using Ghostscript to convert multi-page PDF into single JPG?
  • Freeware to split a pdf's pages down the middle?

My procedure uses commandline and/or scripts. However, this could also be extended to do it programmatically from PHP with the Ghostscript .dll/.so



来源:https://stackoverflow.com/questions/8589593/join-multiple-pdf-files-into-a-single-page-pdf-positioned-join-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!