List of usage examples for com.lowagie.text.pdf PdfCopyFields addDocument
public void addDocument(PdfReader reader) throws DocumentException, IOException
From source file:org.kuali.kfs.module.ar.document.service.impl.DunningLetterServiceImpl.java
License:Open Source License
/** * Loops through the collection of lookup results, creating pdfs for each and appending the bytes of the pdfs onto the returned "finalReport" * @see org.kuali.kfs.module.ar.document.service.DunningLetterDistributionService#createDunningLettersForAllResults(org.kuali.kfs.module.ar.businessobject.DunningLetterTemplate, java.util.Collection) */// w w w .j av a 2 s . co m @Override public byte[] createDunningLettersForAllResults(Collection<GenerateDunningLettersLookupResult> results) throws DocumentException, IOException { ByteArrayOutputStream zos = null; PdfCopyFields reportCopy = null; byte[] finalReport = null; try { zos = new ByteArrayOutputStream(); reportCopy = new PdfCopyFields(zos); reportCopy.open(); List<DunningLetterTemplate> dunningLetterTemplates = (List<DunningLetterTemplate>) getBusinessObjectService() .findAll(DunningLetterTemplate.class); for (DunningLetterTemplate dunningLetterTemplate : dunningLetterTemplates) { for (GenerateDunningLettersLookupResult generateDunningLettersLookupResult : results) { final byte[] report = createDunningLetters(dunningLetterTemplate, generateDunningLettersLookupResult); if (ObjectUtils.isNotNull(report)) { reportCopy.addDocument(new PdfReader(report)); } } } reportCopy.close(); finalReport = zos.toByteArray(); } finally { if (zos != null) { zos.close(); } } return finalReport; }
From source file:org.kuali.kfs.module.ar.document.service.impl.DunningLetterServiceImpl.java
License:Open Source License
/** * Generates the pdf file for printing the invoices. * * @param list/*from w w w .j a va 2s . com*/ * @param outputStream * @throws DocumentException * @throws IOException */ protected void generateCombinedPdfForInvoices(Collection<ContractsGrantsInvoiceDocument> list, byte[] report, OutputStream outputStream) throws DocumentException, IOException { PdfCopyFields copy = new PdfCopyFields(outputStream); copy.open(); copy.addDocument(new PdfReader(report)); for (ContractsGrantsInvoiceDocument invoice : list) { for (InvoiceAddressDetail invoiceAddressDetail : invoice.getInvoiceAddressDetails()) { Note note = noteService.getNoteByNoteId(invoiceAddressDetail.getNoteId()); if (ObjectUtils.isNotNull(note) && note.getAttachment().getAttachmentFileSize() > 0) { copy.addDocument(new PdfReader(note.getAttachment().getAttachmentContents())); } } } copy.close(); }
From source file:org.kuali.kfs.module.ar.report.service.impl.ContractsGrantsInvoiceReportServiceImpl.java
License:Open Source License
/** * Use iText <code>{@link PdfStamper}</code> to stamp information into field values on a PDF Form Template. * * @param agency The award the values will be pulled from. * @param reportingPeriod/* w w w . j a v a2 s . co m*/ * @param year * @param returnStream The output stream the federal form will be written to. */ protected void stampPdfFormValues425A(ContractsAndGrantsBillingAgency agency, String reportingPeriod, String year, OutputStream returnStream, Map<String, String> replacementList) { String federalReportTemplatePath = configService .getPropertyValueAsString(KFSConstants.EXTERNALIZABLE_HELP_URL_KEY); try { final String federal425ATemplateUrl = federalReportTemplatePath + ArConstants.FF_425A_TEMPLATE_NM + KFSConstants.ReportGeneration.PDF_FILE_EXTENSION; final String federal425TemplateUrl = federalReportTemplatePath + ArConstants.FF_425_TEMPLATE_NM + KFSConstants.ReportGeneration.PDF_FILE_EXTENSION; Map<String, Object> fieldValues = new HashMap<>(); fieldValues.put(KFSPropertyConstants.AGENCY_NUMBER, agency.getAgencyNumber()); fieldValues.put(KFSPropertyConstants.ACTIVE, Boolean.TRUE); List<ContractsAndGrantsBillingAward> awards = kualiModuleService .getResponsibleModuleService(ContractsAndGrantsBillingAward.class) .getExternalizableBusinessObjectsList(ContractsAndGrantsBillingAward.class, fieldValues); Integer pageNumber = 1, totalPages; totalPages = (awards.size() / ArConstants.Federal425APdf.NUMBER_OF_SUMMARIES_PER_PAGE) + 1; PdfCopyFields copy = new PdfCopyFields(returnStream); // generate replacement list for FF425 populateListByAgency(awards, reportingPeriod, year, agency); contractsGrantsBillingUtilityService.putValueOrEmptyString(replacementList, ArPropertyConstants.FederalFormReportFields.TOTAL_PAGES, org.apache.commons.lang.ObjectUtils.toString(totalPages + 1)); KualiDecimal sumCashControl = KualiDecimal.ZERO; KualiDecimal sumCumExp = KualiDecimal.ZERO; while (pageNumber <= totalPages) { List<ContractsAndGrantsBillingAward> awardsList = new ArrayList<ContractsAndGrantsBillingAward>(); for (int i = ((pageNumber - 1) * ArConstants.Federal425APdf.NUMBER_OF_SUMMARIES_PER_PAGE); i < (pageNumber * ArConstants.Federal425APdf.NUMBER_OF_SUMMARIES_PER_PAGE); i++) { if (i < awards.size()) { awardsList.add(awards.get(i)); } } // generate replacement list for FF425 List<KualiDecimal> list = populateListByAgency(awardsList, reportingPeriod, year, agency); if (CollectionUtils.isNotEmpty(list)) { sumCashControl = sumCashControl.add(list.get(0)); if (list.size() > 1) { sumCumExp = sumCumExp.add(list.get(1)); } } // populate form with document values contractsGrantsBillingUtilityService.putValueOrEmptyString(replacementList, ArPropertyConstants.FederalFormReportFields.PAGE_NUMBER, org.apache.commons.lang.ObjectUtils.toString(pageNumber + 1)); if (pageNumber == totalPages) { contractsGrantsBillingUtilityService.putValueOrEmptyString(replacementList, ArPropertyConstants.FederalFormReportFields.TOTAL, contractsGrantsBillingUtilityService.formatForCurrency(sumCashControl)); contractsGrantsBillingUtilityService.putValueOrEmptyString(replacementList, ArPropertyConstants.FederalFormReportFields.CASH_RECEIPTS, contractsGrantsBillingUtilityService.formatForCurrency(sumCashControl)); contractsGrantsBillingUtilityService.putValueOrEmptyString(replacementList, ArPropertyConstants.FederalFormReportFields.CASH_DISBURSEMENTS, contractsGrantsBillingUtilityService.formatForCurrency(sumCumExp)); contractsGrantsBillingUtilityService.putValueOrEmptyString(replacementList, ArPropertyConstants.FederalFormReportFields.CASH_ON_HAND, contractsGrantsBillingUtilityService .formatForCurrency(sumCashControl.subtract(sumCumExp))); } // add a document copy.addDocument(new PdfReader(renameFieldsIn(federal425ATemplateUrl, replacementList))); pageNumber++; } contractsGrantsBillingUtilityService.putValueOrEmptyString(replacementList, ArPropertyConstants.FederalFormReportFields.PAGE_NUMBER, "1"); // add the FF425 form. copy.addDocument(new PdfReader(renameFieldsIn(federal425TemplateUrl, replacementList))); // Close the PdfCopyFields object copy.close(); } catch (DocumentException | IOException ex) { throw new RuntimeException("Tried to stamp the 425A, but couldn't do it. Just...just couldn't do it.", ex); } }
From source file:org.kuali.kfs.module.ar.report.service.impl.ContractsGrantsInvoiceReportServiceImpl.java
License:Open Source License
/** * Generates the pdf file for printing the invoices. * * @param list//from w w w.j av a2 s. c o m * @param outputStream * @throws DocumentException * @throws IOException */ protected void generateCombinedPdfForInvoices(Collection<ContractsGrantsInvoiceDocument> list, OutputStream outputStream) throws DocumentException, IOException { PdfCopyFields copy = new PdfCopyFields(outputStream); boolean pageAdded = false; for (ContractsGrantsInvoiceDocument invoice : list) { // add a document List<InvoiceAddressDetail> invoiceAddressDetails = invoice.getInvoiceAddressDetails(); for (InvoiceAddressDetail invoiceAddressDetail : invoiceAddressDetails) { if (ArConstants.InvoiceTransmissionMethod.MAIL .equals(invoiceAddressDetail.getInvoiceTransmissionMethodCode())) { Note note = noteService.getNoteByNoteId(invoiceAddressDetail.getNoteId()); Integer numberOfCopiesToPrint = invoiceAddressDetail.getCustomerAddress() .getCustomerCopiesToPrint(); if (ObjectUtils.isNull(numberOfCopiesToPrint)) { numberOfCopiesToPrint = 1; } if (!ObjectUtils.isNull(note)) { for (int i = 0; i < numberOfCopiesToPrint; i++) { if (!pageAdded) { copy.open(); } pageAdded = true; copy.addDocument(new PdfReader(note.getAttachment().getAttachmentContents())); } } invoiceAddressDetail.setInitialTransmissionDate(new Date(new java.util.Date().getTime())); } } documentService.updateDocument(invoice); } if (pageAdded) { copy.close(); } }
From source file:us.mn.state.health.lims.reports.action.implementation.CollectionReport.java
License:Mozilla Public License
protected byte[] merge(List<byte[]> byteList) throws DocumentException { byte[] outputBytes; OutputStream outputStream = new ByteArrayOutputStream(); try {//from w w w. jav a 2 s . c o m PdfCopyFields pcf = new PdfCopyFields(outputStream); for (byte[] bytes : byteList) { ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); PdfReader pdfReader = new PdfReader(inputStream); // place holder in case we do have to rotate // if (false) { // int n = pdfReader.getNumberOfPages(); // int rot; // PdfDictionary pageDict; // for (int i = 1; i <= n; i++) { // rot = pdfReader.getPageRotation(i); // pageDict = pdfReader.getPageN(i); // pageDict.put(PdfName.ROTATE, new PdfNumber(rot + 90)); // } // } pcf.addDocument(pdfReader); } if (!byteList.isEmpty()) { pcf.close(); } outputBytes = ((ByteArrayOutputStream) outputStream).toByteArray(); return outputBytes; } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } finally { try { if (outputStream != null) outputStream.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } return null; }
From source file:util.MyPDFFiles.java
public static void concatenar2PDF(String file1, String file2, String fileSale) throws Exception { System.out.println("Concatenate Two PDF"); PdfReader reader1 = new PdfReader(file1); PdfReader reader2 = new PdfReader(file2); PdfCopyFields copy = new PdfCopyFields(new FileOutputStream(fileSale)); copy.addDocument(reader1); copy.addDocument(reader2);/*from w w w . ja va2 s . c o m*/ copy.close(); }