I have a PDFthat has text boxes in it. My program uses Xfinium PDF software to fill the text boxes. When I view the filled in PDF the document shows up with no data in the fields. I have tried using QLPreviewController and UIWebView and they both do not display the filled in fields; however, if I email the document to myself and open it in Adobe DC on the iPad all the data shows up correctly. It may be important to note that even the mail app does not show the PDF correctly filled in. Here is the PDF opened in Adobe on iPad Here is the PDF opened in UIWebView in my app (also shows same way in QLPreviewController
5 Answers
PDF forms may bring along appearances or may rely on the viewer to create an appearance for the value of the field.
Fairly complete PDF viewers (like Adobe Reader or Foxit) can get along with both variants well. Incomplete viewers, though, like many so called previewers, require an existing appearance and display empty documents for forms which do not bring along appearances.
Thus, if you want your forms to be visible on incomplete viewers, too, provide appearances.
The QLPreviewController use the CGPDF* API to display the PDF files. The CGPDF* API has some limitations, it displays only the page content and it does not display annotations, no matter if they have appearances or not. Form fields use widget annotations to display the field content so they are also not displayed.
The solution here is to flatten the form fields. This operation will transform the form fields into page content and QLPreviewController will display the final file correctly. The downside of this operation is that the form fields are no longer editable.
The XFINIUM.PDF library creates apearance objects for field values. The problem is related to iOS PDF rendering engine which does not display annotations and form fields. The solution is to flatten the form fields if you want to view the files using the QLPreviewController.
The form fields are flattened with this line of code:
pdfDocumentObject.Form.FlattenFormFields();
Disclaimer: I work for the company that develops the XFINIUM.PDF library.
Both QuickLook and UIWebView
/WKWebView
uses Apple's internal and undocumented CorePDF
framework, which has no code that would render PDF AcroForms (doesn't matter if backed by appearance streams or not)
You can either
1) Flatten the document on the server or with a client-side library.
2) Re-implement everything from scratch and add support for PDF forms. (See Page 431ff in Adobe's PDF Specifications - "Interactive Form Dictionary")
We did (2) in the commercially available PSPDFKit SDK. It doesn't use Apple's rendering engine as you do not have a way here to render appearance streams for PDF form widgets, so even with a lot of code you'll not be able to get the representation that is encoded in the document. For this you'll either have to result to private API or re-implement everything yourself. We also support (1) using the PSPDFProcessor
class.