Example usage for com.lowagie.text.pdf PdfCopyFields open

List of usage examples for com.lowagie.text.pdf PdfCopyFields open

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfCopyFields open.

Prototype

public void open() 

Source Link

Document

Opens the document.

Usage

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 ww  .j  a va2 s.  c  om*/
@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 .  ja  v  a  2s . c om*/
 * @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

/**
 * Generates the pdf file for printing the invoices.
 *
 * @param list/*from   ww w  .  j a v  a  2s. c om*/
 * @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();
    }
}