Posted 23 September 2026, 1:27 am EST
Hi Robin,
Thank you for reaching out.
The field values are missing because the page annotations and form widgets are being drawn before the page content. As per the official approach, it is recommended to draw the page content first, then draw the annotations and widgets:
GcPdfDocument doc = new();
foreach (Page srcPage in srcDoc.Pages)
{
Page page = doc.Pages.Add();
page.Size = srcPage.Size;
FormXObject fxo = new(doc, srcPage);
GcPdfGraphics pdfGraphics = page.Graphics;
pdfGraphics.DrawForm(fxo, page.Bounds, null, ImageAlign.Default);
srcPage.DrawAnnotations(pdfGraphics, page.Bounds);
}
However, one important caveat applies to your use case. Your earlier PDF has an image covering the hidden Headshot1 field. Drawing the annotations last can place that field’s appearance over the image. Therefore, it is required to redraw the image on the destination page, which adds additional image-drawing overhead. Please refer to the code snippet below that demonstrates the approach:
GcPdfDocument doc = new();
foreach (Page srcPage in srcDoc.Pages)
{
Page page = doc.Pages.Add();
page.Size = srcPage.Size;
FormXObject fxo = new(doc, srcPage);
GcPdfGraphics pdfGraphics = page.Graphics;
pdfGraphics.DrawForm(fxo, page.Bounds, null, ImageAlign.Default);
srcPage.DrawAnnotations(pdfGraphics, page.Bounds);
foreach (PdfImageInfo imgInfo in srcPage.GetImages())
{
foreach (PdfImageLocation imgLocation in imgInfo.Locations)
{
pdfGraphics.DrawImage(imgInfo.Image, imgLocation.PageBounds.ToRect(), null, ImageAlign.ScaleImage);
}
}
}
You can further refer to the attached sample below that demonstrates the above approach and generates the flattened PDF as per your requirements.
Please let us know if you encounter any further issues or require additional assistance.
Best regards,
Chirag
Attachments: FlatPDF.zip