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.
Related
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.
The basic question is how can I click a button on a asp.net web page and it should show the download file box with open or save using Microsoft Word 2007?
I'm using OpenXML SDK v 2.0 and can, by clicking on a button, create (server-side) a docx document from a template, add in custom xml to populate Content controls and create a new Word docx document. However, my problem is then trying to send the document content in the http response object which will recognise the content as a Word 2007 document and, with the appropriate mime type, ask the user if they want to open the file with Word 2007 (which they have installed on their machine). No matter which option I try (about a dozen so far) I get either a 'Error parsing near 'PK ..' or an Error parsing near '
I've read just about all that seems to be online in the OpenXML Developer.org site, Eric White's blog, the MSDN articles, etc, etc but none seem to work when it comes to sending the document content to the client. I don't want to open the document in the browser, simply give the user the option to open the document (for further editing) in Word 2007.
I understand most of the Word 2007 file structure stuff and realise that the errors above relate to trying to parse the apparent zip file of docx or the xml (I have tried various permutations of Response.ContentType). It seems to me that the 'difficult' stuff of server-side document generation is done but the simple part of sending the content to the client is eluding me.
I hope someone who has managed to do this can help.
Trying to understand from a high-level how this would be accomplished.
Use case:
Flash application embedded in HTML used to create Certificates (just an example).
User enters a bunch of data into a form (Name, Address, What certificate is for, etc.).
User clicks a button which causes the application to create a Certificate in PDF form, with the form data displayed in a format that I define with a bunch of different images).
Ideally, Flex could use the browsers functionality to prompt the user with "What would you like to do with this document, 'Download', 'Open'. So it would function just like clicking on a link to a PDF document inside of a web page.
I already have the form and everything, its just a matter of how I create a PDF from that data. Is there a certain function that can take the current screen and create a PDF image of it? Or is there a certain library for creating PDFs? If anyone can point me in the right direction it would be much appreciated.
There is a AS3 PDF generator library called AlivePDF and can be found here.
Purepdf
is another actionscript library for creating Pdf file.
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/
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/)