Cannot open pdf.
- From: "HINDI TLC" <hindi_tlc (at) hotmail.com>
- Date: Fri, 19 May 2006 10:15:48 +0200
Hi
My application gives me an error when opening the pdf. Acrobat Reader says
the file is damaged and cannot be open.
My code is attached.
From: bruno <bruno (at) lowagie.com>
To: HINDI TLC <hindi_tlc (at) hotmail.com>
CC: itext-questions (at) lists.sourceforge.net
Subject: Re: [iText-questions] Re: Table Font
Date: Wed, 17 May 2006 15:51:53 +0200
HINDI TLC wrote:
Thx Again Bruno.. Works fine now...
One more question..
My app creates a physical file. How do get to create the file in memory
and display it in my browser..
Create the file in memory by using a ByteArrayOutputStream
instead of a FileOutputStream.
When I close my browser, my file must no longer exist. It must be flushed.
When the ByteArrayOutputStream goes 'out of scope',
it will be garbage collected.
Read http://itextdocs.lowagie.com/tutorial/general/webapp/
for more information.
br,
Bruno
_________________________________________________________________
Discover the magic of RSS feeds at MSN South Africa! http://za.msn.com/
Private Sub ViewPdf(ByVal fs As Stream)
Dim buffer(fs.Length) As Byte
fs.Position = 0
fs.Read(buffer, 0, fs.Length)
Response.Clear()
Response.ContentType = "application/pdf"
Response.BinaryWrite(buffer)
Response.OutputStream.Flush()
Response.OutputStream.Close()
fs.Close()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Try
Dim doc As Document = New Document(PageSize.A4.Rotate, 10,
10, 10, 10)
Dim ms As New MemoryStream
Dim writer As PdfWriter = PdfWriter.GetInstance(doc, ms)
PdfWriter.GetInstance(doc, ms)
doc.Open()
Dim p As New Paragraph("Sale ID",
FontFactory.GetFont(FontFactory.COURIER, 10, Font.UNDERLINE))
doc.Add(p)
ViewPdf(ms)
doc.Close()
Catch de As DocumentException
Label1.Text = "de:" & de.Message()
Catch ioe As IOException
Label1.Text = "ioe: " & ioe.Message
Catch ex As Exception
Label1.Text = "ex: " & ex.Message
End Try
End If
End Sub