Filling PDF form in Memory and displaying in browser

Hi There,

I am evaluating your product and was wondering if it is possible to fill an instance of a pdf form (that is stored on disk) in memory with data from a database and then display the flattened form in a browser on the fly. I looked at your WIKI and see how to store it back to disk as a new pdf but not how to create it in memory (without saving a new version to disk) and then display it in a browser.

Thanks for your help.

-Tom

Hi Tom,

Thanks for considering Aspose.

You could refer to the demo about how to fill form in momery and display in IE.
A simple demo is this :GitHub Repositories for Examples, Plugins and Showcases of Aspose APIs for .NET, Java, C++ and Android .
A more complete demo is this (including how to fill the form directly from the database) :
GitHub Repositories for Examples, Plugins and Showcases of Aspose APIs for .NET, Java, C++ and Android .

Best regards.

Thanks Ken! I am getting a 404 error (Page Not Found) for the following link:

http://www.aspose.com/Products/Aspose.Pdf.kit/Demos/Northwind.aspx?index=MailMergeStream

Also, the first link of the demo you gave me shows the final PDF but is there a way to see the code that created the demo in C#.

Thanks,

Tom

Nevermind - I found the demos code - it was part of the installation.

Thanks,

-TQ

I have another question for you. I looked at the demo but I am having a problem getting the pdf to be displayed in the browser. When I run the code in IE 7, it only allows me to save the resulting pdf, not open it in the browser. When I run it in Fire Fox 2, it displays the binary code in the browser.

This is the code from the demo:

templatePdf = path + @".\Resources\student.pdf";

Response.AddHeader("content-disposition","inline; filename=" + "studentOut.pdf");

FormDemos.FillFields(path,templatePdf, Response.OutputStream);

Response.End();

Is there a way to get it to display in the browser in IE and Firefox?

Thanks,

Tom

Hi, Tom,
An option of Adobe Reader needs setting. It is “Edit->Preferences->Internet->display the pdf in browser”. Select the option and test it.

Any other question is welcome.

Best regards.

Hi Ken,

I checked the setting in Adobe Reader 8.0 and it is correctly set to display in the browser but I am still getting the situation I descriped earlier - in IE it will give me a dialog box to save the pdf but won’t display and in FireFox it displays the binary code.

FYI - when I run the demo code on your site (http://www.aspose.com/Products/Aspose.Pdf.kit/Demos/) for Fill Fields (#9) I get the same result.

Is there something else I am missing? Is there a way to take the instantiated Form object and create a PDF object, so I can use the save method of the PDF object and use the SaveType property to get it to display in the browser?

Thanks,

Tom

Hi,

Please try clicking the following link:

http://illiad.evms.edu/sample.pdf

This pdf should open in your browser. If not then there is a problem with your Acrobat Reader installation. Please consider reinstalling Acrobat reader.

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team

Hi Adeel,

The document in the link does load in my browser. Acrobat 8 is installed correctly on my machine. I still have the issue when I run the Fill Fields demo - in IE 7 I get a pop-up box that only allows me to save the PDF to disk (it does not load the pdf in the browser) and in FireFox 2 it loads the binary version of the pdf into the browser.

Is there some other setting I am missing?

Thanks,

Tom

Try adding this line after you set your Response header info:

Response.ContentType = "application/pdf";

Thanks anotaro! It now loads correctly in IE 7. I am still having problems loading it in Firefox 2. It no longer displays the binary version of the document but seems to freeze up the browser.

Is there some code or setting I need to get this to work in Firefox 2?

Thanks,

Tom

You may just need to update or install the adobe plug-in for firefox...not sure, though. Good luck...

Hi,

If you were unable to view the pdf that I posted then it means acrobat reader isn’t installed properly. By this I mean the plugin is not cofigured correctly with IE and other browsers that you may have. The simplest solution is to uninstall reader and install it again. Have you tried this ?

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html

Hi Adeel,

As I stated in an earlier post, I was able to view the pdf that you posted (http://illiad.evms.edu/sample.pdf) in both IE and Firefox. Acrobat is installed correctly in both browsers on my machine.

The problem I am having is that when I run the Fill Fields (#9) demo on http://www.aspose.com/Products/Aspose.Pdf.kit/Demos/ in Firefox 2, it is displaying the binary code for the pdf instead of displaying the actual document. I also tested this in Firefox 2 on a different machine and had the same issue. In IE 7, it displays a pop-up box that allows me to save the pdf to disk but does not let me load it into the browser.

I fixed the problem in IE 7 (it now loads correctly in the browser) by adding the code that anotaro suggested above:

Response.ContentType = "application/pdf";

However, this did not fix the problem in FireFox 2. Instead of displaying the binary version of the document, it now freezes up the browser and does not diplay the pdf.

I am wondering if anyone else has had problems with Firefox and if there is anyway to fix this?

Thanks,

Tom

Hi, Tom, I have solved this problem. It needs to set more options about the “Response” in codes since the firefox is not very compatible with the IE and VS.

Please change the code of the demo about the fillfield (in default.aspx.cs) like this:

case “FillFields”:
templatePdf = path + @".\Resources\student.pdf";
// Response.AddHeader(“content-disposition”,“inline; filename=” + “studentOut.pdf”);

//response to user’s web.
Response.Expires = 0;
Response.Buffer = true;
Response.ClearContent();
Response.AddHeader(“content-disposition”,“inline; filename=” + “studentOut.pdf”);
Response.ContentType = “application/pdf”;

FormDemos.FillFields(path,templatePdf, Response.OutputStream);
Response.End();
break;


Best regards.

Hi Ken,

Thanks for your help!

I copied the code into my local version of the demo and it is working in IE but still hangs the browser in Firefox 2. I have tried this on multiple machines in Firefox and have the same issue.

An error appears in the footer of the FireFox browser: "This document has been closed by Acrobat- press the refresh button to reload." When I reload the browser, the pdf does not load in the browser - all I see is a blank page.

I also tried it with Safari on the Mac and it also froze the browser. Is this tool kit cross-browser compatible or is it only to be used with IE?

Thanks,

Tom

Hi, Tom
My firefox version is “Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.0.10) Gecko/20070216 Firefox/1.5.0.10” . And I found the code was ok on my machine. Before I fix the code, the browser dispaly the binary code.

Which version of Firefox is yours? Detailed information.
We will install a firefox of yours to reproduce the error.

Best regards.

Thanks, Ken. Here is the version I am using.

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2 Web-Sniffer/1.0.24

I was able to get this to work on a different machine using this exact version of Firefox listed above. The difference between the 2 machines is that the one that froze the browser had the latest version of Adobe Acrobat Professional (8.0) and the latest version Adobe Acrobat Reader (8.0). The machine that worked contained verison 7.05 of Professional and 6.0 of Reader.

Is it possible that the problem has to do with the plugins associated with the latest version of Reader and/or Professional?

-Tom

Well, I got this to finally work on my machine with Firefox, although why this is, I am not quite sure. It seems that when I run the demo on my test server, I need run it through ssl to get it to work (https:///Aspose.Pdf.Kit.Demos/default.aspx?index=FillFields) instead of just http (http:///Aspose.Pdf.Kit.Demos/default.aspx?index=FillFields).

Why I need to go through ssl to get it to work on my machine but not on other machines I tested - I do not know...

Any ideas?

-Tom

Hi, Tom.
It is really a strange problem. In fact, our simple demo needs nothing else except the http.

I will discuss this problem in our team.

Best regards.