Class InsertPagesPDFJob


  • public class InsertPagesPDFJob
    extends PDFServicesJob
    A job that can be used to insert pages of multiple PDF files into a base PDF file.

    For more complex use cases, refer the CombinePDFJob.

    Sample Usage:

    
                 InputStream baseInputStream = new FileInputStream(new File("SOURCE_PATH"));
                 InputStream firstInputStreamToInsert = new FileInputStream(new File("SOURCE_PATH"));
                 InputStream secondInputStreamToInsert = new FileInputStream(new File("SOURCE_PATH"));
    
                 Credentials credentials = new ServicePrincipalCredentials(
                         System.getenv("PDF_SERVICES_CLIENT_ID"),
                         System.getenv("PDF_SERVICES_CLIENT_SECRET"));
    
                 PDFServices pdfServices = new PDFServices(credentials);
    
                 Asset baseAsset = pdfServices.upload(baseInputStream, PDFServicesMediaType.PDF.getMediaType());
                 Asset firstAssetToInsert = pdfServices.upload(firstInputStreamToInsert, PDFServicesMediaType.PDF.getMediaType());
                 Asset secondAssetToInsert = pdfServices.upload(secondInputStreamToInsert, PDFServicesMediaType.PDF.getMediaType());
    
                 PageRanges pageRanges = new PageRanges();
                 pageRanges.addSinglePage(1, 3);
                 pageRanges.addRange(4);
    
                 InsertPagesParams insertPagesParams = InsertPagesParams.insertPagesParamsBuilder(baseAsset)
                         .addPagesToInsertAt(firstAssetToInsert, pageRanges, 2)
                         .addPagesToInsertAt(secondAssetToInsert, 3)
                         .build();
    
                 InsertPagesPDFJob insertPagesJob = new InsertPagesPDFJob(insertPagesParams);
    
                 String location = pdfServices.submit(insertPagesJob);
                 PDFServicesResponse<InsertPagesResult> pdfServicesResponse = pdfServices.getJobResult(location, InsertPagesResult.class);
    
                 Asset resultAsset = pdfServicesResponse.getResult().getAsset();
                 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
     
    • Constructor Detail

      • InsertPagesPDFJob

        public InsertPagesPDFJob​(InsertPagesParams insertPagesParams)
        Constructs a new InsertPagesPDFJob instance.
        Parameters:
        insertPagesParams - InsertPagesParams object containing the input files and the page numbers to insert at; can not be null.
    • Method Detail

      • setOutput

        public InsertPagesPDFJob setOutput​(Asset asset)
        Sets the output asset for the job. @note External assets can be set as output only when input is external asset as well
        Parameters:
        asset - Asset object representing the output asset; can not be null.
        Returns:
        InsertPagesPDFJob instance