Welcome Guest Search | Active Topics | Sign In | Register

draw line in table of contents Options
Becky
Posted: Sunday, May 27, 2012 12:22:29 AM
Rank: Advanced Member
Groups: Member

Joined: 5/24/2012
Posts: 45
Hi,
I just about have everything the way I want it.

I have a table of contents in my document. I render my html to a pdfdocument. Then I find the location of my toc entries and the page number of where they are (toc_target) in the document.

I use this information to render the page number on the toc in the correct location.

You can see my sample program at: http://pakatrak.ipower.com/2009_HRDirector/ConvertwithEO.aspx
click the 'Convert PolicyDemo htm file with EO' button

What I would like to add is a line from the toc entry to the page number.

What I am currently doing (I mostly took from the samples) is this:
Code: Visual Basic.NET
For K As Integer = 0 To TOC_ENTRIES_COUNT - 1
            Dim TOCNumber As Acm.AcmText
            Dim TOCpgNumRender As Acm.AcmRender

            'create line and page number for TOC entry
            'Create an AcmText representing the toc page number
            TOCNumber = New Acm.AcmText(arrTOC(K, 3).ToString)

            'Create an AcmRender to render the page number and line
            'The arguments are:
            ' First argument: the target page
            ' Second argument: the "Y" position
            ' Third argument: The paper margins in left, top, right, bottom order
            TOCpgNumRender = New Acm.AcmRender(doc.Pages(arrTOC(K, 2)), arrTOC(K, 1), _
                New Acm.AcmPageLayout( _
                    New Acm.AcmPadding(7.5, 0, 1, 0)))
            'Render the page number
            TOCpgNumRender.Render(TOCNumber)

            'now create the line between the toc entry and the page number
            'Add a new page
            Dim TOCpage As EO.Pdf.PdfPage = doc.Pages(arrTOC(K, 2))

            'Create a new PdfPathContent
            Dim content As New EO.Pdf.Contents.PdfPathContent()

            'Create a new sub path and set the sub path's starting point
            Dim subPath As New EO.Pdf.Drawing.PdfSubPath()
            subPath.From = New EO.Pdf.Drawing.PdfPoint(arrTOC(K, 0) + 250, 640 - arrTOC(K, 1))

            'Draw a line from the current position to the right edge
            Dim line As New EO.Pdf.Drawing.PdfPathLineSegment(New EO.Pdf.Drawing.PdfPoint(500, 640 - arrTOC(K, 1)))
            subPath.Segments.Add(line)

            'Add the sub path into the path
            content.Path.SubPaths.Add(subPath)

            'Stroke the path
            content.LineWidth = 1.0F
            If K Mod 2 = 0 Then
                content.StrokingColor = New EO.Pdf.Drawing.PdfColor(Color.Red)
            Else
                content.StrokingColor = New EO.Pdf.Drawing.PdfColor(Color.Black)
            End If
            content.Action = EO.Pdf.Contents.PdfPathPaintAction.Stroke

            'Add the path into the page
            TOCpage.Contents.Add(content)

        Next


If you look at the sample this writes all the lines at the same x location and a very small y location. It would be best to be able to find the right end of the entry, start the line there and go to a specific spot at the right side of the document.

I can draw this line using html to pdf in the after or before render event. I just couldn't quite figure out how to do that.

What am I doing wrong?
Thanks!
Becky
eo_support
Posted: Sunday, May 27, 2012 9:22:32 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

I haven't debugged through your code but your code looks fine to us structurally. The only thing you want to be careful is the coordinates you get elsewhere (both from HTML to PDF and PDF Creator interface) are in inches and the Y axis goes from top to the bottom. However the coordinates for PdfPathContent is in 1/72 inch and the Y axis goes from bottom to top. So you have to have some kind of conversions.

However it might be much easier if you use HTML to draw the lines. Here is a small piece of HTML code that creates one TOPC entry:

Code: HTML/ASPX
<table>
  <tr>
    <td nowrap="nowrap">
        <!-- The TOC entry text -->
        <a href="#chapter1">Chapter 1</a>
    </td>
    <td width="99%" valign="center">
        <!-- This creates the line -->
        <div style="height:1px;background-color:black;"></div>
    </td>
    <td nowrap="nowrap">
        <!-- Page number text to be "fixed up" later -->
        <div style="width:100px">page #</div>
    </td>
   </tr>
   .... more rows.....
</table>


The obvious advantages to use HTML to constructor the TOC include less code and automatic links (When you use an A element in your HTML, it automatically becomes clickable in the PDF). Note you still need to fill the page numbers in. You can either do it with PDF Creator interface, or simply run the converter for the first time to get all the page numbers, then re-create the whole HTML with the correct page numbers and then run the converter again.

Hope this helps.

Thanks!
Becky
Posted: Sunday, May 27, 2012 10:32:33 AM
Rank: Advanced Member
Groups: Member

Joined: 5/24/2012
Posts: 45
Yes, I was not multiplying the y coordinate by 72. It is working now.
Thanks!
eo_support
Posted: Sunday, May 27, 2012 2:14:12 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Great! Glad that everything is working for you. Feel free to let us know if there is anything else.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.