开发者

opening code generated pdf in browser without saving it to either webserver/client

Is this even possible? tried several ways and i have no idea how to continue. Using vb.net in vs 200开发者_运维问答8 and itextsharp

This is my code for creating the pdf.. also have alot of code to fill it

    Dim doc As New Document(iTextSharp.text.PageSize.LETTER, 90, 80, 80, 90)
    Try

        PdfWriter.GetInstance(doc, New FileStream(Server.MapPath("PDF.pdf"),FileMode.Create))

But this saves the pdf.. can i do it any other way?


I use a MemoryStream to assemble the PDF into thus (sorry in C# but should be easily convertable):

public byte[] GetPDF()
{
    using (MemoryStream ms = new MemoryStream())
    {
        Document document = new Document(PageSize.A4, 38f, 30f, 15f, 35f);
        PdfWriter writer = PdfWriter.GetInstance(document, ms);
        ...
        document.Close();
        return (ms.GetBuffer());
    }
}

Then you can provide a byte stream back to your response stream, in MVC I do this with a FileResult return as follows:

return File(GetPDF(), System.Net.Mime.MediaTypeNames.Application.Pdf, "generated.pdf");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜