This example shows how to import an HTML page which uses named
destinations.
We first create a Doc object and
inset the edges a little so that the HTML will appear in the middle
of the page. We assign the appropriate HTML options so that links
will be rendered live.
using (Doc doc = new Doc()) {
doc.Rect.Inset(18, 18);
doc.HtmlOptions.AddLinks = true;
Using doc As New Doc()
doc.Rect.Inset(18, 18)
doc.HtmlOptions.AddLinks = True
We add the pages to the document.
int theID = doc.AddImageUrl("http://www.websupergoo.com/support.htm");
while (true) {
if (!doc.Chainable(theID))
break;
doc.Page = doc.AddPage();
theID = doc.AddImageToChain(theID);
}
Dim theID As Integer = doc.AddImageUrl("http://www.websupergoo.com/support.htm")
While True
If Not doc.Chainable(theID) Then
Exit While
End If
doc.Page = doc.AddPage()
theID = doc.AddImageToChain(theID)
End While
The URL we've referenced makes extensive use of named
destinations. We want these named destination links to take us
between pages on the PDF rather than taking us to the original
URL.
After adding the pages, we can flatten them. We can't do this
until after the pages have been added because flattening will
invalidate our previous ID and break the chain.
doc.HtmlOptions.LinkPages();
for (int i = 1; i <= doc.PageCount; i++) {
doc.PageNumber = i;
doc.Flatten();
}
doc.HtmlOptions.LinkPages()
Dim i As Integer = 1
While i <= doc.PageCount
doc.PageNumber = i
doc.Flatten()
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
Finally, we save.
doc.Save(Server.MapPath("linkpages.pdf"));
}
doc.Save(Server.MapPath("linkpages.pdf"))
End Using
We get the following output. The links work – where possible –
within the PDF.
linkpages.pdf [Page 1] |
linkpages.pdf [Page 2] |
|