Как устранить ошибку PDFBox: конец файла при слиянии? - PullRequest
0 голосов
/ 13 мая 2019

Я использую PDFbox для объединения 5 файлов PDF. Этот код работал нормально, внезапно у меня возникла проблема: Конец строки.

Я попытался записать свой код. Я нашел, когда я загружаю документ, он начинает выдавать исключение

            final String assignmentReportPath = context.lookup(ResourceProperty.reportBundle.getString("FILE_CREATING_DIRECTORY_PATH")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+context.lookup(ResourceProperty.configBundle.getString("FOLDER_SEPARATOR")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+ResourceProperty.reportBundle.getString("SUFFIX_ASSIGNMENT_REPORT_PARAM");
            log.info("::OwnerConfirmationViewUtility::mergeFilesForEmail::assignmentReportPath: "+assignmentReportPath);
            final String appraiserWorkSheetPath = context.lookup(ResourceProperty.reportBundle.getString("FILE_CREATING_DIRECTORY_PATH")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+context.lookup(ResourceProperty.configBundle.getString("FOLDER_SEPARATOR")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+ResourceProperty.reportBundle.getString("SUFFIX_APPRAISER_WORKSHEET_PARAM");
            log.info("::OwnerConfirmationViewUtility::mergeFilesForEmail::appraiserWorkSheetPath: "+appraiserWorkSheetPath);
            final String appraiserLogBookPath = context.lookup(ResourceProperty.reportBundle.getString("FILE_CREATING_DIRECTORY_PATH")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+context.lookup(ResourceProperty.configBundle.getString("FOLDER_SEPARATOR")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+ResourceProperty.reportBundle.getString("SUFFIX_APPRAISER_LOG_BOOK_PARAM");
            log.info("::OwnerConfirmationViewUtility::mergeFilesForEmail::appraiserLogBookPath: "+appraiserLogBookPath);
            final String ownerConfirmReportPath = context.lookup(ResourceProperty.reportBundle.getString("FILE_CREATING_DIRECTORY_PATH")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+context.lookup(ResourceProperty.configBundle.getString("FOLDER_SEPARATOR")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+ResourceProperty.reportBundle.getString("SUFFIX_OWNER_CONFIRMATION_REPORT_PARAM");
            log.info("::OwnerConfirmationViewUtility::mergeFilesForEmail::ownerConfirmReportPath: "+ownerConfirmReportPath);
            final String originalReportPath = context.lookup(ResourceProperty.reportBundle.getString("FILE_CREATING_DIRECTORY_PATH")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+context.lookup(ResourceProperty.configBundle.getString("FOLDER_SEPARATOR")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+ResourceProperty.reportBundle.getString("SUFFIX_ORIGINAL_ASSIGNMENT");
            log.info("::OwnerConfirmationViewUtility::mergeFilesForEmail::originalReportPath: "+originalReportPath);

            final File assignmentReportPDFFile = new File(assignmentReportPath);
            final PDDocument assignmentReportPDF = PDDocument.load(assignmentReportPDFFile);

            final File appraiserWorkSheetPDFFile = new File(appraiserWorkSheetPath);
            final PDDocument appraiserWorkSheetPDF = PDDocument.load(appraiserWorkSheetPDFFile);

            final File appraiserLogBookPDFFile = new File(appraiserLogBookPath);
            final PDDocument appraiserLogBookPDF = PDDocument.load(appraiserLogBookPDFFile);

            final File confirmationReportPDFFile = new File(ownerConfirmReportPath);
            final PDDocument confirmationReportPDF = PDDocument.load(confirmationReportPDFFile);

            final File originalPDFFile = new File(originalReportPath);
            final PDDocument originalPDF = PDDocument.load(originalPDFFile);

            final PDFMergerUtility PDFmerger = new PDFMergerUtility();

            final String destinationFile = context.lookup(ResourceProperty.reportBundle.getString("FILE_CREATING_DIRECTORY_PATH")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+context.lookup(ResourceProperty.configBundle.getString("FOLDER_SEPARATOR")).toString()+ownerConfirmationViewPojo.getCanFileNumber()+".PDF";

            PDFmerger.setDestinationFileName(destinationFile);

            PDFmerger.addSource(assignmentReportPDFFile);
            PDFmerger.addSource(appraiserWorkSheetPDFFile);
            PDFmerger.addSource(appraiserLogBookPDFFile);
            PDFmerger.addSource(confirmationReportPDFFile);
            PDFmerger.addSource(originalPDFFile);

            PDFmerger.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());

            final File finalFile = new File(destinationFile);
...