We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Extracting data from PDF document

Hi,

Following is my scenario and would love any feed back.

Scenario 1

  1. Have a asp.net web form which will have a button and load a pdf in a frame or something
  2. when button is clicked on the web form, extract the data form the PDF document fields and then post it to the database

Scenario 2

  1. Have user load a PDF which would have a button to save the data from the PDF back to the database upon click of the button

Any feedback would be appreciated

Thanks,

Salil

Hi Salil,

You can find a sample similar to your scenario in this topic: Posting AcroForm Data to Web Page. Please note that we have merged Aspose.Pdf.Kit for .NET into Aspose.Pdf for .NET and Aspose.Pdf.Kit for .NET has been discontinued. However, you can use the same sample with Aspsoe.Pdf for .NET using Aspose.Pdf.Facades namespace.

I hope this helps. If you find any further questions, please do let us know.
Regards,

Thanks Shahzad for the reply.

The solution you provided worked. I have one more scenario and like to know how I can use Form & FormEditor object together to do following

  1. I want to open an existing PDF template, fill all the filds on PDF with data from database ( would love to use memory stream object rather than writing to the disk, new FormEditor(stream, stream) )
  2. Then make modification to data on the PDF and then post back to DB

Thanks,

Salil

Hi Salil,

Please find the answers to your questions below:

I want to open an existing PDF template, fill all the filds on PDF with
data from database ( would love to use memory stream object rather than
writing to the disk, new FormEditor(stream, stream) )

You can open the PDF file using Form class and fill the data into the form fields. You can also save the file to a MemoryStream using the appropriate overload of the Form class.

Then make modification to data on the PDF and then post back to DB

If you want to make modifications programmatically, you can still use the Form class. However, if you want to make these changes manually and then save the data to database then the solution suggested in my previous post will work.

If you think I haven’t understood your requirement clearly or you have any further questions, please do let us know.

Regards,

Hi Shahzad,

Looks like even if I use stream object I would still have to save file locally. Following is my code. What I want to do is get the source file, assign URL to submit button, then fill the PDF form fields with data from DB and then display. I am unable to achieve. Please let me know what I am doing wrong looking at my code.

//Get the file

byte[] file = File.ReadAllBytes(Server.MapPath( "~/XYZ.pdf" ));
MemoryStream inputStream = new MemoryStream( file );
MemoryStream outputStream = new MemoryStream( file );
MemoryStream displayStream = new MemoryStream( file );
FormEditor editor = new FormEditor( inputStream, outputStream );
editor.SetSubmitUrl( "btnSubmit", GetDisplayPageURL() );

Form form = new Form( outputStream, displayStream );
form.FillField( "LName", "Doe" );
form.FillField( "FName", "Jon" );
form.FillField( "MName", "XYZABC" );
form.FillField( "OtherNames", "Some Other Names" );
//editor.Save();
form.Save();
//OpenPDF( ( MemoryStream ) form.SrcStream );
OpenPDF( displayStream );

Thanks,

Salil

Hi Salil,

First off, please do not pass file variable containing input file data to outputStream and displayStream. You can create these two MemoryStream objects without any parameters. Secondly, once you’re done adding the submit button URL, please save the output stream.

You need to modify the code as shown below:

//Get the file
byte[] file = File.ReadAllBytes(Server.MapPath( “~/XYZ.pdf” ));

MemoryStream inputStream = new MemoryStream( file );

MemoryStream outputStream = new MemoryStream();

MemoryStream displayStream = new MemoryStream();

FormEditor editor = new FormEditor( inputStream, outputStream );

editor.SetSubmitUrl( “btnSubmit”, GetDisplayPageURL() );

editor.Save();

Form form = new Form( outputStream, displayStream );

form.FillField( “LName”, “Doe” );

form.FillField( “FName”, “Jon” );

form.FillField( “MName”, “XYZABC” );

form.FillField( “OtherNames”, “Some Other Names” );

//editor.Save();

form.Save();

//OpenPDF( ( MemoryStream ) form.SrcStream );

OpenPDF( displayStream );

After the above code is finished executing, you’ll be able to use the output stream as you like.

I hope this resolves your issue. If you have any further questions, please do let us know.
Regards,

Hi Shahzad,

Fantastic, that worked.

Thanks,

Salil