PDF In-Depth

IAC - Importing single pages

February 18, 1999


How to import a single page many times

This code sample is posted here for the general benefit of the PDF development community. Attribution and usage guidelines are as noted in the code source; please respect the wishes of the author when using this code.

Option Explicit ' Force variable declaration

' Author : Planet PDF

' Date : 11 February, 1999

' Description: ImportTheSamePageManyTimes

' This vb method uses IAC to import a single page many times into a given

' PDF. This method / function should be extended to suit the requirements

' of an organisation

Private Const WORKING_PATH = "c:\temp\"

Private Const SOURCE_FILE_NAME = "source.pdf"

Private Const SOURCE_PAGE_TO_INSERT = 1 ' one based


Private Const TARGET_FILE_NAME = "source.pdf"

Private Const TARGET_PAGE_TO_INSERT_AFTER = 2 ' one based

Private Sub HowToImportTheSamePageManyTimes()

    Dim AcroExchApp As Object

    Dim AcroExchPDDocTarget As Object

    Dim AcroExchPDDocSource As Object

    Dim strSourceFileName As String

    Dim strPath As String

    Dim strTargetFileName As String

    Dim iSourcePageToInsert As Integer

    Dim iTargetPageToInsertAfter As Integer

    Dim iInsertCount As Integer

    ' Create our Exchange application object (this starts Exchange)

    Set AcroExchApp = CreateObject("AcroExch.App")

     ' And our PDDoc object

    Set AcroExchPDDocTarget = CreateObject("AcroExch.PDDoc")

    ' Show the Acrobat Exchange window


    ' Set the path *** this shouldn't be hardcoded in a real application

    strPath = WORKING_PATH

    ' Set the target file

    strTargetFileName = TARGET_FILE_NAME

    ' Set the page to insert after (note this is being converted to base 0)

    iTargetPageToInsertAfter = TARGET_PAGE_TO_INSERT_AFTER - 1

    ' Open the target file (the file that we wish to insert pages into)

    If (AcroExchPDDocTarget.Open(strPath + strTargetFileName) = False) Then

        MsgBox "Could not open " + strPath + strTargetFileName

        Exit Sub

    End If

    ' Set the source filename

    strSourceFileName = SOURCE_FILE_NAME

    ' Open the source file (that contains the page we wish to insert)

    Set AcroExchPDDocSource = CreateObject("AcroExch.PDDoc")

    If (AcroExchPDDocSource.Open(strPath + strSourceFileName) = False) Then

        MsgBox "Could not open " + strPath + strSourceFileName

        Exit Sub

    End If

    ' Set the page number to insert (note this is being converted to base 0)

    iSourcePageToInsert = SOURCE_PAGE_TO_INSERT - 1
    ' Insert the page 'NUMBER_OF_TIMES_TO_INSERT' times

    For iInsertCount = 1 To NUMBER_OF_TIMES_TO_INSERT
        ' Insert the pages

        If (AcroExchPDDocTarget.InsertPages(iTargetPageToInsertAfter, AcroExchPDDocSource, 
iSourcePageToInsert, 1, True) = False) Then

    Next iInsertCount

    ' Close the source document


    ' Save the entire target document where it was ***** note this saves over the top of the existing file

    AcroExchPDDocTarget.Save &H1, strPath + AcroExchPDDocTarget.GetFileName

    ' Close the PDDoc


    ' Close Acrobat Exchange


    ' Cleanup the Acrobat objects

    Set AcroExchApp = Nothing

    Set AcroExchPDDocTarget = Nothing

    Set AcroExchPDDocSource = Nothing

End Sub
PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Five visions of a PDF Day

In the world of PDFs or as we like to say Planet (of) PDF, a year isn't a real PDF year without an intense few days of industry knowledge sharing.

May 15, 2018
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.