FDFMerge results in no page added to PDFDoc

Product: Windows C# (.Net Core)

Product Version: Latest (

Please give a brief summary of your issue:
After successfully creating a FDFDoc from a xfdf string no pages are added to the PDFDoc.

Please describe your issue and provide steps to reproduce it:
From code I am passed a in house file that needs to be generated into a template PDF. Instead of opening the template pdf I decided to generate a string of xfdf as this can be done very quickly with string builder and the amount of text I am using.

After the xfdf is generated for each line in the file, I run the following lines of code.

var form = new FDFDoc(FDFDoc.CreateFromXFDF(sb.ToString()));

sb is the string builder stated before and outputPdf is a PDF that was created further up to be open for longer so that multiple “forms” can be added to the single pdf. I have made sure that after ever pages is added that the pdf is refreshed then flattened so the next form page fields do not get mixed up with the previously added forms.

When this section of code is done running (this does not error) it returns the “outputPdf” and then the main function saves the pdf with “e_linearized”. This save action fails with the following error.

When diagnosing this problem, I first tried changing the e_linearized to any other option and it would save, but the pdf had no pages. I then tracked down why no pages were present. I found that the Form when the FDF Merge was called no pages to the outputPdf.

I also tried saving the xfdf file to see if the data was not being created properly, however, it was as not only was the file displaying properly but it also could be double clicked and open the form filled out in Adobe Acrobat DC.

Outside of opening the Template Form as a PDFDoc and filling each field individually and then adding a new page for each line in the file, is there something that could possible be done to get the FDF Merge working. I have to be able to do this PDF generation very quickly and not take up GB of memory which is a tall order. Any help or advice is appriciated.

The exception you are seeing indicates that the document does not contain any pages, so it is an invalid PDF file. Please make sure you are creating a page and adding it on your code like the following:

Page pg = doc.PageCreate();

Thanks for the reply, this answer did fix the “Error” message that was showing. But not the overarching problem. I got the point that the pdf didn’t have any pages. Why did the pdf not have pages?

As I had stated, I generate xfdf data in a string and then us the code below to create the FDFDoc (this works fine as I can save the xfdf as a file with no problem).

var form = new FDFDoc(FDFDoc.CreateFromXFDF(sb.ToString()));

The problem is that the line outputPdf.FDFMerge(form); does not add a page (the form that is set linked in the xfdf string) to the outputPdf. Looking at the examples of this in the documentation, besides that I created the PDFDoc further up in the function, the form creation and the outputPdf.FDFMerge(form); is exactly how it appears in the documentation but is not adding a page to my pdf.

Is there something else I am missing? I tried the above reply’s suggestion and had the code push back a page which fixed the displaying error but now just generates a blank one page pdf and still does not have the FDF form merged in with the pdf.

Just to confirm, are you creating a new PDFDoc outputPdf, and merging the XFDF to it? If so, please note that the FDFMerge call will not create new pages on the destination document.

If no pages are found, or if the document does not contain the pages defined in the XFDF, the FDFMerge call will not merge the annotations to the document.

You will need to make sure that the destination document has the correct number of pages prior to calling the outputPdf.FDFMerge(form); method.

The PDFDoc outputPdf was a new document with no pages. And then I never added the template to the form before calling the FDFMerge. This would explain why there was no page added.

Thank you!