Welcome Guest Search | Active Topics | Sign In | Register

html5 compliance regarding links and anchors Options
Ramon
Posted: Monday, February 18, 2013 2:43:49 AM
Rank: Member
Groups: Member

Joined: 2/17/2013
Posts: 14
LS,

I'm trying to figure out why my links and anchors are not working when converting xhtml to pdf.

Case:
- multiple xhtml files with anchors and links
- some links refer to anchors not yet converted and the other way around

The anchors look like this:
Code: HTML/ASPX
<div class="cadretitle1"><a name="FCOM_F_00000707">GENERAL</a></div>


The links look like this:
Code: HTML/ASPX
<div class="left-margin">
    <p class="para_no_margin">
        <a class="abb" href="#FCOM_F_00000707" title="Nosewheel Steering">NWS</a> limit angle
    </p>
</div>


The result PDF document doesn't provide the clickable links I was hoping for.
Could this be the result of HTML5 specs and should I change the anchors to:
Code: HTML/ASPX
<div class="cadretitle1" id="FCOM_F_00000707">GENERAL</div>



Any help appriciated and thanks in advance!

Ramon


eo_support
Posted: Monday, February 18, 2013 10:10:15 AM
Rank: Administration
Groups: Administration

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

I do not see any problem with your HTML. If you can post the full HTML file you are trying to convert, and tell us which link is not correctly converted, we will take a look and see what we can find.

Thanks!
Ramon
Posted: Monday, February 18, 2013 11:19:09 AM
Rank: Member
Groups: Member

Joined: 2/17/2013
Posts: 14
Thanks for looking into it.
Below a simplefied example.

file1
Code: HTML/ASPX
<body>
    <div id="body_content">
        <div class="cadretitle" id="FCOM_F_00000770">
            <div class="cadretitle1">GROUND MANEUVERING</div>
        </div>
    </div>
...some more html
</body>


file2
Code: HTML/ASPX
<body>
    <div id="body_content">
        <div class="cadretitle" id="FCOM_F_00000771">
            <div class="cadretitle1">SOMETHING ELSE</div>
        </div>
    </div>
...some more html
    <a href="FCOM_F_00000772" title="">ANOTHER TITLE</a> <!-- forward linking -->
</body>


file3
Code: HTML/ASPX
<body>
    <div id="body_content">
        <div class="cadretitle" id="FCOM_F_00000772">
            <div class="cadretitle1">ANOTHER TITLE</div>
        </div>
    </div>
    <a href="#FCOM_F_00000770" title="GROUND MANEUVERING">GROUND MANEUVERING</a> <!-- backward linking -->
...some more html
</body>


code
Code: C#
HtmlToPdfOptions PdfOptions = new HtmlToPdfOptions()
                            {
                                PageSize = PdfPageSizes.A4,
                                OutputArea = new RectangleF(0.3f, 0.75f, 7.7f, 10.2f),
                                NoLink = false,
                                NoScript = true,
                                JpegQualityLevel = 70,
                                PreserveHighResImages = false,
                                HeaderHtmlFormat = header,
                                FooterHtmlFormat = footer
                            };

HtmlToPdf.ConvertUrl(file1, FCOMPDFDocument, PdfOptions); // contains no links, just anchor
HtmlToPdf.ConvertUrl(file2, FCOMPDFDocument, PdfOptions); // contains a link to file3
HtmlToPdf.ConvertUrl(file3, FCOMPDFDocument, PdfOptions); // contains a link to file1


This generates the pdf just fine, but not the links I was hoping to achieve.
eo_support
Posted: Monday, February 18, 2013 12:48:45 PM
Rank: Administration
Groups: Administration

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

You can not have link from one document to another document. A link is either an anchor to another location of the same HTML file, or a Url to another file. Merging the output to the same PDF document does not change the fact that these are different HTML files.

Thanks!
Ramon
Posted: Monday, February 18, 2013 1:02:09 PM
Rank: Member
Groups: Member

Joined: 2/17/2013
Posts: 14
Thanks!

I was afraid for this answer...

Is there an option to find and create bookmarks to the anchors?
If that's possible I can merge al the XML and create my bookmarks afterwards, this will provide me with all the wanted functionality.

Regards,

Ramon
eo_support
Posted: Monday, February 18, 2013 3:02:08 PM
Rank: Administration
Groups: Administration

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

Yes. You can use the HtmlToPdfResult object returned to you to get a HtmlDocument object, then use any of the GetElementXXX on the HtmlDocument object to get an HtmlElement object. Then create a bookmark with from that HtmlElement:

http://www.essentialobjects.com/doc/4/eo.pdf.htmlelement.createbookmark_overloads.aspx

You can then add it to the root level bookmark collection:

http://www.essentialobjects.com/doc/4/eo.pdf.pdfdocument.bookmarks.aspx

Or add it as a child bookmark of another bookmark:

http://www.essentialobjects.com/doc/4/eo.pdf.pdfbookmark.childnodes.aspx

Hope this helps. Please feel free to let us know if you have any questions.

Thanks!
Ramon
Posted: Friday, February 22, 2013 4:14:07 AM
Rank: Member
Groups: Member

Joined: 2/17/2013
Posts: 14
Hi again,

Sorry for the long time no reaction here.

I wrote an example to check for the linking functionality and unfortunately, I don't get it to work...

here is my xhtml:
Code: HTML/ASPX

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta content="text/html;charset=UTF-8" http-equiv="Content-Type" />
    <title>title XHTML</title>
    <link href=".\ct_day.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div>
      <a href="#internal_bottomtarget" id="bottomlink">link to the bottom</a>
    </div>
    <div id="topdestination">
      <a name="internal_toptarget" id="internal_toptarget">target  at the top</a>
    </div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
.
.
.
.
.
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>blah</div>
    <div>
      <a href="testhtmlinternallink.xhtml#internal_toptarget" id="toplink">link to the top</a>
    </div>
    <div id="bottomdestination">
      <a name="internal_bottomtarget" id="internal_bottomtarget"> target="" at="" the="" bottom=""</a>
    </div>
  </body>
</html>


and here is the code:
Code: C#
PdfDocument testPDF = new PdfDocument();
  
            HtmlToPdfOptions PdfOptions = new HtmlToPdfOptions()
            {
                PageSize = PdfPageSizes.A4,
                OutputArea = new RectangleF(0.3f, 0.75f, 7.7f, 10.2f),
                NoLink = false,
                NoScript = true,
                JpegQualityLevel = 70,
                PreserveHighResImages = false
            };
 
            HtmlToPdfResult result = HtmlToPdf.ConvertUrl(".\\testhtmlinternallink.xhtml", testPDF);
            //result = HtmlToPdf.ConvertUrl(".\\testhtml.xhtml", testPDF);
            //result = HtmlToPdf.ConvertUrl(".\\testhtmlinternallink.xhtml", testPDF);
            //result = HtmlToPdf.ConvertUrl(".\\testhtmlexternallink.xhtml", testPDF);
            //result = HtmlToPdf.ConvertUrl(".\\testhtml.xhtml", testPDF);

            // create link from bottom to top
            HtmlElement link = result.HtmlDocument.GetElementById("toplink");
            HtmlElement destination = result.HtmlDocument.GetElementById("topdestination");
            link.CreateLink( destination.Location );

            //create link from top to bottom
            link = result.HtmlDocument.GetElementById("bottomlink");
            destination = result.HtmlDocument.GetElementById("bottomdestination");
            link.CreateLink(destination.Location);

            testPDF.Save(".\\TestPDF.pdf");


Both links don't work in the resulting PDF
I'm working with the trial version

Regards

Ramon
Ramon
Posted: Friday, February 22, 2013 6:22:44 AM
Rank: Member
Groups: Member

Joined: 2/17/2013
Posts: 14
Found the problem...

HtmlToPdf.ConvertUrl doesn't create links when using other filetypes then .html or .htm

So the above example works, even without creating the links programmatically, when I change my filename from .xhtml to .html

Can I request there for to add .xhtml file extension as well?

Ramon
eo_support
Posted: Friday, February 22, 2013 9:34:42 AM
Rank: Administration
Groups: Administration

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

You missed the point in our previous reply. You can not do cross link like this. Period.

After you merge HTML file A, B and C into a single PDF file P, you end up with a single PDF file P. HTML file A, B, C does not exist in PDF file P. As such:

1. A link inside A that points somewhere in B does NOT point anywhere inside P. It still points to a Url "B#somewhere", this Url has no meaning inside P since it can not resolve the "B" part of that Url (Remember B does not exist in P);

2. A link inside A that points somewhere inside A will be preserved. So a link inside A such as "#somewhere" will point to the same location inside P;

#1 is a cross link. It does not work. #2 is a in document link. It will work.

The fact that you are merging multiple HTML files into a single PDF file DOES NOT change cross link into in document link.

Hope this clears it up for you.

Thanks!
Ramon
Posted: Friday, February 22, 2013 9:56:18 AM
Rank: Member
Groups: Member

Joined: 2/17/2013
Posts: 14
Thanks for getting back... I didn't miss the point: file to file linking is not possible, which makes sense...

You are missing my point:
In-document linking with a file extension of .xhtml doesn't generate the links.
The same in-document linking with a file extension .html (a simple rename does the job) generates the links.

There for my request to add the xhtml file extension to this functionality.

Regards,

Ramon
eo_support
Posted: Friday, February 22, 2013 10:29:08 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Yes. You are right. This looks like a problem on our side. We will provide you an update build shortly.

Thanks!
eo_support
Posted: Friday, February 22, 2013 11:10:13 AM
Rank: Administration
Groups: Administration

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

We have posted a new build that should fix this issue. Please see your private message for the download location.

Thanks!
Ramon
Posted: Friday, February 22, 2013 11:56:31 AM
Rank: Member
Groups: Member

Joined: 2/17/2013
Posts: 14
Downloaded the new build and .xhtml file extension is functional as well now.

THANKS!
eo_support
Posted: Friday, February 22, 2013 2:30:01 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Great. Thanks for confirming the fix!


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.