1 Replies - 7198 Views - Last Post: 19 May 2011 - 07:01 AM Rate Topic: -----

#1 RedRabbit  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 71
  • Joined: 09-May 10

Creating a PDF using ItextSharp in a windows forms application

Posted 18 May 2011 - 11:26 PM

Creating a pdf document using Itext is quite simple if your application is a web application because you can find samples to help you out all over the web.

Creating a pdf document for a windows application on the other hand is not so easy. I cannot find a single sample online anywhere.


can you help me out with the following code, its supposed to create a pdf document but the executes however nothing is displayed the reason being Im not writing the pdf to a disk anywhere and thats where I need help:

so far this is what I have:

Private Sub PrintDefaultReport()


        'Declare PDF document
        Dim doc As New Document(PageSize.A4, 40, 40, 0, 35)
        Dim MemStream As New MemoryStream
        Dim writer As PdfWriter = PdfWriter.GetInstance(doc, MemStream)

        'print the header section (logo)
        Dim imageFilePath As String = "C:\Documents and Settings\HumanSettlements\HumanSettlements\logo.gif"
        doc.Open()

        Dim cLogo As Image = Image.GetInstance(imageFilePath)
        cLogo.Alignment = Element.ALIGN_MIDDLE

        'This adds the logo
        doc.Add(cLogo)

        'Line break
        doc.Add(New Phrase(Environment.NewLine))
        doc.Add(New Phrase(Environment.NewLine))

        'Create the title for the report
        Dim reportTitle As New Paragraph("Monthly Applications Report", TitleFont)

        reportTitle.Alignment = Element.ALIGN_MIDDLE

        doc.Add(reportTitle)

        doc.Close()
       


    End Sub




At the end of the sample asp.net code that Im using this is the code that generates the pdf file:

HttpContext.Current.Response.Buffer = True
            HttpContext.Current.Response.ClearContent()
            HttpContext.Current.Response.ClearHeaders()
            HttpContext.Current.Response.ContentType = "application/pdf"
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" & bookingNum & ".pdf")
            HttpContext.Current.Response.BinaryWrite(MemStream.GetBuffer())
            HttpContext.Current.Response.End()


What is the above equivalent for a windows application?

Any help greatly appreciated.
Thanks

This post has been edited by RedRabbit: 18 May 2011 - 11:29 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Creating a PDF using ItextSharp in a windows forms application

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9059
  • View blog
  • Posts: 34,017
  • Joined: 12-June 08

Re: Creating a PDF using ItextSharp in a windows forms application

Posted 19 May 2011 - 07:01 AM

Have you tried using that "pdfwriter" object? I am not sure if that's a custom class of yours or something else, but it would seem logical a command like
writer.write("location")

would exist...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1