This example shows how to import an HTML page into a multi-page
PDF document.
We first create a Doc object and
inset the edges a little so that the HTML will appear in the middle
of the page.
using (Doc doc = new Doc()) {
doc.Rect.Inset(72, 144);
Using doc As New Doc()
doc.Rect.Inset(72, 144)
We add the first page of HTML. We save the returned ID as this
will be used to add subsequent pages.
int theID;
theID = doc.AddImageUrl("http://www.yahoo.com/");
Dim theID As Integer
theID = doc.AddImageUrl("http://www.yahoo.com/")
We now chain subsequent pages together. We stop when we reach a
page which wasn't truncated.
while (true) {
doc.FrameRect();
if (!doc.Chainable(theID))
break;
doc.Page = doc.AddPage();
theID = doc.AddImageToChain(theID);
}
While True
doc.FrameRect()
If Not doc.Chainable(theID) Then
Exit While
End If
doc.Page = doc.AddPage()
theID = doc.AddImageToChain(theID)
End While
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.
for (int i = 1; i <= doc.PageCount; i++) {
doc.PageNumber = i;
doc.Flatten();
}
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("pagedhtml.pdf"));
}
doc.Save(Server.MapPath("pagedhtml.pdf"))
End Using
We get the following output.

pagedhtml.pdf [Page 1] |

pagedhtml.pdf [Page 2] |
|