The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SelectPdf::PdfMergeClient - Pdf Merge with SelectPdf Online API.

SYNOPSIS

Merge PDFs from local disk or public url and save result into a file on disk.

    use SelectPdf;
    print "This is SelectPdf-$SelectPdf::VERSION\n";

    my $test_url = "https://selectpdf.com/demo/files/selectpdf.pdf";
    my $test_pdf = "Input.pdf";
    my $local_file = "Result.pdf";
    my $apiKey = "Your API key here";

    eval {
        my $client = new SelectPdf::PdfMergeClient($apiKey);

        # set parameters - see full list at https://selectpdf.com/pdf-merge-api/
        $client
            # specify the pdf files that will be merged (order will be preserved in the final pdf)

            ->addFile($test_pdf) # add PDF from local file
            ->addUrlFile($test_url) # add PDF From public url
            #->addFileWithPassword($test_pdf, "pdf_password") # add PDF (that requires a password) from local file
            #->addUrlFileWithPassword($test_url, "pdf_password") # add PDF (that requires a password) from public url
        ;

        print "Starting pdf merge ...\n";

        # merge pdfs to local file
        $client->saveToFile($local_file);

        # merge pdfs to memory
        # my $pdf = $client->save();

        print "Finished! Number of pages: " . $client->getNumberOfPages() . ".\n";

        # get API usage
        my $usageClient = new SelectPdf::UsageClient($apiKey);
        my $usage = $usageClient->getUsage(0);
        print("Usage: " . encode_json($usage) . "\n");
        print("Conversions remained this month: ". $usage->{"available"});
    };

    if ($@) {
        print "An error occurred: $@\n";  
    }

For more details and full list of parameters see Pdf Merge API.

METHODS

new( $apiKey )

Construct the Pdf Merge Client.

    my $client = SelectPdf::PdfMergeClient->new($apiKey);

Parameters:

- $apiKey: API Key.

addFile( $inputPdf )

Add local PDF document to the list of input files.

    my $client = new SelectPdf::PdfMergeClient($apiKey);
    $client->addFile($inputPdf);

Parameters:

- $inputPdf: Path to a local PDF file.

Returns:

- Reference to the current object.

addFileWithPassword( $inputPdf, $userPassword )

Add local PDF document to the list of input files.

    my $client = new SelectPdf::PdfMergeClient($apiKey);
    $client->addFileWithPassword($inputPdf, $userPassword);

Parameters:

- $inputPdf: Path to a local PDF file.

- $userPassword: User password for the PDF document.

Returns:

- Reference to the current object.

addUrlFile( $inputUrl )

Add remote PDF document to the list of input files.

    my $client = new SelectPdf::PdfMergeClient($apiKey);
    $client->addUrlFile($inputUrl);

Parameters:

- $inputUrl: Url of a remote PDF file.

Returns:

- Reference to the current object.

addUrlFileWithPassword( $inputUrl, $userPassword )

Add remote PDF document to the list of input files.

    my $client = new SelectPdf::PdfMergeClient($apiKey);
    $client->addUrlFileWithPassword($inputUrl, $userPassword);

Parameters:

- $inputUrl: Url of a remote PDF file.

- $userPassword: User password for the PDF document.

Returns:

- Reference to the current object.

save

Merge all specified input pdfs and return the resulted PDF.

    my $client = new SelectPdf::PdfMergeClient($apiKey);
    $client->addFile($inputPdf1);
    $client->addFile($inputPdf2);
    $content = $client->save();

Returns:

- Byte array containing the resulted PDF.

saveToFile( $filePath )

Merge all specified input pdfs and writes the resulted PDF to a local file.

    my $client = new SelectPdf::PdfMergeClient($apiKey);
    $client->addFile($inputPdf1);
    $client->addFile($inputPdf2);
    $client->saveToFile($filePath);

Parameters:

- $filePath: Local file including path if necessary.

Returns:

- Byte array containing the resulted PDF.

saveAsync

Merge all specified input pdfs and return the resulted PDF.

    my $client = new SelectPdf::PdfMergeClient($apiKey);
    $client->addFile($inputPdf1);
    $client->addFile($inputPdf2);
    $content = $client->saveAsync();

Returns:

- Byte array containing the resulted PDF. An asynchronous call is used.

saveToFileAsync( $filePath )

Merge all specified input pdfs and writes the resulted PDF to a local file. An asynchronous call is used.

    my $client = new SelectPdf::PdfMergeClient($apiKey);
    $client->addFile($inputPdf1);
    $client->addFile($inputPdf2);
    $client->saveToFileAsync($filePath);

Parameters:

- $filePath: Local file including path if necessary.

Returns:

- Byte array containing the resulted PDF.

setDocTitle( $docTitle )

Set the PDF document title.

Parameters:

- $docTitle: Document title.

Returns:

- Reference to the current object.

setDocSubject( $docSubject )

Set the PDF document subject.

Parameters:

- $docSubject: Document subject.

Returns:

- Reference to the current object.

setDocKeywords( $docKeywords )

Set the PDF document keywords.

Parameters:

- $docKeywords: Document keywords.

Returns:

- Reference to the current object.

setDocAuthor( $docAuthor )

Set the PDF document author.

Parameters:

- $docAuthor: Document author.

Returns:

- Reference to the current object.

setDocAddCreationDate( $docAddCreationDate )

Add the date and time when the PDF document was created to the PDF document information. The default value is False.

Parameters:

- $docAddCreationDate: Add creation date to the document metadata or not.

Returns:

- Reference to the current object.

setViewerPageLayout( $pageLayout )

Set the page layout to be used when the document is opened in a PDF viewer. The default value is 1 - OneColumn.

Parameters:

- $pageLayout: Page layout. Possible values: 0 (Single Page), 1 (One Column), 2 (Two Column Left), 3 (Two Column Right).

Returns:

- Reference to the current object.

setViewerPageMode( $pageMode )

Set the document page mode when the pdf document is opened in a PDF viewer. The default value is 0 - UseNone.

Parameters:

- $pageMode: Page mode. Possible values: 0 (Use None), 1 (Use Outlines), 2 (Use Thumbs), 3 (Full Screen), 4 (Use OC), 5 (Use Attachments).

Returns:

- Reference to the current object.

setViewerCenterWindow( $viewerCenterWindow )

Set a flag specifying whether to position the document's window in the center of the screen. The default value is False.

Parameters:

- $viewerCenterWindow: Center window or not.

Returns:

- Reference to the current object.

setViewerDisplayDocTitle( $viewerDisplayDocTitle )

Set a flag specifying whether the window's title bar should display the document title taken from document information. The default value is False.

Parameters:

- $viewerDisplayDocTitle: Display title or not.

Returns:

- Reference to the current object.

setViewerFitWindow( $viewerFitWindow )

Set a flag specifying whether to resize the document's window to fit the size of the first displayed page. The default value is False.

Parameters:

- $viewerFitWindow: Fit window or not.

Returns:

- Reference to the current object.

setViewerHideMenuBar( $viewerHideMenuBar )

Set a flag specifying whether to hide the pdf viewer application's menu bar when the document is active. The default value is False.

Parameters:

- $viewerHideMenuBar: Hide menu bar or not.

Returns:

- Reference to the current object.

setViewerHideToolbar( $viewerHideToolbar )

Set a flag specifying whether to hide the pdf viewer application's tool bars when the document is active. The default value is False.

Parameters:

- $viewerHideToolbar: Hide tool bars or not.

Returns:

- Reference to the current object.

setViewerHideWindowUI( $viewerHideWindowUI )

Set a flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.

Parameters:

- $viewerHideWindowUI: Hide window UI or not.

Returns:

- Reference to the current object.

setUserPassword( $userPassword )

Set PDF user password.

Parameters:

- $userPassword: PDF user password.

Returns:

- Reference to the current object.

setOwnerPassword( $ownerPassword )

Set PDF owner password.

Parameters:

- $ownerPassword: PDF owner password.

Returns:

- Reference to the current object.

setCustomParameter( $parameterName, $parameterValue )

Set a custom parameter. Do not use this method unless advised by SelectPdf.

Parameters:

- $parameterName: Parameter name.

- $parameterValue: Parameter value.

Returns:

- Reference to the current object.

setTimeout( $timeout )

Set the maximum amount of time (in seconds) for this job. The default value is 30 seconds. Use a larger value (up to 120 seconds allowed) for pages that take a long time to load.

Parameters:

- $timeout: Timeout in seconds.

Returns:

- Reference to the current object.