Using PDF In .Net App - asp.net

Can someone point me to some code/tutorial on how to upload pdf files and store them, then moreover how to use a pdf reader to display the file as read only in an asp.net application.
Is there a PDF reader already in the visual studio toolbox?

The approach I would use in this situation is to upload the PDF as you would any other file, then use a tool like GhostScript to convert the PDF pages into image files that you can show in ASP .Net.
Here's a tutorial doing that in C# http://www.codeproject.com/KB/cs/GhostScriptUseWithCSharp.aspx

Adobe provides (on acrobat.com) a free service which provides you with the ability to upload pdf (and also other types like doc...) and then embed a nice flash interface for displaying the files on your page.
It's pretty helpful as you can store some 5 gigs of files here.
But if you want to let the users upload their own files then this won't help you.

PDF is a final format file, ie its is read-only for the most part and can be embedded into the page via the <object> tag, except if you mean downloadable by the user.
Displaying PDF is generally done by rasterising to an image format for display (ie as an image on the page or via a richer interface (with zooming etc) through flash/silverlight etc.
You can use [GhostScript][1] to interpret PDF files and convert them to an image.
[1]: http://www.GhostScript .com

Uploading a PDF is just like any other file. Use the ASP.NET file uploader control:
http://www.codeproject.com/KB/aspnet/fileupload.aspx
In order to view the PDF in an ASP.NET application, you could either depend on Acrobat being there or use a PDF Viewer control.
The company I work for, Atalasoft, sells a PDF Reader add-on to our web viewer controls. You can learn more here: http://www.atalasoft.com/products/dotimage/pdf-reader

Related

How to convert a html table to downloadable excel file ASP.NET C#

I need a function to convert any HTML table to a excel file!
I like to add a button to my page and once that button is clicked I pass a complete HTML table in to such a function that will generate an excel file and past the html table into the file with the same layout and design!
I appreciate any help with this request.
I am using c# and asp.net
This is a nasty trick, but it works in recent version of excel.
You just save the html table as a normal html file, then just rename it to xls. If your application is a web application use response.setHeader("Content-Disposition", "attachment; filename=order.xls").
Recent version of excel support Microsoft Office XML Formats, so if the previous solution doesn't work, you may want to try to generate the xml from the html table.
See XML Spreadsheet Reference.
What I do, is to generate the xml from excel in the xml format, then hack into it. You can implement also advanced features like automatic filters, and cool layouts. I used a template engine to generate the xml (Freemarker, it's Java stuff, but I'm sure there are template engines also for .NET)

Reading an e pub file

I have files in e pub format. I have to show their contents to the user. How do I read them in asp.net? Can it be done through javascript?
Authoritative? What could be better then a StackOverflow answer? I started from this question ( https://stackoverflow.com/questions/4870594/is-there-a-c-sharp-epub-library ) and gleaned a few usefull links:
Usefull information on displaying text in a web browser using javascript so it paginates nicely: HTML book-like pagination
A C# open source library for reading ePub files, the sample code on the home page includes how to get the contents as HTML: http://epubreader.codeplex.com/
There are other libraries which may come in handy if the ePub reader library on codeplex doesn't pan out: http://sourceforge.net/projects/epubsharp/, and http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx
You can't do this with just JavaScript of course, you'll have a server side like a web service or code behind on your asp.net webpage which opens the epub file, extracts the contents as HTML and returns it to the client, but I think there is enough here to get you started.
Just to add then i suggest the steps:
Step 1: unzip the file using C#,.net code having some third party library.
Refer : recommend a library/API to unzip file in C#
Step 2: Check whether in the extracted folder there is only one file or more.
Refer: How do I find out how many files are in a directory?
Step 3 :Read the file using stream reader in c#.net
Refer: http://msdn.microsoft.com/en-us/library/aa328963(v=vs.71).aspx
http://www.dotnetperls.com/streamreader
Epub file is actually a zip archive that contains
xml files for meta data, table of contents etc
xhtml or dtbook (xml) + gif, jpeg, png, svg + css for content
To be able to display epub you will have to be able to handle all of the above. Here Reading ePub format you'll find what you have to do to open epub step by step - it's an example for iphone, but it should be enough.

A "shortcut" method for exporting an ASP.Net Page to pdf/xls

I want to export a few Pages to pdf/xls. By Pages I mean as the eye sees it - a screenshot of the Page's contents. I know how to build pdf/xls documents using 3rd party tools but is there any way to quickly export the rendered contents of say a Panel?
edit: maybe a tool that can render the page's output as a browser would, and save it as an image file?
There is an open source console program named wkhtmltopdf which you could call from asp.net to convert the page. It can convert to PDF or an image with wkhtmltoimage (JPG, PNG, etc.) using the webkit rendering engine.
Check my answer to this question to see an example of how to convert from a html to a pdf using C#:
Easiest way of porting html table data to readable document
I can recommend http://www.screengrab.org/ for firefox.

Display Word Document inside ASP.Net page

I want to display a word Document, which is sitting on my IIS. I want to display the whole document as is, inside a iFrame on my aspx page.
I know I can use MS Word Libs, but I cannot install Word on Server where application will be hosted, (Correct me if I am wrong: I cannot use just dlls without installing MS Word on Server).
How can I display the word document in my iFrame?
Probably the easiest way would be to include the Google Docs Viewer.
Other ways could be to use Aspose.Words (commercial) to convert Word to PDF and then use Aspose.Pdf.Kit to convert PDF to images and then display the images online.
PowerTools for Open XML contains an open source, free implementation of a conversion from DOCX to HTML formatted with CSS. The module HtmlConverter.cs supports all paragraph, character, and table styles, fonts and text formatting, numbered and bulleted lists, images, and more. See http://bit.ly/1bclyg9

How can I create new PDF files based on a template where some text will be replaced?

I'm developing a CMS aplication in ASP .Net using WebForms and I'm looking for a way to create new PDF files based on a template.
This feature will be used to generate contracts where some placeholders will be replaced with the customer data.
What's the best approach to do that?
Edited: The templates will be static, the main content will never change from customer to customer, only some text in the beginning that will contain the placeholders to recive the customer data. The catch is that I must allow the owner of the application to upload new templates in PDF, with the predetermined placeholders in it to allow the replacement to occur.
I can think of two approaches depending on what type of template you are looking at:
1) Static Template - Say the template does not change with the data (Ex.some standard compliance form etc)
You can try something like iTextSharp, where you have your templates defined in your .net code, and you just "plug in" the relevant data and render the PDF via iTextSharp.
2) Dynamic Templates - Say your template isn't standard and is user customizable. In this case, I'd say go for HTML for designing and "print" the for to PDF. There are many components available.
You may also want to try out components like crystal reports.
I'd go with static HTML templates containing substitution tokens e.g. {FullName} which you can then replace with your data. Once you have created an HTML file like this, say in a StringBuilder, you can use PrinceXML or ABCPdf.net (www.websupergoo.com) to transform your HTML into a PDF.
I hope I am understaning this correctly but wouldn't using standard PDF Form Fields give you the functionality and features you require. Load the PDF template into Adobe Acrobat Full or Foxit Phantom and define standard PDF Form Fields on top of the PDF. Each field has a name, position, font etc.
Then just use a standard PDF library to fill in the PDF form fields and 'flatten' the form fields if that is required.
This solution allows the customer to design new PDF layouts and so long as they define form fields with names that match up then you will be able to drop in the replacement form with a simple file copy.
The iText or iTextSharp library should be able to do all of this quite easily. If not them there are many PDF libraries out there that can.

Resources