We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

What is the difference between PdfLoadedDocument and PdfDocument classes

Thread ID:

Created:

Updated:

Platform:

Replies:

115319 Jan 9,2014 08:19 PM UTC Sep 25,2015 01:11 PM UTC ASP.NET Web Forms (Classic) 5
loading
Tags: PDF
Eric Rosenblum
Asked On January 9, 2014 08:19 PM UTC

I am trying to do a proof on concept where I take a few uploaded PDFs and merge them with a local file then set  form value(s), flatten the form, run OCR and then encrypt the PDF.

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'


KarthikeyanC [Syncfusion]
Replied On January 10, 2014 09:14 AM UTC

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


Eric Rosenblum
Replied On January 20, 2014 08:05 PM UTC

Karthikeyan,

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

KarthikeyanC [Syncfusion]
Replied On January 22, 2014 04:26 AM UTC

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


Eric Rosenblum
Replied On September 24, 2015 08:01 PM UTC

Lets say I have an XFDF string in memory, not on disk, how I use the ImportData method?   I dont see any overloaded method to pass a stream or XML?
           

form.ImportData("ImportData.XFdf",DataFormat.XFdf, false);


Abirami Selvan [Syncfusion]
Replied On September 25, 2015 01:11 PM UTC

Hi  Eric,

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.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;