how would i go about generating PDF on the fly with asp.net?
i found some itextsharp examples that can create PDF file, but i would like
to write a cutome handler than generates PDFs on the fly.
This is what i have some far
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "application/pdf";
context.Response.AddHeader("content-disposition", "attachment;
filename=\"document.pdf\"");
Document document = new Document();
PdfWriter.GetInstance(document, not sure how to put here);
document.Open();
document.Add(new Paragraph("hello world"));
document.Close();
}
context.Response.OutputStream
Good luck.
"Tem" <tem...@yahoo.com> wrote in message
news:OATpwf4C...@TK2MSFTNGP05.phx.gbl...
Then, when I was done, I dumped the memory stream to the
Response.BinaryWrite.
If you need more help, I can dig around my old files to see if I have a
sample, I just can't find one right now.
--
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
"Tem" <tem...@yahoo.com> wrote in message
news:OATpwf4C...@TK2MSFTNGP05.phx.gbl...
"Ashot Geodakov" <a_geo...@nospam.hotmail.com> wrote in message
news:uma7cn4C...@TK2MSFTNGP06.phx.gbl...
The main idea is that you write your output to some stream. So instead of a
FileStream you use any other stream, in this case OutputStream. It'll need
some tweaking. Perhaps use MemoryStream first, as it has been suggested,
then dump its contents to HttpResponse.OutputStream.
Try to just take an existing PDF file and send it using
Response.TransmitFile().
"Tem" <tem...@yahoo.com> wrote in message
news:ubOCZ04C...@TK2MSFTNGP06.phx.gbl...
> It's been a long time since I played with iTextSharp, but you have to
> stream it to an intermediate source before you can dump it to the browser.
> If I remember correctly, I first created a memory stream then passed that
> to the GetInstance.
>
> Then, when I was done, I dumped the memory stream to the
> Response.BinaryWrite.
Siberix pretty much takes care of all of that for you:
http://www.siberix.com
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Document document= new Document();
PdfWriter writer = PdfWriter.getInstance(document, memStream );
writer.Open();
document.Open();
// do a bunch of stuff with the document object
document.Close();
writer.Close();
Response.OutputStream.Write(memStream .GetBuffer(), 0, memStream
.GetBuffer().Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Of course, this was a while ago so I'm not sure if it works with the newer
releases but it should.
--
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression
"Tem" <tem...@yahoo.com> wrote in message
news:ODwshx4C...@TK2MSFTNGP02.phx.gbl...
> Could you look for that sample?
>
>
> Thank you
>
>
> "Mark Fitzpatrick" <mark...@fitzme.com> wrote in message
> news:uzHfht4C...@TK2MSFTNGP05.phx.gbl...
memStream.GetBuffer().Length may return an incorrect size, since the
internal buffer can grow bigger than its actual contents. memStream.Length
should be used instead, imho...
"Mark Fitzpatrick" <mark...@fitzme.com> wrote in message
news:%23l6RxM5...@TK2MSFTNGP02.phx.gbl...
Downloaded the trial, absolutely loved it, company purchased it, and we've
never looked back.
Not affiliated in anyway, just a very satisfied customer/user.
hth,
Brian
"Tem" <tem...@yahoo.com> wrote in message
news:OATpwf4C...@TK2MSFTNGP05.phx.gbl...
thanks for your help
Tem
"Mark Fitzpatrick" <mark...@fitzme.com> wrote in message
news:%23l6RxM5...@TK2MSFTNGP02.phx.gbl...