Hi expert,
i want to created tagged PDF . I am using existing PDF and read the contents
and create a new PDF with tag. Following code works well but i am unable to
read the formatting of existing pdf. In following code i comment the code
which split the page content on the base of new line character

Try
            Me.Cursor = Cursors.WaitCursor
            Dim reader As PdfReader = New PdfReader(txtPath.Text.Trim)
            Dim n As Integer = reader.NumberOfPages
            Dim psize As iTextSharp.text.Rectangle = reader.GetPageSize(1)
            Dim width1 As Single = psize.Width
            Dim height1 As Single = psize.Height


            Dim parser As PDF.parser.PdfReaderContentParser = New
parser.PdfReaderContentParser(reader)
            Dim mystrtergy As parser.ITextExtractionStrategy

            Dim PageContent(n) As String

            For k As Integer = 1 To reader.NumberOfPages
                mystrtergy = parser.ProcessContent(k, New
PDF.parser.SimpleTextExtractionStrategy)

                PageContent(k - 1) = mystrtergy.GetResultantText
            Next
            reader.Close()

            If (n > 0) Then
                Dim document As iTextSharp.text.Document = New
iTextSharp.text.Document()
                Dim myWriter As PdfWriter = PdfWriter.GetInstance(document,
New FileStream(PDFPath("TaggedCheck.pdf"), FileMode.Create))
                myWriter.SetTagged()

                'myWriter.UserProperties = True

                document.Open()
                Dim root As PdfStructureTreeRoot =
myWriter.StructureTreeRoot
                Dim eTop As PdfStructureElement = New
PdfStructureElement(root, New PdfName("Correctly_Tagged.pdf"))
                root.MapRole(New PdfName("Everything"), New PdfName("Sect"))
                Dim cb As PdfContentByte = myWriter.DirectContent
                Dim bf As PDF.BaseFont =
PDF.BaseFont.CreateFont(PDF.BaseFont.HELVETICA, PDF.BaseFont.WINANSI, False)


                For k As Integer = 1 To n

                    If k > 1 Then
                        document.NewPage()
                    End If

                    Dim e1 As PdfStructureElement = New
PdfStructureElement(eTop, PdfName.PAGE)
                    Dim userprop As PdfDictionary = New PdfDictionary
                    userprop.Put(PdfName.O, PdfName.USERPROPERTIES)

                    Dim properties As PdfArray = New PdfArray

                    Dim property1 As PdfDictionary = New PdfDictionary
                    property1.Put(PdfName.N, New PdfString("Page Number"))
                    property1.Put(PdfName.V, New PdfNumber(k))
                    properties.Add(property1)

                    userprop.Put(PdfName.P, properties)
                    e1.Put(PdfName.A, userprop)


                    Dim par As iTextSharp.text.Paragraph = New
iTextSharp.text.Paragraph(PageContent(k - 1))
                    par.KeepTogether = True
                    Dim ct As ColumnText = New ColumnText(cb)
                    ct.SetSimpleColumn(0, 0, width1, height1)
                    ct.AddElement(par)
                    Dim e2 As PdfStructureElement = New
PdfStructureElement(e1, PdfName.P)
                    cb.BeginText()
                    cb.BeginMarkedContentSequence(e2)
                    ct.Go()
                    cb.EndMarkedContentSequence()
                    cb.EndText()

                    'Dim starty As Single = height1 - 35
                    'Dim stringArray() As String =
Microsoft.VisualBasic.Split(PageContent(k -
1),Microsoft.VisualBasic.ControlChars.Lf)
                    'Dim ChunkArray(stringArray.Length) As
iTextSharp.text.Chunk
                    'For i As Integer = 0 To stringArray.Length - 1
                    '    Dim e2 As PdfStructureElement = New
PdfStructureElement(e1, PdfName.H)
                    '    cb.SetLeading(16)
                    '    cb.SetFontAndSize(bf, 12)
                    '    'cb.SetTextMatrix(100, starty)
                    '    cb.BeginText()
                    '    cb.BeginMarkedContentSequence(e2)
                    '    'cb.ShowText(stringArray(i))
                    '
cb.ShowTextAligned(iTextSharp.text.Element.ALIGN_LEFT, stringArray(i), 10,
starty, 0)
                    '    cb.EndMarkedContentSequence()
                    '    cb.EndText()
                    '    starty -= 18
                    'Next
                Next

                document.Close()

            End If
        Catch ex As Exception

        End Try

Please suggest or provide some helpful link for read the formatting of
existing PDF.

-- 
Please, consider your environmental responsibility.
Before printing this e-mail ask yourself: "Do I need a hard copy?"
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to