Add barcode to PDF

1.5k Views Asked by At

How can I add PDF417 2-D barcode (as an image) to a Acroform PDF?

  • I have a process in place where I populate a PDF "templates" with data using a XFDF file that I build server side. Staying in the same workflow, I'd like to either use XFDF or FDF files to add a barcode to the PDF.

  • I'm using full-stack JavaScript environment, where the Nodejs environment runs server side. I'm using PDFTK Server (JavaScript on the server calling out to a PDFTK.exe).

  • I can use any tool/technique within my technology stack (Nodejs/Javascript). Also, this solution must work server side only.

  • The PDF "template" currently uses a Adobe Lifecycle "Paper Forms Barcode" control for the barcode. When we fill this PDF form out with data manually, the XFA script embedded within the PDF automatically populates the "Paper Forms Barcode" control with the PDF417 barcode.

  • When I run PDFTK Server's form fill command to populate the PDF with the XFDF data I build server side, I believe the XFA (and hence any intelligence behind the "Paper Forms Barcode" control) is automatically removed from the resulting output PDF.

  • I can optionally remove the "Paper Forms Barcode" control and use any other control available.

  • pdf417-js seems to get my close to building a PDF417 barcode, but it's client side. And also, I can't see a way to build an image output.

  • From my research it seems I might need to remove the existing "Paper Forms Barcode" control and add an image somehow to the PDF. Then possibly use PDFTK to somehow merge a PDF that I have filled with data from my existing process with another PDF that simply has the barcode.

  • I never seen an example of XFDF or FDF inserting an image into the PDF. I've read where one can dynamically add an image (icon) to a button control via FDF (I've found no hard example of this), but haven't been able to get anything working.

2

There are 2 best solutions below

8
On

FDF does support inserting images as icons into Button fields. I am, however, not sure whether XFDF does it. You may have to convert the image into PDF format.

For an industrial-strength use, you might consider dedicated tools, such as FDFMerge by Appligent (which would also allow to selectively flatten the barcode field (and others too)).

0
On

Both FDF and XFDF support adding images to PDF pages. Some background first, Adobe Acrobat and Reader can submit form data as well as comment annotations. It can also import form data as well as comment annotations. Therefore, FDF and XFDF can represent both form data and comment annotations.

Images can be added to a PDF via FDF or XFDF by representing them as a stamp annotation. Acrobat can certainly import these but most server tools don't know about the <annots> element of the XFDF and even if they did, they generally can't create an annotation appearance based on the annotation properties. One can; the Datalogics PDF Java Toolkit is capable of importing XFDF with stamp annotations.