Doc AddImageDoc Function. Draw a page from one PDF document onto the current page of this document. ABCpdf .NET PDF Library.

ABCpdf .net

 
   

Draw a page from one PDF document onto the current page of this document.

 

   
Syntax  

[C#]
int AddImageDoc(Doc doc, int page, XRect rect)
int AddImageDoc(Doc doc, int page, XRect rect, bool copyAnnotations)
int AddImageDoc(Doc doc, int page, XRect rect, double alpha)

[Visual Basic]
Function AddImageDoc(doc As Doc, page As Integer, rect As XRect) As Integer
Function AddImageDoc(doc As Doc, page As Integer, rect As XRect, copyAnnotations As Boolean) As Integer
Function AddImageDoc(doc As Doc, page As Integer, rect As XRect, copyAnnotations As Boolean, alpha As Double) As Integer

 

   

Params
 
Name Description
doc

The document to be used as the source.

page

The page you want drawn. Use one to indicate the first page.

rect

The portion of the page you want drawn. Pass null to specify the entire page.

The format of this string should be the same as that obtained via the XRect.String property.

copyAnnotations Whether to copy fields and annotations - default false.
alpha The level of alpha to apply to the drawn page from transparent through to fully opaque (0 to 255).
return The ID of the newly added Image Object.

 

   

Notes
 

Draw a page from one PDF document onto the current page of this document returning the ID of the newly added object.

The page is scaled to fill the current Rect. It is transformed using the current Transform.

Many field and annotation types can only exist as a simple rectangle with sides parallel to the page borders. For this reason you should be cautious about the transforms you use when specifying that annotations should be copied. A transform which involves scale and translation will be fine but one involving rotation and skew factors may result in unusual output if the field or annotation does not support this combination.

The Refactor setting determines whether new/modified redundant objects are eliminated. The Preflight setting determines whether objects in the destination document are validated before this operation is performed. Unless the document and the pages are big in terms of memory use and have many common objects, it is faster to disable refactor and preflight for adding the pages and enable them for saving the document. You can use SetInfo to change these settings.

Pages may be rotated. As such, when drawing one page onto another, you may wish to copy the Page.Rotation from the source page to the destination page. More complex example code to de-rotate a page may be found under the documentation for the Page.Rotation.

 

   

Example
 

This example shows how to draw one PDF into another. It takes a PDF document and creates a 'four-up' summary document by drawing four pages on each page of the new document.

First we create an ABCpdf Doc object and read in our source document.

[C#]
Doc theSrc = new Doc();
theSrc.Read(Server.MapPath("../Rez/spaceshuttle.pdf"));
int theCount = theSrc.PageCount;

[Visual Basic]
Dim theSrc As Doc = New Doc()
theSrc.Read(Server.MapPath("../Rez/spaceshuttle.pdf"))
Dim theCount As Integer = theSrc.PageCount

Next we create a destination Doc object and set the MediaBox so that the page size will match that of the source document. We change the rect so that it occupies a quarter of the page with room to accomodate a small margin.

[C#]
Doc theDst = new Doc();
theDst.MediaBox.String = theSrc.MediaBox.String;
theDst.Rect.String = theDst.MediaBox.String;
theDst.Rect.Magnify(0.5, 0.5);
theDst.Rect.Inset(10, 10);
double theX, theY;
theX = theDst.MediaBox.Width / 2;
theY = theDst.MediaBox.Height / 2;

[Visual Basic]
Dim theDst As Doc = New Doc()
theDst.MediaBox.String = theSrc.MediaBox.String
theDst.Rect.String = theDst.MediaBox.String
theDst.Rect.Magnify(0.5, 0.5)
theDst.Rect.Inset(10, 10)
Dim theX As Double,theY As Double
theX = theDst.MediaBox.Width / 2
theY = theDst.MediaBox.Height / 2

We go through every page in the source document drawing a framed copy of each page at a different position on our four-up document. Every fourth page we add a new page into our destination document.

[C#]
for (int i = 1; i <= theCount; i++) {
  switch (i % 4) {
    case 1:
      theDst.Page = theDst.AddPage();
      theDst.Rect.Position(10, theY + 10);
      break;
    case 2:
      theDst.Rect.Position(theX + 10, theY + 10);
      break;
    case 3:
      theDst.Rect.Position(10, 10);
      break;
    case 0:
      theDst.Rect.Position(theX + 10, 10);
      break;
  }
  theDst.AddImageDoc(theSrc, i, null);
  theDst.FrameRect();
}

[Visual Basic]
For i As Integer = 1 To theCount
  Select Case i Mod 4
    Case 1
      theDst.Page = theDst.AddPage()
      theDst.Rect.Position(10, theY + 10)
    Case 2
      theDst.Rect.Position(theX + 10, theY + 10)
    Case 3
      theDst.Rect.Position(10, 10)
    Case 0
      theDst.Rect.Position(theX + 10, 10)
  End Select
  theDst.AddImageDoc(theSrc, i, Nothing)
  theDst.FrameRect()
Next

Finally we save.

[C#]
theDst.Save(Server.MapPath("fourup.pdf"));
// finished

[Visual Basic]
theDst.Save(Server.MapPath("fourup.pdf"))
' finished

We get the following output.


fourup.pdf - [Page 1]

fourup.pdf - [Page 2]