Create new PDF from existing PDF with PHP

Asked

Viewed 2,162 times

3

I’m with a project that I need to add header/footer/watermark, dynamically in existing PDF files, via PHP language.

I’ve done a lot of research and I still can’t find a way to do this.

You can edit existing PHP Pdfs and add information?

Or, it would be possible to create a new PDF, through an existing one, and so be able to edit the contents of this new PDF?

Another way I thought would be to transform the existing PDF into HTML and then turn this HTML into a new PDF with the header/footer/watermark.

  • 1

    That’s a lot of questions in one question, but that’s okay. Well, I want to tell you that 60% of you crave cannot. There are several PHP classes that handle Pdfs. You can create PDF, but editing PDF might be a long way. It depends a lot on what editing pdf means. Creating a footer for example could be relatively easy, but changing a text in the pdf will depend on many factors, starting with the way this PDF was created. Look at this example

  • I don’t know if it’s possible either, but try to see mPDF https://github.com/mpdf/mpdf

  • 1

    If they are not too complex, perhaps the quickest is to simulate/recreate these existing HTML pdfs...

  • Yes @brasofilo, there are several possibilities, only it needs to be clearer what it means edit a pdf.

  • @durtto, I imagine there is not much mystery, means do what Acrobat Pro or Nitro PDF do: open a PDF and paste/remove elements and record a new one. I don’t think it’s "too many questions in one", for me it’s clear: how to open an existing PDF, paste a header and footer, record a new PDF.

  • 1

    http://stackoverflow.com/questions/12510117/using-fpdf-to-modify-existing-pdf-in-php

  • Guys, I managed to solve my problem with what was posted by @durtto using the FPDF and FPDI libraries. Thank you all! Example: https://rubayeet.wordpress.com/2010/02/modifying-pdf-files-with-php/

  • The @Daniel Omine link also helped me! Thank you!

  • This is really good. Willian, so now I’m going to turn my comment into an answer and if you think it was an answer to your question, mark it as accepted. It was a pleasure to help.

Show 4 more comments

1 answer

2


That’s a lot of questions in one question, but that’s okay. Well, I want to tell you that 60% of what you want is not possible. There are several PHP classes that deal with Pdfs. You can create PDF, but editing PDF might be a long way. Depende muito do que significa editar pdf. Creating a footer for example could be relatively easy, but changing a text in the pdf will depend on many factors, starting with the way this PDF was created. Look at this example

Browser other questions tagged

You are not signed in. Login or sign up in order to post.