PDF In-Depth

IAC - Importing single pages

February 18, 1999

Advertisement
Advertisement
 

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 NUMBER_OF_TIMES_TO_INSERT = 10

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

    AcroExchApp.Show


    ' 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

    AcroExchPDDocSource.Close

    ' 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

    AcroExchPDDocTarget.Close

    ' Close Acrobat Exchange

    AcroExchApp.Exit


    ' 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

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
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.

Features

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.