- Home
- Forum
- ASP.NET Web Forms (Classic)
- What is the difference between PdfLoadedDocument and PdfDocument classes
What is the difference between PdfLoadedDocument and PdfDocument classes
here is my sample code :
Stream stream1 = File1.PostedFile.InputStream;
Stream stream2 = File2.PostedFile.InputStream;
//Load the documents as streams
PdfLoadedDocument doc1 = new PdfLoadedDocument(stream1);
PdfLoadedDocument doc2 = new PdfLoadedDocument(stream2);
PdfLoadedDocument doc3 = new PdfLoadedDocument(Server.MapPath("~/PDFTemplates/My_PDF_with_fields.pdf"));
PdfLoadedForm form = doc3.Form;
// fill the fields from the first page
(form.Fields["::agency_name::"] as PdfLoadedTextBoxField).Text = "test name";
object[] dobj = { doc1, doc2, doc3 };
PdfDocument doc = new PdfDocument();
PdfDocument.Merge(doc, dobj);
doc.Form.Flatten = true;
OCRProcessor processor = new OCRProcessor();
//Language to process the OCR
processor.Settings.Language = Languages.English;
//Process OCR by providing loaded PDF document, Data dictionary and language
processor.PerformOCR(doc, Server.MapPath("/bin/Tessdata"));
Is there a way to convert a PdfDocument to a PdfLoadedDocument so i no longer get:
cannot convert from 'Syncfusion.Pdf.PdfDocument' to 'Syncfusion.Pdf.Parsing.PdfLoadedDocument'
Hi Eric,
Thank you for your interest in Syncfusion Products.
We can able to convert PdfDocument into PdfLoadedDocument, please use the code snippet below.
MemoryStream pdfGenerated = new MemoryStream();
PdfDocument.Merge(doc, dobj);
doc.Form.Flatten = true;
doc.Save(pdfGenerated);
doc.Close(true);
PdfLoadedDocument ldDoc = new PdfLoadedDocument(pdfGenerated);
Please let us know if you need any further assistance.
Thanks,
Karthikeyan.C
Thank you for the reply.
Do you also have a code example for importing (and exporting) an XFDF stream (or string) data into a PDF to populate its form data and an example of looping through the loaded form names and values?
For example I may want to import the entire XFDF, then set a few fields manually, possibly loop through the form names and values, possibly flatten the form, and possibly export the resultant XFDF.
Thanks,
Eric
HI Eric,
Thank you for your interest in Syncfusion Products.
We can able to import and export the XFDF data to Pdf forms please use the below code snippet:
Exporting
PdfLoadedDocument doc = new PdfLoadedDocument("SourceForm.pdf");
PdfLoadedForm form = doc.Form;
MemoryStream stream = new MemoryStream();
form.ExportData(stream, DataFormat.XFdf, "SourceForm.pdf");
Importing
PdfLoadedDocument doc = new PdfLoadedDocument("SourceForm.pdf");
PdfLoadedForm form = doc.Form;
form.ImportData("ImportData.XFdf",DataFormat.XFdf, false);
doc.Save("Import.pdf")
Please refer the below link to fill the PDF from fields manually.
http://asp.syncfusion.com/Windows/demos/reporting/pdf/User%20Interaction/Form%20Fill/Sample.aspx
Please let us know if you have any concern.
Thanks,
Karthikeyan.C
form.ImportData("ImportData.XFdf",DataFormat.XFdf, false);
We have an overload method to pass the XFDF file as stream to import into an existing PDF document.
Please refer to the following code snippet:
// Load the existing form
PdfLoadedForm form = doc.Form;
// Load the FDF file
FileStream stream = new FileStream("ImportFDF.xfdf", FileMode.Open);
// Import the FDF stream
form.ImportDataXFDF(stream, true);
We have created the sample for your reference in the below link:
http://www.syncfusion.com/downloads/support/forum/115319/ze/xdf_file_import-842004607
Please try this and let us know if you have any further assistance.
Regards,
Abirami.
- 5 Replies
- 3 Participants
-
ER Eric Rosenblum
- Jan 9, 2014 08:19 PM UTC
- Sep 25, 2015 01:11 PM UTC