Package com.selectpdf
Class PdfMergeClient
java.lang.Object
com.selectpdf.ApiClient
com.selectpdf.PdfMergeClient
public class PdfMergeClient extends ApiClient
Pdf Merge with SelectPdf Online API.
package com.selectpdf;
public class PdfMerge {
public static void main(String[] args) throws Exception {
String testUrl = "https://selectpdf.com/demo/files/selectpdf.pdf";
String testPdf = "Input.pdf";
String localFile = "Result.pdf";
String apiKey = "Your API key here";
System.out.println(String.format("This is SelectPdf-%s.", ApiClient.CLIENT_VERSION));
try {
PdfMergeClient client = new 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(testPdf) // add PDF from local file
.addUrlFile(testUrl) // add PDF From public url
// .addFile(testPdf, "pdf_password") // add PDF (that requires a password) from local file
// .addUrlFile(testUrl, "pdf_password") // add PDF (that requires a password) from public url
;
System.out.println("Starting pdf merge...");
// merge pdfs to local file
client.saveToFile(localFile);
// merge pdfs to memory
// byte[] pdf = client.save();
System.out.println(String.format("Finished! Number of pages: %d.", client.getNumberOfPages()));
// get API usage
UsageClient usageClient = new UsageClient(apiKey);
String usage = usageClient.getUsage(false);
System.out.printf("Usage details: %s.\r\n", usage);
// org.json.JSONObject usageObject = new org.json.JSONObject(usage);
// int available = usageObject.getInt("available");
// System.out.printf("Conversions remained this month: %d.\r\n", available);
}
catch (Exception ex) {
System.out.println("An error occured: " + ex.getMessage());
}
}
}
-
Field Summary
Fields inherited from class com.selectpdf.ApiClient
apiAsyncEndpoint, apiEndpoint, apiWebElementsEndpoint, AsyncCallsMaxPings, AsyncCallsPingInterval, binaryData, CLIENT_VERSION, files, headers, jobId, lastHTTPCode, MULTIPART_FORM_DATA_BOUNDARY, NEW_LINE, numberOfPages, parameters
-
Constructor Summary
Constructors Constructor Description PdfMergeClient(java.lang.String apiKey)
Construct the Pdf Merge Client. -
Method Summary
Modifier and Type Method Description PdfMergeClient
addFile(java.lang.String inputPdf)
Add local PDF document to the list of input files.PdfMergeClient
addFile(java.lang.String inputPdf, java.lang.String userPassword)
Add local PDF document to the list of input files.PdfMergeClient
addUrlFile(java.lang.String inputUrl)
Add remote PDF document to the list of input files.PdfMergeClient
addUrlFile(java.lang.String inputUrl, java.lang.String userPassword)
Add remote PDF document to the list of input files.byte[]
save()
Merge all specified input pdfs and return the resulted PDF.byte[]
saveAsync()
Merge all specified input pdfs and return the resulted PDF.void
saveToFile(java.lang.String filePath)
Merge all specified input pdfs and writes the resulted PDF to a local file.void
saveToFileAsync(java.lang.String filePath)
Merge all specified input pdfs and writes the resulted PDF to a local file.void
saveToStream(java.io.OutputStream stream)
Merge all specified input pdfs and writes the resulted PDF to a specified stream.void
saveToStreamAsync(java.io.OutputStream stream)
Merge all specified input pdfs and writes the resulted PDF to a specified stream.PdfMergeClient
setCustomParameter(java.lang.String parameterName, java.lang.String parameterValue)
Set a custom parameter.PdfMergeClient
setDocAddCreationDate(java.lang.Boolean docAddCreationDate)
Add the date and time when the PDF document was created to the PDF document information.PdfMergeClient
setDocAuthor(java.lang.String docAuthor)
Set the name of the PDF document author.PdfMergeClient
setDocKeywords(java.lang.String docKeywords)
Set the PDF document keywords.PdfMergeClient
setDocSubject(java.lang.String docSubject)
Set the subject of the PDF document.PdfMergeClient
setDocTitle(java.lang.String docTitle)
Set the PDF document title.PdfMergeClient
setOwnerPassword(java.lang.String ownerPassword)
Set PDF owner password.PdfMergeClient
setTimeout(int timeout)
Set the maximum amount of time (in seconds) for this job.PdfMergeClient
setUserPassword(java.lang.String userPassword)
Set PDF user password.PdfMergeClient
setViewerCenterWindow(java.lang.Boolean viewerCenterWindow)
Set a flag specifying whether to position the document's window in the center of the screen.PdfMergeClient
setViewerDisplayDocTitle(java.lang.Boolean viewerDisplayDocTitle)
Set a flag specifying whether the window's title bar should display the document title taken from document information.PdfMergeClient
setViewerFitWindow(java.lang.Boolean viewerFitWindow)
Set a flag specifying whether to resize the document's window to fit the size of the first displayed page.PdfMergeClient
setViewerHideMenuBar(java.lang.Boolean viewerHideMenuBar)
Set a flag specifying whether to hide the pdf viewer application's menu bar when the document is active.PdfMergeClient
setViewerHideToolbar(java.lang.Boolean viewerHideToolbar)
Set a flag specifying whether to hide the pdf viewer application's tool bars when the document is active.PdfMergeClient
setViewerHideWindowUI(java.lang.Boolean 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.PdfMergeClient
setViewerPageLayout(ApiEnums.PageLayout pageLayout)
Set the page layout to be used when the document is opened in a PDF viewer.PdfMergeClient
setViewerPageMode(ApiEnums.PageMode pageMode)
Set the document page mode when the pdf document is opened in a PDF viewer.Methods inherited from class com.selectpdf.ApiClient
getNumberOfPages, performPost, performPostAsMultipartFormData, serializeDictionary, serializeParameters, setApiAsyncEndpoint, setApiEndpoint, setApiWebElementsEndpoint, startAsyncJob, startAsyncJobMultipartFormData
-
Constructor Details
-
PdfMergeClient
public PdfMergeClient(java.lang.String apiKey)Construct the Pdf Merge Client.- Parameters:
apiKey
- API Key.
-
-
Method Details
-
addFile
Add local PDF document to the list of input files.- Parameters:
inputPdf
- Path to a local PDF file.- Returns:
- Reference to the current object.
-
addFile
Add local PDF document to the list of input files.- Parameters:
inputPdf
- Path to a local PDF file.userPassword
- User password for the PDF document.- Returns:
- Reference to the current object.
-
addUrlFile
Add remote PDF document to the list of input files.- Parameters:
inputUrl
- Url of a remote PDF file.- Returns:
- Reference to the current object.
-
addUrlFile
Add remote PDF document to the list of input files.- Parameters:
inputUrl
- Url of a remote PDF file.userPassword
- User password for the PDF document.- Returns:
- Reference to the current object.
-
save
public byte[] save()Merge all specified input pdfs and return the resulted PDF.- Returns:
- Byte array containing the resulted PDF.
-
saveToFile
public void saveToFile(java.lang.String filePath) throws java.io.IOExceptionMerge all specified input pdfs and writes the resulted PDF to a local file.- Parameters:
filePath
- Local output file including path if necessary.- Throws:
java.io.IOException
-
saveToStream
public void saveToStream(java.io.OutputStream stream) throws java.io.IOExceptionMerge all specified input pdfs and writes the resulted PDF to a specified stream.- Parameters:
stream
- The output stream where the resulted PDF will be written.- Throws:
java.io.IOException
-
saveAsync
public byte[] saveAsync()Merge all specified input pdfs and return the resulted PDF. An asynchronous call is used.- Returns:
- Byte array containing the resulted PDF.
-
saveToFileAsync
public void saveToFileAsync(java.lang.String filePath) throws java.io.IOExceptionMerge all specified input pdfs and writes the resulted PDF to a local file. An asynchronous call is used.- Parameters:
filePath
- Local output file including path if necessary.- Throws:
java.io.IOException
-
saveToStreamAsync
public void saveToStreamAsync(java.io.OutputStream stream) throws java.io.IOExceptionMerge all specified input pdfs and writes the resulted PDF to a specified stream. An asynchronous call is used.- Parameters:
stream
- The output stream where the resulted PDF will be written.- Throws:
java.io.IOException
-
setDocTitle
Set the PDF document title.- Parameters:
docTitle
- Document title.- Returns:
- Reference to the current object.
-
setDocSubject
Set the subject of the PDF document.- Parameters:
docSubject
- Document subject.- Returns:
- Reference to the current object.
-
setDocKeywords
Set the PDF document keywords.- Parameters:
docKeywords
- Document keywords.- Returns:
- Reference to the current object.
-
setDocAuthor
Set the name of the PDF document author.- Parameters:
docAuthor
- Document author.- Returns:
- Reference to the current object.
-
setDocAddCreationDate
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
Set the page layout to be used when the document is opened in a PDF viewer. The default value is PageLayout.OneColumn.- Parameters:
pageLayout
- Page layout.- Returns:
- Reference to the current object.
-
setViewerPageMode
Set the document page mode when the pdf document is opened in a PDF viewer. The default value is PageMode.UseNone.- Parameters:
pageMode
- Page mode.- Returns:
- Reference to the current object.
-
setViewerCenterWindow
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
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
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
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
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
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. The default value is False.- Parameters:
viewerHideWindowUI
- Hide window UI or not.- Returns:
- Reference to the current object.
-
setUserPassword
Set PDF user password.- Parameters:
userPassword
- PDF user password.- Returns:
- Reference to the current object.
-
setOwnerPassword
Set PDF owner password.- Parameters:
ownerPassword
- PDF owner password.- Returns:
- Reference to the current object.
-
setTimeout
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 large documents.- Parameters:
timeout
- Timeout in seconds.- Returns:
- Reference to the current object.
-
setCustomParameter
public PdfMergeClient setCustomParameter(java.lang.String parameterName, java.lang.String 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.
-