1

I've been looking for and trying solutions for 2 days now. Can't seem to find anything that works.

Problem: Given a fillable PDF, I need to take data from a database and put it into the pdf, then allow the user to download it.

Context:

  • The PDF is the same every time (So I can do manual manipulations to it initially if necessary to make it work)
  • The PDF has checkboxes
  • This needs to run in an alpine 3.16 docker container
  • Using PHP 8.1
  • Rebuilding the entire PDF with the data in it each time is not an option.
  • I can't include the specific PDF here, but there's nothing special about it. Just a fillable pdf with text inputs and checkboxes.

Solutions I've Tried/Seen:

  • Dompdf: Not for filling. Only creates
  • Setasign/FPDI: Imports the template pdf, but doesn't have filling functionality
  • SetaPDF-FormFiller: Probably works. Crazy expensive for what is a relatively small, but necessary, part of this app.
  • tecnickcom/TCPDF: Not for filling. Only creates
  • pdftk (Server): Testing this locally works. Unfortunately there doesn't seem to be a way to get it on an alpine container.
  • pdftk-java: Haven't tested yet. Installing java on every pod just for this feature is a last-ish resort.
  • mikehaertl/php-pdftk: PHP wrapper for pdftk. Same core problem of not being able to get it on alpine.
  • FPDF: Doesn't support checkboxes
  • codeshell/fpdm: Based on FPDF. Supports checkboxes, but it's broken as of PHP 8.1. Hasn't been updated in 4 years. Relevant issue
  • Use an image: I could convert the PDF to an image, position text over the image at certain places, save the image, and convert back to pdf. This removes all "form" functionality from the pdf that gets downloaded, and ideally the user should still be able to edit the downloaded PDF.

Any help would be appreciated. As I mentioned, this is a small, but necessary part of the app, so I'm trying to find a solution that's proportionate.

Dylan Buth
  • 1,648
  • 5
  • 35
  • 57
  • I have a very similar use case and use pdftk wrapper from mikehaertl. I works perfect for me, filling a PDF template with data, but i do not have the Alpine requirement like you have. What about considering another dist if its really a necessary feature? Especially if you use docker, the advantage is, that pdftk can live in its own container/environment ... just orchestrate it properly – Jim Panse Mar 01 '23 at 15:28
  • @JimPanse That my be the direction that we end up going. I just keep going back to, this is adding way more complexity to the app, than the feature is worth. At the end of the day, we need it, so we have to do something, it just feels like there should be a simpler solution. – Dylan Buth Mar 01 '23 at 15:34
  • 1
    My personal experience is, that in most cases it's not more effort to setup a "service" container maintaining your PDF creation and design an interface that is general ... also if it's not embed in your PHP app, it's also more flexible since its interchangeable with other implementations ... – Jim Panse Mar 01 '23 at 16:20

0 Answers0