SelectPdf::PdfMergeClient - Pdf Merge with SelectPdf Online API.
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.
Construct the Pdf Merge Client.
my $client = SelectPdf::PdfMergeClient->new($apiKey);
Parameters:
- $apiKey: API Key.
Add local PDF document to the list of input files.
my $client = new SelectPdf::PdfMergeClient($apiKey); $client->addFile($inputPdf);
- $inputPdf: Path to a local PDF file.
Returns:
- Reference to the current object.
my $client = new SelectPdf::PdfMergeClient($apiKey); $client->addFileWithPassword($inputPdf, $userPassword);
- $userPassword: User password for the PDF document.
Add remote PDF document to the list of input files.
my $client = new SelectPdf::PdfMergeClient($apiKey); $client->addUrlFile($inputUrl);
- $inputUrl: Url of a remote PDF file.
my $client = new SelectPdf::PdfMergeClient($apiKey); $client->addUrlFileWithPassword($inputUrl, $userPassword);
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();
- Byte array containing the resulted PDF.
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);
- $filePath: Local file including path if necessary.
my $client = new SelectPdf::PdfMergeClient($apiKey); $client->addFile($inputPdf1); $client->addFile($inputPdf2); $content = $client->saveAsync();
- Byte array containing the resulted PDF. An asynchronous call is used.
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);
Set the PDF document title.
- $docTitle: Document title.
Set the PDF document subject.
- $docSubject: Document subject.
Set the PDF document keywords.
- $docKeywords: Document keywords.
Set the PDF document author.
- $docAuthor: Document author.
Add the date and time when the PDF document was created to the PDF document information. The default value is False.
- $docAddCreationDate: Add creation date to the document metadata or not.
Set the page layout to be used when the document is opened in a PDF viewer. The default value is 1 - OneColumn.
- $pageLayout: Page layout. Possible values: 0 (Single Page), 1 (One Column), 2 (Two Column Left), 3 (Two Column Right).
Set the document page mode when the pdf document is opened in a PDF viewer. The default value is 0 - UseNone.
- $pageMode: Page mode. Possible values: 0 (Use None), 1 (Use Outlines), 2 (Use Thumbs), 3 (Full Screen), 4 (Use OC), 5 (Use Attachments).
Set a flag specifying whether to position the document's window in the center of the screen. The default value is False.
- $viewerCenterWindow: Center window or not.
Set a flag specifying whether the window's title bar should display the document title taken from document information. The default value is False.
- $viewerDisplayDocTitle: Display title or not.
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.
- $viewerFitWindow: Fit window or not.
Set a flag specifying whether to hide the pdf viewer application's menu bar when the document is active. The default value is False.
- $viewerHideMenuBar: Hide menu bar or not.
Set a flag specifying whether to hide the pdf viewer application's tool bars when the document is active. The default value is False.
- $viewerHideToolbar: Hide tool bars or not.
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.
- $viewerHideWindowUI: Hide window UI or not.
Set PDF user password.
- $userPassword: PDF user password.
Set PDF owner password.
- $ownerPassword: PDF owner password.
Set a custom parameter. Do not use this method unless advised by SelectPdf.
- $parameterName: Parameter name.
- $parameterValue: Parameter value.
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.
- $timeout: Timeout in seconds.
To install SelectPdf, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SelectPdf
CPAN shell
perl -MCPAN -e shell install SelectPdf
For more information on module installation, please visit the detailed CPAN module installation guide.