Adds a copy of an existing image to the current page.




ImageID = Doc.AddImageCopy(ID)



Name Type Description
ID Long The ID of an existing Image object.
ImageID Long The ID of the newly added Image object.




Adds a copy of an image which has already been inserted elsewhere in the document.

You can use this facility to add commonly used graphics such as watermarks. The raw image data is inserted only once, which means that PDF size is greatly reduced.

This method only works with raster or bitmap images. So your ID must have been obtained from a previous call to AddImageFile, AddImageData or AddImageObject.

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

If the width or height of the current rectangle is zero, the image is auto-sized. If you are working in TopDown mode, the image is positioned with its top left pinned at the location indicated by the rectangle. If you are not in TopDown mode, the bottom left of the image is pinned at the location indicated by the rectangle. In both cases, the natural dimensions of the supplied image are used to determine the displayed width and height resulting in a 72-dpi output.




This example shows how to read an existing PDF document and insert a background image into every page.

We start by reading our template PDF document and finding out core information we will need to reference each page.

Set theDoc = Server.CreateObject("ABCpdf10.Doc")
theDoc.Read "c:\mypics\sample.pdf"
theCount = theDoc.PageCount

We cycle through the pages inserting images as we go.

We set the layer property to ensure that the image gets added in the background rather than on top of existing content.

The first time, we add an image file. Subsequent times, we reference the image ID. This means that we embed only one copy of the image data and simply reference that data from each page.

Finally, we save the modified PDF.

For i = 1 To theCount
  theDoc.PageNumber = i
  theDoc.Layer = theDoc.LayerCount + 1
  If i = 1 Then
    theID = theDoc.AddImageFile("c:\mypics\light.jpg", 1)
    theDoc.AddImageCopy theID
  End If
theDoc.Save "c:\mypdfs\watermark.pdf"

Given the following document.

sample.pdf [Page 1]

sample.pdf [Page 2]

sample.pdf [Page 3]

sample.pdf [Page 4]

And the following image.

This is the kind of output you might expect.

watermark.pdf [Page 1]

watermark.pdf [Page 2]

watermark.pdf [Page 3]

watermark.pdf [Page 4]