How to convert a PDF with a filled form to a JPEG image using ImageMagick and preserving the form data?

StackOverflow https://stackoverflow.com/questions/20156293

Pergunta

I'm trying to convert this PDF to a JPEG image via ImageMagick (v 6.8.7-0): https://dl.dropboxusercontent.com/u/10351891/cd.pdf

I didn't find any working solution to preserve the filled data inside the PDF. This is one of the commands tried:

convert -colorspace CMYK -alpha off -interlace none -density 300x300 -quality 100 cd.pdf[0] cd_image.jpg

Since ImageMagick use Ghostscript for the conversion I've also update it to the last version (v 9.10) but nothing changed.

The command always print out a few warnings:

"Warning: considering '0000000000 XXXXX n' as a free entry"

"/BBox has zero width or height, which is not allowed."

Did someone find a way to convert it?

More information:

I used Preview for Mac to fill out the form.

On production, we use Ubuntu not Mac OS X and the PDF is not filled by me, but It's sent to us prefilled

Foi útil?

Solução

It is a known issue that Max OS X PDF Preview does not support AcroForms properly, see this blog post that contains some details: Script to Fix Mac OSX Preview.app Form Fill and Save.

Among other errors, your PDF form fields have a missing piece of information: the appearance stream (a set of instructions that tell the viewer how the field value is supposed to be rendered when it is not being edited).

If you can specify which PDF viewer should be used for editing the forms, then avoid Mac OS X preview. If you need to support Mac OS X preview, then you can try to re-generate this information programmatically with any PDF library that allows filling out forms, or you can apply a form flattening process instead (converting the "dynamic" text into static) before exporting as jpeg.

Examples:

  • If you have access to a Windows box and Adobe Acrobat, you can try with the script mentioned before.
  • If you have access to a Windows box and purchasing a commercial library is an option, you can try with Amyuni PDF Creator (Disclaimer: I work for Amyuni Technologies). for regenerating the appearance stream you will need to enumerate the form fields, retrieve their values, set an empty value to them, then re-assign them the original values. For doing form flattening, you will have to set the annotation attribute of each form field to false.
  • If you have access to a Linux box and a library with a GPL license is not an issue, you can try creating a Java application with iText, the method PdfStamper.setFormFlattening(boolean) seems to do what you need.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top