Generating PDF documents in ASP.NET [duplicate] - asp.net

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Directly convert .aspx to .pdf
Is there any way to generate PDF document from asp.net directly from the page output. My requirement is, when user visits a page on my website, there should be a provision to get the same page / report in PDF format. Using iTextSharp, we need to built layout logic agin to generate PDF. If there are any changes in page output in future, I again need to work on logic to generate PDF. Instead I want to generate PDF directly from the page output just by setting "Response.ContentType" property.

One strategy I use is to develop reports using SQL Server Reporting Services. SSRS reports support export to PDF out of the box.
If you use SSRS 2008, you can even assign arbitrary HTML to a text box and the reporting engine will interpret it fairly well. This allows you to retrieve a snippet of HTML from any page, and present it in a report that will export to PDF without having to manually generate PDF document elements with iTextSharp.
If you go the SSRS 2008 route, check out this thread: http://forums.asp.net/t/1443965.aspx
I hope this helps.
Happy Coding!

You can set a button on your page that, if clicked, starts rendering a HTML page to PDF - only that the page you're asking it to render is exactly the page the user has clicked the button on. Once you got the PDF you can just send it in the normal way.
This of course requires a program that can render arbitrary HTML pages to pdf. You might want to check out ABCpdf which has always worked for me like a charm, but it's not free.

http://princexml.com/
They offer an application that converts html to pdf.

We use ActivePDF WebGrabber - which is designed to do exactly what you described. http://www.activepdf.com/products/serverproducts/webgrabber/

Related

Reading a PDF back from an iFrame?

I have a PDF document that is getting generated on the fly, and rendered on the fly to an iFrame within a radwindow. Basically the document is already largely prepopulated, however the user will still have a chunk of information that they are required to enter. I've found a good amount of information about sending a pdf TO an iframe, but not much information about going the other way. I have a button within the radwindow that can access the iframe object, however I'm somewhat lost as to where to go from there.
EDIT: The PDF is an editable form. I'm trying to pull back the entire PDF document as is, after the client side makes their entries to the form.
I think you'll need to send the file to the user so they can edit it locally and instruct them to upload it.
The content-disposition header with value attachment can help with the first task and you can use RadAsyncUpload to upload it: http://demos.telerik.com/aspnet-ajax/asyncupload/examples/overview/defaultcs.aspx.
I am not aware of ways to tap into the PDF viewer plugin the browsers use to show the PDF. Perhaps there is API from Adobe or some other third party plugin but that would rely on them and is out of your control.
Perhaps the JS PDF viewer from FireFox has something: https://mozillalabs.com/en-US/pdfjs/ but I don't know how stable and usable it is.
As per what was described in the comments, I ended up using postbacks through the PDF's themselves along with 1 pixel fields to store data required to identify the documents. It's a little hacky, but functional. I'm leaving this as an actual answer as this is as close to a real solution to the problem I originally had. This has been up and running for close to 4 years in this manner, and thus far hasn't caused any issues.

Generate PDF from Gridview in asp.net

I am using 4 gridviews on my page. I need to generate a pdf file which should be accessible on a button click and should contain these 4 grids.
Please help.
We have used WKHTMLTOPDF for our PDF's and it has worked very well. You can use it with a URL which it will then convert to a pdf which can then be sent to the users browser. So you could give it the url of your page with the gridview and then it would return a pdf. There are third party providers that can do the conversion for you, such as PDFCrowd, however this comes at a cost. If I recall correctly they provide a C# wrapper for you to use so it is pretty simple. There is also iText PDF, I have never used it though so cannot comment on it.
Hope this gives you a good start.
You could try with Amyuni WebkitPDF. It is a free tool for HTML to PDF or XAML/XPS convertion. You can pass the URL of the page to the library and obtain a PDF file as result that you can send to the browser.
Usual disclaimer applies.

Editing PDF document online and save in the database using ASP.NET

I have a PDF document storted as binary in the SQL Server database. I have rendered the binary document as PDF inside an iFrame using HTTP Handler.
Now, I want to allow the users to edit the data in the PDF file shown inside the iFrame and also populate some of the fields in the PDF automatically on clicking a button.
After all the fields are populated, the filled PDF document in the iFrame should be saved back as binary in the database.
How can this be implemented using ASP.NET 4.0?
I think you're looking for http://www.radpdf.com/
I have implemented this by adding HTTP Submit button inside the Adobe Acrobat (interactive) form. When the submit button is clicked, the PDF document will be posted to the server (an ASPX page). ASPX page will read the PDF document posted as stream, convert that into bytes and store in the database.
This is the difficult part of your question:
Now, I want to allow the users to edit the data in the PDF file shown inside the iFrame and also populate some of the fields in the PDF automatically on clicking a button.
You're going to need a third party tool that provides an API for filling form fields in a PDF. There are a few cheap ones and a few expensive ones. The only ones I've ever used successfully are
activePDF
Aspose
But there is also some open source projects:
iText ("iTextSharp") (example)
These tools can be used to fill in the fields of a PDF, as well as for other basic edits to PDFs, but things like editing text outside of form fields is very tough to do. There are entire software suites built around PDF authoring (think Adobe Acrobat). They should all provide ways to give you the new PDF (as a file, a byte array, a stream) so you can persist it back to the database.
You might have better luck allowing users to download and edit Word documents (or whatever equivalent you choose) and converting the end result into PDF. Aspose again could help with filling form fields in a document as well as the conversion from Doc to PDF.
I am not affiliated with Aspose in any way -- it just seems to be the tool of the trade for these sort of tasks.

How Do I convert HTML to PDF with hot links in outputted PDF with ASP(.NET)? Preferably with ActivePDF WebGrabber

My company purchased ActivePDF WebGrabber a couple of years ago to convert a classic ASP created HTML page into a PDF form. The only drawback with the tool that we continually run into is that the outputted HTML links are not hot. Are there any tools that do include hot-links within the HTML to PDF output?
According to the ActivePDF FAQ for Does WebGrabber convert hyperlinks into usable links in the output PDF?, the answer is no. There is a phrase confusing me at the end of the answer:
"To implement links in the final PDF,
the application would search for links
prior to the Postscript generation,
and append them once the PDF has been
generated using Toolkit."
Does that mean this is how to achieve it, or is this their theoretical but not tested solution? If this is the solution, has anyone done this that might be able to post some sample (pseudo-)code?
Edit: I should mention that we're open to a different tool, and we need it to be accessible via classic ASP and ASP.NET. I would prefer a solution in which the links are automatically hot-linked during PDF generation.
Looks like you can do it with the activepdf toolkit after the pdf is generated. I think this is what they are referring to.
Use the AddHyperlink function on the resultant pdf
AddHyperlink instructs Toolkit to add
a hyperlink in the current output file
that connects to a specified URL.
When clicked, the URL opens in a new
browser window.
edit
It would be easier to get a tool that actually does this here are some links
Open Source HTML to PDF Renderer with Full CSS Support
https://stackoverflow.com/questions/3178448/list-of-html-to-pdf-converters
In the old days, activePDF Server was the engine behind activePDF WebGrabber. activePDF Server is a Print-to-PDF program (hence the reference to Postscript) so the links were not live.
Beginning with the WebGrabber 2009 release, the dependancy on Server was removed and WebGrabber will now (versions 2009 & 2010) output intelligent PDFs that include hot-links within the HTML to PDF output.
If you can call into a web service then try the PDF Conversion Services. We are currently looking for beta testers for the html to pdf bit, just drop a line via the contact page.
I know it is an old question, but nowadays it should be sufficient to use
converter.PreserveLinks = true;
Where converter is a WebGrabber instance.

Free PDF viewers in ASP.net

I have many PDF documents in binary format which is in the SQL Server 2008 database. I have a gridview in my ASP.net page. When a user clicks on any ID column of the record I need to open the pdf in the browser.
Are there any free PDF viewer controls out there? How can I convert the binary PDF file and display as PDF in the browser.
Thanks
Just return the data to the client with a Content-Type of application/pdf. The client will open it in Adobe Reader or whatever PDF viewer is installed.
If you want a consistent experience without wondering how the user's browser will choose to handle the file (i.e. display it inline, launch Acrobat, or try to save it, etc)...
Google has made its own web-based PDF viewer available for free for embedding. You might use the iframe version in your website.
(This is a sample I created using their web viewer. They make available zoom, thumbnail and page controls - enough to get around the documents easily)
You will have to make an ASP.NET page that delivers the PDF binary stream, then give Google's viewer the URL of that page.
To stream a PDF through an ASPX page you'll want to Google and search for articles like these :
http://support.microsoft.com/default.aspx?scid=kb;en-us;307603
http://support.microsoft.com/default.aspx?scid=kb;en-us;326502
etc.
Basically it's about HTTP and manipulating the MIME type, page headers, etc and writing binary data to the Response stream using available ASP.NET mechanisms.
It might be worthwhile to post a separate question specifically about streaming PDF data through an ASPX page because the current question can be construed as a two-part question or being more oriented toward PDF viewers.
When using modern Webbrowser (with HTML5 Canvas support) you can try PDFJS library (https://mozilla.github.io/pdf.js/)

Resources