Welcome Guest Search | Active Topics | Sign In | Register

Sample: merging multiple PDF files and adding page numbers Options
eo_support
Posted: Monday, August 8, 2011 10:53:32 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
The following code demonstrates how to merge multiple files and add page numbers:

Code: C#
//Merge the file. You can merge as many files
//as you would like here
EO.Pdf.PdfDocument result = 
    EO.Pdf.PdfDocument.Merge(
        new EO.Pdf.PdfDocument("c:\\1.pdf"), 
        new EO.Pdf.PdfDocument("c:\\2.pdf"));

//Add page number to each page
for (int i = 0; i < result.Pages.Count; i++)
{
    //Create an AcmText representing the page number
    EO.Pdf.Acm.AcmText text = 
        new EO.Pdf.Acm.AcmText("Page " + i.ToString());

    //Create an AcmRender to render the page number.
    //The arguments are:
    //First argument: the target page
    //Second argument: the "Y" position
    //Third argument: The paper margins in left, top, right, bottom order
    EO.Pdf.Acm.AcmRender render = new EO.Pdf.Acm.AcmRender(
        result.Pages[i], 10.5f, 
        new EO.Pdf.Acm.AcmPageLayout(
            new EO.Pdf.Acm.AcmPadding(1, 0, 1, 0)));
    render.Render(text);
}

//Render the page number
result.Save("c:\\3.pdf");


Code: Visual Basic.NET
Dim result As EO.Pdf.PdfDocument

'Merge the file. You can merge as many files
'as you would like here
result = EO.Pdf.PdfDocument.Merge( _
    New EO.Pdf.PdfDocument("1.pdf"), _
    New EO.Pdf.PdfDocument("2.pdf"))

'Add page number to each page
For I As Integer = 0 To result.Pages.Count - 1
    Dim pageNumber As EO.Pdf.Acm.AcmText
    Dim acmRender As EO.Pdf.Acm.AcmRender

    'Create an AcmText representing the page number
    pageNumber = New EO.Pdf.Acm.AcmText("Page " + (I + 1).ToString())

    'Create an AcmRender to render the page number.
    'The arguments are:
    ' First argument: the target page
    ' Second argument: the "Y" position
    ' Third argument: The paper margins in left, top, right, bottom order
    acmRender = New EO.Pdf.Acm.AcmRender(result.Pages(I), 10.5, _
        New EO.Pdf.Acm.AcmPageLayout( _
            New EO.Pdf.Acm.AcmPadding(1, 0, 1, 0)))

    'Render the page number
    acmRender.Render(pageNumber)
Next

'Save the result file
result.Save("result.pdf")


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.