Doc AddImageToChain Function. Adds a new page from a paged HTML or PostScript render. ABCpdf .NET PDF Library.

ABCpdf .net

 
   

Adds a new page from a paged HTML or PostScript render.

 

   
Syntax  

[C#]
int AddImageToChain(int id)

[Visual Basic]
Function AddImageToChain(id As Integer) As Integer

Throws Exceptions may throw Exception()

 

   

Params
 
Name Description
id

The ID of the previous object in the chain.

return The ID of the newly added object.

 

   

Notes
 

Some web pages are too large to fit on one PDF page.

To split a web page across multiple PDF pages you need to call AddImageUrl or AddImageHtml to render the first page. The ID returned from these calls represents the head of the chain.

To add subsequent pages to the chain you need to make calls to AddImageToChain passing in the previous image from the chain each time.

As well as using chaining to split web pages across multiple PDF pages you can also use it to split your web pages across multiple columns within a page. You can even split your chain to generate multiple copies of the same page.

More information can be found in the HTML / CSS Rendering section of the documentation.

Similarly some PostScript (PS) files contain more than one page of content.

To split a PS file across multiple PDF pages you need to call AddImageFile or AddImageData to render the first page. The ID returned from these calls represents the head of the chain.

To add subsequent pages to the chain you need to make calls to AddImageToChain passing in the previous image from the chain each time.

 

   

Example
 

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.

[C#]
Doc theDoc = new Doc();
theDoc.Rect.Inset(72, 144);

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.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.

[C#]
int theID;
theID = theDoc.AddImageUrl("http://www.yahoo.com/");

[Visual Basic]
Dim theID As Integer
theID = theDoc.AddImageUrl("http://www.yahoo.com/")

We now chain subsequent pages together. We stop when we reach a page which wasn't truncated.

[C#]
while (true) {
  theDoc.FrameRect();
  if (!theDoc.Chainable(theID))
    break;
  theDoc.Page = theDoc.AddPage();
  theID = theDoc.AddImageToChain(theID);
}

[Visual Basic]
While True
  theDoc.FrameRect()
  If Not theDoc.Chainable(theID) Then
    Exit While
  End If
  theDoc.Page = theDoc.AddPage()
  theID = theDoc.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.

[C#]
for (int i = 1; i <= theDoc.PageCount; i++) {
  theDoc.PageNumber = i;
  theDoc.Flatten();
}

[Visual Basic]
For i As Integer = 1 To theDoc.PageCount
  theDoc.PageNumber = i
  theDoc.Flatten()
Next

Finally we save.

[C#]
theDoc.Save(Server.MapPath("pagedhtml.pdf"));
theDoc.Clear();

[Visual Basic]
theDoc.Save(Server.MapPath("pagedhtml.pdf"))
theDoc.Clear()

We get the following output.


pagedhtml.pdf [Page 1]

pagedhtml.pdf [Page 2]