Class ReplacePagesPDFJob


  • public class ReplacePagesPDFJob
    extends PDFServicesJob
    A job that allows specific pages in a PDF file to be replaced with pages from multiple PDF files.

    For more complex use cases, refer the CombinePDFJob.

    Sample Usage:

    
                 InputStream baseInputStream = new FileInputStream(new File("SOURCE_PATH"));
                 InputStream inputStream1 = 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 asset1 = pdfServices.upload(inputStream1, PDFServicesMediaType.PDF.getMediaType());
    
                 PageRanges pageRanges = new PageRanges();
                 pageRanges.addSinglePage(1, 3);
                 pageRanges.addRange(4);
    
                 ReplacePagesParams replacePagesParams = ReplacePagesParams.replacePagesParamsBuilder(baseAsset)
                         .addPagesForReplace(asset1, pageRanges, 1)
                         .build();
    
                 ReplacePagesPDFJob replacePagesPDFJob = new ReplacePagesPDFJob(replacePagesParams);
    
                 String location = pdfServices.submit(replacePagesPDFJob);
                 PDFServicesResponse<ReplacePagesResult> pdfServicesResponse = pdfServices.getJobResult(location, ReplacePagesResult.class);
    
                 Asset resultAsset = pdfServicesResponse.getResult().getAsset();
                 StreamAsset streamAsset = pdfServices.getContent(resultAsset);
     
    • Constructor Detail

      • ReplacePagesPDFJob

        public ReplacePagesPDFJob​(ReplacePagesParams replacePagesParams)
        Constructs a new ReplacePagesPDFJob instance.
        Parameters:
        replacePagesParams - ReplacePagesParams object containing the base PDF file and the pages to be replaced; can not be null.
    • Method Detail

      • setOutput

        public ReplacePagesPDFJob 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:
        ReplacePagesPDFJob instance