List of usage examples for com.lowagie.text.pdf PdfCopyFields PdfCopyFields
public PdfCopyFields(OutputStream os) throws DocumentException
From source file:de.intranda.test_ics.ImageHelper.java
License:Apache License
@SuppressWarnings("unused") private void addFrontPage(File frontPage, File pdfFile) throws IOException, DocumentException { File tempFile = new File(pdfFile.getParent(), System.currentTimeMillis() + ".pdf"); pdfFile.renameTo(tempFile);/* ww w. j a va 2s. co m*/ PdfReader reader1 = new PdfReader(frontPage.getAbsolutePath()); PdfReader reader2 = new PdfReader(tempFile.getAbsolutePath()); PdfCopyFields copy = new PdfCopyFields(new FileOutputStream(pdfFile)); copy.addDocument(reader1); copy.addDocument(reader2); copy.close(); if (tempFile != null && tempFile.isFile()) { tempFile.delete(); } }
From source file:it.jugpadova.blo.ParticipantBadgeBo.java
License:Apache License
/** * Build a PDF with the badges of confirmed participants. *///from w w w . j ava2 s.c om public byte[] buildPDFBadges(Event event) throws IOException, DocumentException { List<Participant> participants = participantDao .findConfirmedParticipantsByEventIdOrderByLastNameAndFirstName(event.getId()); int participantsPerPage = getParticipantsPerPage(event); int pages = (participants.size() / participantsPerPage) + 2; // prints a more page with empty badges ByteArrayOutputStream pdfMergedBaos = new ByteArrayOutputStream(); PdfCopyFields pdfMerged = new PdfCopyFields(pdfMergedBaos); int newIndex = 1; for (int i = 0; i < pages; i++) { InputStream templateIs = getBadgePageTemplateInputStream(event); RandomAccessFileOrArray rafa = new RandomAccessFileOrArray(templateIs); PdfReader template = new PdfReader(rafa, null); ByteArrayOutputStream pdfPageBaos = new ByteArrayOutputStream(); PdfStamper pdfPage = new PdfStamper(template, pdfPageBaos); AcroFields pdfPageForm = pdfPage.getAcroFields(); for (int j = 1; j <= participantsPerPage; j++) { pdfPageForm.renameField("title" + j, "title" + newIndex); pdfPageForm.renameField("firstName" + j, "firstName" + newIndex); pdfPageForm.renameField("lastName" + j, "lastName" + newIndex); pdfPageForm.renameField("firm" + j, "firm" + newIndex); pdfPageForm.renameField("role" + j, "role" + newIndex); newIndex++; } pdfPage.close(); template.close(); pdfMerged.addDocument(new PdfReader(pdfPageBaos.toByteArray())); } pdfMerged.close(); ByteArrayOutputStream resultBaos = new ByteArrayOutputStream(); PdfReader mergedReader = new PdfReader(pdfMergedBaos.toByteArray()); PdfStamper mergedStamper = new PdfStamper(mergedReader, resultBaos); AcroFields mergedForm = mergedStamper.getAcroFields(); int count = 1; for (int i = 0; i < pages; i++) { for (int j = 1; j <= participantsPerPage; j++) { mergedForm.setField("title" + count, event.getTitle()); count++; } } count = 1; for (Participant participant : participants) { mergedForm.setField("firstName" + count, participant.getFirstName()); mergedForm.setField("lastName" + count, participant.getLastName()); count++; } mergedStamper.setFormFlattening(true); mergedStamper.close(); return resultBaos.toByteArray(); }
From source file:it.pdfsam.console.tools.pdf.writers.PdfCopyFieldsConcatenator.java
License:Open Source License
public PdfCopyFieldsConcatenator(OutputStream os) throws DocumentException { writer = new PdfCopyFields(os); }
From source file:net.mitnet.tools.pdf.book.publisher.BookPublisher.java
License:Open Source License
/** * TODO: review concat process and compare to PdfCopy. *///from w w w. jav a 2 s . c om public void concatPdf(File firstPdf, File secondPdf, File concatPdf) throws IOException, DocumentException { if (isDebugEnabled()) { debug("firstPdf: " + firstPdf); debug("secondPdf: " + secondPdf); debug("concatPdf: " + concatPdf); debug("concat PDFs"); } PdfReader firstReader = new PdfReader(firstPdf.getPath()); PdfReader secondReader = new PdfReader(secondPdf.getPath()); PdfCopyFields copy = new PdfCopyFields(new FileOutputStream(concatPdf.getPath())); copy.addDocument(firstReader); copy.addDocument(secondReader); copy.close(); }
From source file:net.sourceforge.fenixedu.presentationTier.servlets.filters.ProcessCandidacyPrintAllDocumentsFilter.java
License:Open Source License
private ByteArrayOutputStream concatenateDocs(byte[] originalDoc, Person person) throws IOException, DocumentException { ByteArrayOutputStream concatenatedPdf = new ByteArrayOutputStream(); PdfCopyFields copy = new PdfCopyFields(concatenatedPdf); try {//ww w . jav a2s . c o m copy.addDocument(new PdfReader(createAcademicAdminProcessSheet(person).toByteArray())); } catch (JRException e) { logger.error(e.getMessage(), e); } copy.addDocument(new PdfReader(originalDoc)); for (PdfFiller pdfFiller : pdfFillersSet) { copy.addDocument(new PdfReader(pdfFiller.getFilledPdf(person).toByteArray())); } copy.close(); return concatenatedPdf; }
From source file:org.fenixedu.academic.servlet.ProcessCandidacyPrintAllDocumentsFilter.java
License:Open Source License
private ByteArrayOutputStream concatenateDocs(byte[] originalDoc, Person person) throws IOException, DocumentException { ByteArrayOutputStream concatenatedPdf = new ByteArrayOutputStream(); PdfCopyFields copy = new PdfCopyFields(concatenatedPdf); //if no documents are added there is nothing to close boolean isToClose = false; if (!FirstTimeDocumentsConfiguration.getInstance().isToExclude("adminProcessSheet")) { try {/*from ww w . jav a 2s . c o m*/ copy.addDocument(new PdfReader(createAcademicAdminProcessSheet(person))); isToClose = true; } catch (Exception e) { logger.error(e.getMessage(), e); } } if (originalDoc.length > 0) { copy.addDocument(new PdfReader(originalDoc)); isToClose = true; } for (PdfFiller pdfFiller : pdfFillersSet) { if (!isPdfFillerToExclude(pdfFiller.getClass().getName())) { copy.addDocument(new PdfReader(pdfFiller.getFilledPdf(person).toByteArray())); isToClose = true; } } if (isToClose) { copy.close(); } return concatenatedPdf; }
From source file:org.fenixedu.idcards.ui.candidacydocfiller.BPIPdfFiller.java
License:Open Source License
@Override public ByteArrayOutputStream getFilledPdf(Person person) throws IOException, DocumentException { ByteArrayOutputStream concatenatedBPIPdf = new ByteArrayOutputStream(); PdfCopyFields copy = new PdfCopyFields(concatenatedBPIPdf); copy.addDocument(new PdfReader(getFilledPdfBPICardAEIST(person).toByteArray())); copy.addDocument(new PdfReader(getFilledPdfBPIDigitalDoc(person).toByteArray())); copy.addDocument(new PdfReader(getFilledPdfBPIPersonalInformation(person).toByteArray())); copy.addDocument(new PdfReader(getFilledPdfBPIProductsandServices(person).toByteArray())); copy.close();/*from w w w.java 2s .c o m*/ return concatenatedBPIPdf; }
From source file:org.fenixedu.idcards.ui.candidacydocfiller.SantanderPdfFiller.java
License:Open Source License
@Override public ByteArrayOutputStream getFilledPdf(Person person) throws IOException, DocumentException { ByteArrayOutputStream concatenatedBPIPdf = new ByteArrayOutputStream(); PdfCopyFields copy = new PdfCopyFields(concatenatedBPIPdf); copy.addDocument(new PdfReader(getFilledPdfSantanderApplication(person).toByteArray())); copy.close();/*from w w w.j av a2 s .c o m*/ return concatenatedBPIPdf; }
From source file:org.fenixedu.ulisboa.specifications.ui.firstTimeCandidacy.DocumentsPrintController.java
License:Open Source License
private static ByteArrayOutputStream concatenateDocs(byte[] existingDoc, byte[] newDoc) { ByteArrayOutputStream concatenatedPdf = new ByteArrayOutputStream(); try {//from w ww . j av a 2s . c o m PdfCopyFields copy = new PdfCopyFields(concatenatedPdf); copy.addDocument(new PdfReader(existingDoc)); copy.addDocument(new PdfReader(newDoc)); copy.close(); } catch (DocumentException | IOException e) { throw new RuntimeException(e); } return concatenatedPdf; }
From source file:org.kuali.continuity.service.JasperReportServiceImpl.java
License:Educational Community License
public void mergePdf(String outfile, List<String> pdfs) throws DocumentException, IOException { // File test = new File("/"); // String[] flist = test.list(); // for (String f : flist) { // System.out.println(f); // }//from ww w.j av a 2 s. co m FileOutputStream baos = new FileOutputStream(new File(outfile)); PdfCopyFields copy = new PdfCopyFields(baos); // int i = 0; for (String pdf : pdfs) { copy.addDocument(new PdfReader(pdf)); } copy.close(); }