pdf conversion using c# and asp.net

G

Guest

Hi,
I want to convert my html page into pdf using c# in codebehind and asp.net. Iis there any assembly or something in .net to do so. I tried itextsharp library but it is saving the pdf file in hard drive I dont want to do in this way, actually am generating reports for my web project thats why i dont want them to be saved in hard drive. Is it possible to generate pdf file without saving? just display the report in browsers. Please help me i need it very urgently.

Thanks
 
A

Andy Fish

sorry I don't know of a solution but if you need it urgently go with the
best thing you have

use itextstarp to generate the PDF to a temporary file (make sure you give
the file a unique name), then read the file from the disk, stream it to the
user and delete it. Don't worry about the performance of saving and
re-reading the file - it won't be noticeable

Andy


dawood said:
Hi,
I want to convert my html page into pdf using c# in codebehind and
asp.net. Iis there any assembly or something in .net to do so. I tried
itextsharp library but it is saving the pdf file in hard drive I dont want
to do in this way, actually am generating reports for my web project thats
why i dont want them to be saved in hard drive. Is it possible to generate
pdf file without saving? just display the report in browsers. Please help me
i need it very urgently.
 
M

Mark Rae

Andy Fish said:
sorry I don't know of a solution but if you need it urgently go with the
best thing you have

use itextstarp to generate the PDF to a temporary file (make sure you give
the file a unique name), then read the file from the disk, stream it to the
user and delete it. Don't worry about the performance of saving and
re-reading the file - it won't be noticeable

I agree. I recently worked on a project which had this functionality and,
because of the IE / PDF bug
(http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=IE+PDF+
bug), this was the only way to guarantee that it would work.
 
G

Guest

if i delete the file then will it displayed to the user for printing or so? and how to stream the file pls give example.
 
A

Andy Fish

dawood said:
if i delete the file then will it displayed to the user for printing or
so? and how to stream the file pls give example.in an aspx file, do this:

Byte[] fileContents;
..read temp file from disk into fileContents
..delete temp file
Response.ContentType = "application/pdf"
Response.BinaryWrite(fileContents);

there may be some other way with streams that doesn't involve reading the
whole file into memory, but this is just an example I had handy
 
M

mdbrooks

You can use itextsharp to generate the .pdf files and send them to the browser. The example is in VB.Net, but it can easily be ported to C#.


Dim m As New System.IO.MemoryStream

Dim document As ItextSharp.text.Document = New Document(PageSize.LETTER)
Dim writer as iTextSharp.text.pdf.pdfWriter = iTextSharp.text.pdf.PdfWriter.getInstance(document, m)

Try
document.Open()

'... manipulate the document here

document.Close()
Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer.Length)
Response.End()
Catch(ex as Exception)
Throw ex
End Try

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top