Welcome to WebmasterWorld Guest from 54.205.251.179

Forum Moderators: ocean10000

Message Too Old, No Replies

Creating PDF's with asp.net

   
9:52 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



Does anyone know of a .net component they can recommend for creating pdf files dynamically and saving them on the server?

Much like creating and saving a text file to the server with code, but the file is a pdf?

I have done some research and have not been happy with what I have found.

Thanks.

9:56 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



Just a heads up...
I can't install any dll's on the server as it is a shared hosting environment...
10:46 pm on Mar 20, 2007 (gmt 0)

10+ Year Member



I've used Apose.Words and Aspose.PDF. With the Words component you can open and edit MS Word documents without having Word on the server. You can then save the document in an XML format that their Aspose.PDF component can open and read/manipulate.

The two are mutually exclusive and I only mention the Words component because it is sometimes usefull to do mailmerge functions with Word and then convert to PDF.

Both are full .Net components with no install needed. Just drop in your bin folder. The company Aspose is also good at releasing lots of upgrades for their components, so you know they support it.

2:15 pm on Mar 21, 2007 (gmt 0)

10+ Year Member



Just got through with a project using a .NET component that has been superb. Google PDF4NET (www.o2sol.com)
4:00 pm on Mar 21, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I have used ITextSharp (open source) in the past, its Dot.Net port from Java version which is updated often. Offers most functions one would need to generate pdf's and rtf documents.
4:59 pm on Mar 21, 2007 (gmt 0)

10+ Year Member



Thank you for the leads. I am currently researching these possibilities.

Ocean10000, I have not had any luck with the iTextSharp component. Do you have a source for documentation?

Thanks again.

5:56 pm on Mar 21, 2007 (gmt 0)

10+ Year Member



For instance,

I thought I was doing things correctly, but its not working as I thought it would?

I have the dll referenced and the following code in my Sub Page_Load which I copied out of a tutorial.
' step 1: creation of a document-object
Dim myDoc As New Document()

' step 2:
' we create a writer that listens to the document
' and directs a PDF-stream to a file
PdfWriter.GetInstance(myDoc, New FileStream("Chap0101.pdf", FileMode.Create))

' step 3: we open the document
myDoc.Open()

' step 4: we add a paragraph to the document
myDoc.Add(New Paragraph("Hello World"))

' step 5: we close the document
myDoc.Close()

When I run the page, nothing happens. I would assume that either a pdf file would be created or displayed. Am I missing something?

Thanks again for all the help.

8:05 pm on Mar 21, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Here is a link to
ITextSharp Examples C# [ujihara.jp].

I hope this helps.

9:51 pm on Mar 21, 2007 (gmt 0)

10+ Year Member



OCEAN10000,

Thanks for the examples. I have the pdf created, but the examples are problematic at best. I keep receiving errors when the aspx page tries to create the pdf file. "There was an error Opening this document. The file is damaged and could not be repaired."

I will continue to look into this.

Thanks again for the help.

11:06 pm on Mar 21, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



#I did this code without compiling but should give you a general reference.

Response.Clear()
Response.ContentType="application/pdf"
Response.AddHeader("content-disposition", "inline; filename=Document.pdf")

' step 1: creation of a document-object
Dim myDoc As New Document()

' step 2:
' we create a writer that listens to the document
' and directs a PDF-stream to a file
PdfWriter.GetInstance(myDoc, Response.OutputStream)

' step 3: we open the document
myDoc.Open()

' step 4: we add a paragraph to the document
myDoc.Add(New Paragraph("Hello World"))

' step 5: we close the document
myDoc.Close()

Response.Flush();

1:45 pm on Mar 22, 2007 (gmt 0)

10+ Year Member



Ocean10000,

Thanks for the code! It is working really well. The other sample code I found was displaying the pdf in a new window, but seemed to be very volatile. As in adding table cell content as a number ("5") for example would work, but adding table cell content as text ("this is a test") for example would cause the pdf to not load.

Thanks again for your help.