MultiColumnText and preventing widows and orphans

View: New views
2 Messages — Rating Filter:   Alert me  

MultiColumnText and preventing widows and orphans

by William Rickards :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've read chapter 7 of "Itext in Action" regarding the ColumnText and
MultiColumnText objects.
I need to control widows and orphans when I add a bunch of tables to
the document.
I've got a working example using the ColumnText object.

Now I'm trying to figure out how you would do the same with the
MultiColumnText object.
And I'm confused.  Maybe I shouldn't use the MultiColumnText object,
you tell me.

In one example in chapter seven, section 7.4.1, it uses
AddRegularColumns and then just document.add(mct).
It doesn't seem to need to do mct.NextColumn, it seems to be adding
all the content, more than just one column or page, or am I missing
something there.

In another example in chapter seven it uses AddColumn and then does a
loop while mct.isOverflow() is true.
This time it calls mct.nextColumn.

What controls when you need to call nextColumn?

Is there a way to do something like ColumnText.Go(true) in MultiColumnText?
I need to control when my tables move to the next column (page) and
insert headers when they do.

--
Will Rickards

My ColumnText Example
   Private Function ColumnTest2() As System.IO.MemoryStream

      Dim docTest As iTextSharp.text.Document
      Dim wrtTest As iTextSharp.text.pdf.PdfWriter
      Dim cbTest As iTextSharp.text.pdf.PdfContentByte
      Dim ctTest As iTextSharp.text.pdf.ColumnText
      Dim intStatus As System.Int32
      Dim stmPDF As System.IO.MemoryStream
      Dim tabTemp As iTextSharp.text.pdf.PdfPTable
      Dim intRow As System.Int32
      Dim objCell As iTextSharp.text.pdf.PdfPCell
      Dim sngPos As System.Single

      'm_intHitBorder = iTextSharp.text.pdf.PdfPCell.BOX
      m_intHitBorder = iTextSharp.text.pdf.PdfPCell.NO_BORDER

      ' create letter sized document with 0.5 inch margins
      docTest = New
iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 36, 36, 36,
36)

      ' create file stream to hold output
      ' get pdfwriter object that links the filestream with our document
      stmPDF = New System.IO.MemoryStream
      wrtTest = iTextSharp.text.pdf.PdfWriter.GetInstance(docTest, stmPDF)
      wrtTest.CloseStream = False

      ' open the document
      docTest.Open()

      ' get fonts
      SetupGenericITextObjects()

      ' get content
      cbTest = wrtTest.DirectContent

      ' create column text object
      ctTest = New iTextSharp.text.pdf.ColumnText(cbTest)
      ctTest.SetSimpleColumn(36.0F, 36.0F,
iTextSharp.text.PageSize.LETTER.Width - 36.0F,
iTextSharp.text.PageSize.LETTER.Height - 36.0F, 16.0F,
iTextSharp.text.Element.ALIGN_JUSTIFIED)

      ' add some text
      With ctTest

         For intRow = 1 To 34

            ' save initial y position
            sngPos = .YLine

            ' add table to column test
            tabTemp = AddMatterDetail()

            objCell = New iTextSharp.text.pdf.PdfPCell(New
iTextSharp.text.Phrase("Row " & CStr(intRow), m_fntArial9))
            With objCell
               .HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT
               .Border = m_intHitBorder
               .Colspan = 6
            End With
            tabTemp.AddCell(objCell)

            .AddElement(tabTemp)

            ' simulate addition to document to see if it fits in the
column (page)
            intStatus = .Go(True)

            ' if it fits in the column (page)
            If Not iTextSharp.text.pdf.ColumnText.HasMoreText(intStatus) Then

               ' add element back
               .AddElement(tabTemp)

               ' reset the y position
               .YLine = sngPos

               ' add it to the document
               .Go(False)

               ' if it doesn't fit on the column (page)
            Else

               ' start a new page
               docTest.NewPage()

               ' clear the contents
               .SetText(New iTextSharp.text.Phrase())

               ' add it to the column
               .AddElement(tabTemp)

               ' reset the y position to the top of the page
               .YLine = iTextSharp.text.PageSize.LETTER.Height - 36.0F

               ' add it to the document
               .Go(False)

            End If

         Next intRow

      End With

      docTest.Close()

      stmPDF.Seek(0, IO.SeekOrigin.Begin)

      ColumnTest2 = stmPDF

   End Function

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@...
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions

Re: MultiColumnText and preventing widows andorphans

by Paulo Soares :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

MultiColumnText is a convenience class of ColumnText. Forget about it and
use ColumnText if you need full control.

Paulo

----- Original Message -----
From: "William Rickards" <itext@...>
To: <itextsharp-questions@...>
Sent: Wednesday, July 23, 2008 9:21 PM
Subject: [itextsharp-questions] MultiColumnText and preventing widows
andorphans


I've read chapter 7 of "Itext in Action" regarding the ColumnText and
MultiColumnText objects.
I need to control widows and orphans when I add a bunch of tables to
the document.
I've got a working example using the ColumnText object.

Now I'm trying to figure out how you would do the same with the
MultiColumnText object.
And I'm confused.  Maybe I shouldn't use the MultiColumnText object,
you tell me.

In one example in chapter seven, section 7.4.1, it uses
AddRegularColumns and then just document.add(mct).
It doesn't seem to need to do mct.NextColumn, it seems to be adding
all the content, more than just one column or page, or am I missing
something there.

In another example in chapter seven it uses AddColumn and then does a
loop while mct.isOverflow() is true.
This time it calls mct.nextColumn.

What controls when you need to call nextColumn?

Is there a way to do something like ColumnText.Go(true) in MultiColumnText?
I need to control when my tables move to the next column (page) and
insert headers when they do.

--
Will Rickards

My ColumnText Example
   Private Function ColumnTest2() As System.IO.MemoryStream

      Dim docTest As iTextSharp.text.Document
      Dim wrtTest As iTextSharp.text.pdf.PdfWriter
      Dim cbTest As iTextSharp.text.pdf.PdfContentByte
      Dim ctTest As iTextSharp.text.pdf.ColumnText
      Dim intStatus As System.Int32
      Dim stmPDF As System.IO.MemoryStream
      Dim tabTemp As iTextSharp.text.pdf.PdfPTable
      Dim intRow As System.Int32
      Dim objCell As iTextSharp.text.pdf.PdfPCell
      Dim sngPos As System.Single

      'm_intHitBorder = iTextSharp.text.pdf.PdfPCell.BOX
      m_intHitBorder = iTextSharp.text.pdf.PdfPCell.NO_BORDER

      ' create letter sized document with 0.5 inch margins
      docTest = New
iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 36, 36, 36,
36)

      ' create file stream to hold output
      ' get pdfwriter object that links the filestream with our document
      stmPDF = New System.IO.MemoryStream
      wrtTest = iTextSharp.text.pdf.PdfWriter.GetInstance(docTest, stmPDF)
      wrtTest.CloseStream = False

      ' open the document
      docTest.Open()

      ' get fonts
      SetupGenericITextObjects()

      ' get content
      cbTest = wrtTest.DirectContent

      ' create column text object
      ctTest = New iTextSharp.text.pdf.ColumnText(cbTest)
      ctTest.SetSimpleColumn(36.0F, 36.0F,
iTextSharp.text.PageSize.LETTER.Width - 36.0F,
iTextSharp.text.PageSize.LETTER.Height - 36.0F, 16.0F,
iTextSharp.text.Element.ALIGN_JUSTIFIED)

      ' add some text
      With ctTest

         For intRow = 1 To 34

            ' save initial y position
            sngPos = .YLine

            ' add table to column test
            tabTemp = AddMatterDetail()

            objCell = New iTextSharp.text.pdf.PdfPCell(New
iTextSharp.text.Phrase("Row " & CStr(intRow), m_fntArial9))
            With objCell
               .HorizontalAlignment =
iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT
               .Border = m_intHitBorder
               .Colspan = 6
            End With
            tabTemp.AddCell(objCell)

            .AddElement(tabTemp)

            ' simulate addition to document to see if it fits in the
column (page)
            intStatus = .Go(True)

            ' if it fits in the column (page)
            If Not iTextSharp.text.pdf.ColumnText.HasMoreText(intStatus)
Then

               ' add element back
               .AddElement(tabTemp)

               ' reset the y position
               .YLine = sngPos

               ' add it to the document
               .Go(False)

               ' if it doesn't fit on the column (page)
            Else

               ' start a new page
               docTest.NewPage()

               ' clear the contents
               .SetText(New iTextSharp.text.Phrase())

               ' add it to the column
               .AddElement(tabTemp)

               ' reset the y position to the top of the page
               .YLine = iTextSharp.text.PageSize.LETTER.Height - 36.0F

               ' add it to the document
               .Go(False)

            End If

         Next intRow

      End With

      docTest.Close()

      stmPDF.Seek(0, IO.SeekOrigin.Begin)

      ColumnTest2 = stmPDF

   End Function



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@...
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
LightInTheBox - Buy quality products at wholesale price