Quantcast

Error end text missing on iTextSharp after some text inserts

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Error end text missing on iTextSharp after some text inserts

hugetto
This post has NOT been accepted by the mailing list yet.
I'm trying to create a pdf with iTextSharp but after I insert some text on the pdf, the pdf gets corrupted and displays this nasty popup on a Pdf Reader (see link)



I've also used another program to check out what was the error problem and it seems the iText library stops adding begin/end blocks when new text is insert



I'm using the latest version of iTextSharp (v.5.5.8.0) And this is the simple code I use

Sub Main()
    Dim objPageSize As iTextSharp.text.Rectangle
    Dim objDocument As Document
    Dim objWriter As pdf.PdfWriter

    objPageSize = New Rectangle(842, 595)
    objDocument = New Document(objPageSize, 50, 50, 50, 50)
    objWriter = PdfWriter.GetInstance(objDocument, New System.IO.FileStream("test.pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write))
    Call objDocument.Open()
    objWriter.Open()
    objWriter.DirectContent.BeginText()

    For i As Integer = 0 To 85
        Dim ct As ColumnText = New ColumnText(objWriter.DirectContent)
        ct.SetSimpleColumn(1, i * 5, 100, 100, 0, Element.ALIGN_LEFT)
        Dim phrase As Phrase = New Phrase("hello", FontFactory.GetFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, False, 4))
        ct.SetText(phrase)
        ct.Go()
    Next


    objWriter.DirectContent.EndText()
    objDocument.Close()
    objWriter.Close()


End Sub
It look like a bug on the library.

Any help would be appreciated

Thank you!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error end text missing on iTextSharp after some text inserts

hugetto
This post has NOT been accepted by the mailing list yet.
Ok I just found the answer myself.

I'll post it here for any other people might help.

You don't need to call objWriter.DirectContent.BeginText() and objWriter.DirectContent.EndText()

The ColumnText class does it for you
Loading...