//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Graphics;usingGrapeCity.Documents.Drawing; namespaceDsPdfWeb.Demos{// This sample shows how to easily 'flatten' an AcroForm PDF with data -// i.e. convert that form into a non-form PDF that looks like the// original filled form. // The original filled form loaded by this sample is generated by FormFields.publicclassFlattenForm {publicintCreatePDF(Stream stream) {usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "form-fields.pdf"));// Load the filled PDF form into a temp document:var srcDoc = newGcPdfDocument(); srcDoc.Load(fs);// Draw all pages and annotation of the source PDF into a new PDF:var doc = newGcPdfDocument();foreach (var srcPage in srcDoc.Pages) {var page = doc.Pages.Add();var fxo = newFormXObject(doc, srcPage); page.Graphics.DrawForm(fxo, page.Bounds, null, ImageAlign.Default);// This method draws all annotations on the page including form field widgets: srcPage.DrawAnnotations(page.Graphics, page.Bounds); }// Done: doc.Save(stream);return doc.Pages.Count; } }}