List of usage examples for com.itextpdf.text.pdf PdfStamper PdfStamper
public PdfStamper(final PdfReader reader, final OutputStream os) throws DocumentException, IOException
From source file:de.mat.utils.pdftools.PdfSort4Print.java
License:Mozilla Public License
public static void sortPdfPages(String pdfSourceFile, String pdfDestinationFile, int perPage) throws Exception { PdfImportedPage page = null;/*from w ww.j a va 2s.c om*/ if (perPage != 2 && perPage != 4) { throw new IllegalArgumentException( "Sorry, perPage must only be " + "2 or 4. All other is not implemented yet :-("); } // ####### // # fill to odd pagecount // ####### // create reader PdfReader readerOrig = new PdfReader(pdfSourceFile); // calc data int countPage = readerOrig.getNumberOfPages(); int blaetter = new Double(Math.ceil((countPage + 0.0) / perPage / 2)).intValue(); int zielPages = (blaetter * perPage * 2) - countPage; if (LOGGER.isInfoEnabled()) LOGGER.info("CurPages: " + countPage + " Blaetter:" + blaetter + " AddPage:" + zielPages); // add sites String oddFile = pdfDestinationFile + ".filled.pdf"; PdfStamper stamper = new PdfStamper(readerOrig, new FileOutputStream(oddFile)); // add empty pages for (int i = 1; i <= zielPages; i++) { if (LOGGER.isDebugEnabled()) LOGGER.debug("addEmptyPage: " + i); stamper.insertPage(readerOrig.getNumberOfPages() + 1, readerOrig.getPageSizeWithRotation(1)); } stamper.close(); readerOrig.close(); // ######## // # read new odd document and sort pages // ######## // step 1: create new reader PdfReader readerOdd = new PdfReader(oddFile); // create writerSorted String sortedFile = pdfDestinationFile; Document documentSorted = new Document(readerOrig.getPageSizeWithRotation(1)); PdfCopy writerSorted = new PdfCopy(documentSorted, new FileOutputStream(sortedFile)); documentSorted.open(); // add pages in calced order List<Integer> lstPageNr = new ArrayList<Integer>(); int pageCount = readerOdd.getNumberOfPages(); int startseite = 1; for (int i = 1; i <= blaetter; i++) { if (perPage == 2) { startseite = ((i - 1) * perPage) + 1; if (LOGGER.isDebugEnabled()) LOGGER.debug("Blatt:" + i + " Startseite: " + startseite); // front top lstPageNr.add(new Integer(pageCount - startseite + 1)); // front bottom lstPageNr.add(new Integer(startseite)); // back top lstPageNr.add(new Integer(startseite + 1)); // back bottom lstPageNr.add(new Integer(pageCount - startseite + 1 - 1)); } else if (perPage == 4) { startseite = ((i - 1) * perPage) + 1; if (LOGGER.isDebugEnabled()) LOGGER.debug("Blatt:" + i + " Startseite: " + startseite); // front top left lstPageNr.add(new Integer(pageCount - startseite + 1)); // front top right lstPageNr.add(new Integer(startseite)); // front bottom lefts lstPageNr.add(new Integer(pageCount - startseite + 1 - 2)); // front bottom right lstPageNr.add(new Integer(startseite + 2)); // back top left lstPageNr.add(new Integer(startseite + 1)); // back top right lstPageNr.add(new Integer(pageCount - startseite + 1 - 1)); // back bottom left lstPageNr.add(new Integer(startseite + 1 + 2)); // back bottom right lstPageNr.add(new Integer(pageCount - startseite + 1 - 1 - 2)); } else { throw new IllegalArgumentException( "Sorry, perPage must " + "only be 2 or 4. All other is not implemented yet :-("); } } if (LOGGER.isInfoEnabled()) LOGGER.info("Seiten:" + lstPageNr.size()); // copy pages for (Iterator iter = lstPageNr.iterator(); iter.hasNext();) { int pageNum = ((Integer) iter.next()).intValue(); if (LOGGER.isDebugEnabled()) LOGGER.debug("addSortPage: " + pageNum); page = writerSorted.getImportedPage(readerOdd, pageNum); writerSorted.addPage(page); } // close everything documentSorted.close(); writerSorted.close(); readerOdd.close(); // delete Tmp-File File file = new File(oddFile); file.delete(); }
From source file:dk.dma.epd.common.util.FALPDFGenerator.java
License:Apache License
public void generateFal1Form(FALForm1 fal1form, String filename) { try {//from w w w .j av a 2 s .c o m PdfReader pdfReader = new PdfReader("FALForm1.pdf"); FileOutputStream fileWriteStream = new FileOutputStream(filename); PdfStamper pdfStamper = new PdfStamper(pdfReader, fileWriteStream); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getUnderContent(i); // Text over the existing page BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 8); int xFirstColum = 68; int xSecondColum = 314; int startYFirstColumn = 659; int startYSecondColumn = 659; // Arrival Depature if (fal1form.isArrival()) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 316, 690, 0); } else { // Departure content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 380, 690, 0); } // Name and Type of ship content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getNameAndTypeOfShip(), xFirstColum, startYFirstColumn, 0); // IMO Number content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getImoNumber(), xSecondColum, startYSecondColumn, 0); // Call Sign content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getCallSign(), xFirstColum, startYFirstColumn - 30, 0); // Voyage Number content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getVoyageNumber(), xSecondColum, startYSecondColumn - 30, 0); // Port of Arrival/depature content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getPortOfArrivalDeapture(), xFirstColum, startYFirstColumn - 60, 0); // Date and time of arrival/depature content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getDateAndTimeOfArrivalDepature(), xSecondColum, startYFirstColumn - 60, 0); // Flag State of ship content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getFlagStateOfShip(), xFirstColum, startYFirstColumn - 90, 0); // Name of Master content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getNameOfMaster(), xFirstColum + 135, startYFirstColumn - 90, 0); // Last port of call/next port of all content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getLastPortOfCall(), xSecondColum, startYFirstColumn - 90, 0); // Certificate of registry content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getCertificateOfRegistry(), xFirstColum, startYFirstColumn - 120, 0); String nameAndContact = fal1form.getNameAndContactDetalsOfShipsAgent(); addMultiLine(nameAndContact, startYFirstColumn, xSecondColum, content, 54, 120); // Gross Tonnage content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getGrossTonnage(), xFirstColum, startYFirstColumn - 150, 0); // Net Tonnage content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getNetTonnage(), xFirstColum + 135, startYFirstColumn - 150, 0); // Position of the ship in the port content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getPositionOfTheShip(), xFirstColum, startYFirstColumn - 180, 0); // Brief particulars of voyage String briefVoyageParticulars = fal1form.getBriefParticulars(); addMultiLine(briefVoyageParticulars, startYFirstColumn, xFirstColum, content, 140, 210); // Brief particulars of cargo String briefCargoParticulars = fal1form.getBriefDescriptionOfCargo(); addMultiLine(briefCargoParticulars, startYFirstColumn, xFirstColum, content, 140, 257); // Number of Crew content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getNumberOfCrew(), xFirstColum, startYFirstColumn - 305, 0); // Number of Passengers content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getNumberOfPassengers(), xFirstColum + 130, startYFirstColumn - 305, 0); // Remarks String remarks = fal1form.getRemarks(); addMultiLine(remarks, startYFirstColumn, xSecondColum, content, 54, 305); // Ship waste requirements String wasteRequirements = fal1form.getShipWasteRequirements(); addMultiLine(wasteRequirements, startYFirstColumn, xSecondColum, content, 54, 405); content.endText(); } pdfStamper.close(); fileWriteStream.close(); fileWriteStream.flush(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String createPDF(String input, String output) throws FileNotFoundException, DocumentException, IOException { heightScalar = 0;// w w w.j a v a 2 s. co m //Addition. linh 07.21.2016 bypass owner password PdfReader.unethicalreading = true; PdfReader reader = new PdfReader(input); //Sets up the stamper, which is what adds all the content to the page. pds = new PdfStamper(reader, new FileOutputStream(output)); PdfImportedPage page; page = pds.getImportedPage(reader, 1); PdfContentByte bg; totalPages = reader.getNumberOfPages(); r = new Rectangle[totalPages]; rotation = new int[totalPages]; for (int x = 0; x < totalPages; x++) { r[x] = reader.getPageSizeWithRotation(x + 1); rotation[x] = reader.getPageRotation(x + 1); } mediabox = getDocumentMediaBox(reader, totalPages); //r = reader.getPageSizeWithRotation(1); //setRatio(); bg = pds.getUnderContent(1); heightScalar = 0; return ""; }
From source file:es.sm2.openppm.front.utils.DocumentUtils.java
License:Open Source License
/** * Create PDF for Control Change//from w w w . j a v a2s . com * @param idioma * @param project * @param change * @param preparedBy * @return * @throws DocumentException * @throws LogicException */ public static byte[] toPdf(ResourceBundle idioma, Project project, Changecontrol change, Employee preparedBy, final Image headerImg, final Image footerImg) throws DocumentException, LogicException { if (change == null) { throw new DocumentException("No change control found."); } if (preparedBy == null || preparedBy.getContact() == null) { throw new UserSendingException(); } Document document = new Document(PageSize.A4); document.setMargins(70F, 70F, 38F, 38F); // Total Height: 842pt, Total Width: 595pt byte[] file = null; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @SuppressWarnings("unused") PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream); document.open(); Font fontHeader = new Font(FontFamily.TIMES_ROMAN, 9, Font.BOLD); Font fontCell = new Font(FontFamily.TIMES_ROMAN, 9); Font tituloFont = new Font(FontFamily.TIMES_ROMAN, 16, Font.BOLD); document.add(new Paragraph(" ", tituloFont)); document.add(new Paragraph(" ", tituloFont)); document.add(new Paragraph(" ", fontHeader)); Paragraph title = new Paragraph(idioma.getString("change_request").toUpperCase(), tituloFont); title.setAlignment(Paragraph.ALIGN_CENTER); document.add(title); // Header Table // Project info PdfPTable tableHeader = new PdfPTable(3); tableHeader.setWidthPercentage(100); tableHeader.setSpacingBefore(10); tableHeader.setSpacingAfter(15); int[] colWidth = new int[3]; colWidth[0] = 40; colWidth[1] = 30; colWidth[2] = 30; tableHeader.setWidths(colWidth); tableHeader.addCell( prepareHeaderCell(idioma.getString("change_request.project_name"), fontHeader, 1F, 0F, 0F, 1F)); tableHeader.addCell( prepareHeaderCell(idioma.getString("change_request.prepared_by"), fontHeader, 1F, 0F, 0F, 1F)); tableHeader.addCell(prepareHeaderCell(idioma.getString("change_request.date"), fontHeader, 1F, 1F, 0F, 1F)); tableHeader.addCell(prepareCell(project.getProjectName() + " / " + project.getAccountingCode(), fontCell, 0F, 0F, 0F, 1F)); tableHeader.addCell(prepareCell(preparedBy.getContact().getFullName(), fontCell, 0F, 0F, 0F, 1F)); tableHeader.addCell(prepareCell(DateUtil.format(idioma, new Date()), fontCell, 0F, 1F, 0F, 1F)); tableHeader.addCell( prepareHeaderCell(idioma.getString("change_request.customer"), fontHeader, 1F, 0F, 0F, 1F)); tableHeader.addCell( prepareHeaderCell(idioma.getString("change_request.contact_name"), fontHeader, 1F, 0F, 0F, 1F)); tableHeader.addCell( prepareHeaderCell(idioma.getString("change_request.customer_type"), fontHeader, 1F, 1F, 0F, 1F)); tableHeader.addCell(prepareCell(project.getCustomer() != null ? project.getCustomer().getName() : "", fontCell, 0F, 0F, 0F, 1F)); tableHeader.addCell(prepareCell((project.getCustomer() != null ? project.getCustomer().getName() : "-"), fontCell, 0F, 0F, 0F, 1F)); Customertype cusType = (project.getCustomer() != null ? project.getCustomer().getCustomertype() : null); tableHeader.addCell(prepareCell(cusType == null ? "" : cusType.getName(), fontCell, 0F, 1F, 0F, 1F)); tableHeader.addCell( prepareHeaderCell(idioma.getString("change_request.business_manager"), fontHeader, 1F, 0F, 0F, 1F)); tableHeader.addCell( prepareHeaderCell(idioma.getString("change_request.project_manager"), fontHeader, 1F, 0F, 0F, 1F)); tableHeader.addCell( prepareHeaderCell(idioma.getString("change_request.originator"), fontHeader, 1F, 1F, 0F, 1F)); Employee bm = project.getEmployeeByFunctionalManager(); Employee pm = project.getEmployeeByProjectManager(); tableHeader.addCell(prepareCell(bm == null ? "" : bm.getContact().getFullName(), fontCell, 0F, 0F, 1F, 1F)); tableHeader.addCell(prepareCell(pm == null ? "" : pm.getContact().getFullName(), fontCell, 0F, 0F, 1F, 1F)); tableHeader.addCell(prepareCell(change.getOriginator(), fontCell, 0F, 1F, 1F, 1F)); document.add(tableHeader); // Change Information document.add(new Paragraph(idioma.getString("change_information"))); PdfPTable tableInfo = new PdfPTable(1); tableInfo.setWidthPercentage(100); tableInfo.setSpacingBefore(10); tableInfo.setSpacingAfter(15); tableInfo.addCell(prepareHeaderCell(idioma.getString("change.change_type"), fontHeader, 1F, 1F, 0F, 1F)); tableInfo.addCell(prepareCell(change.getChangetype().getDescription(), fontCell, 0F, 1F, 0F, 1F)); String priorityDesc = ""; if (change.getPriority().equals('H')) priorityDesc = idioma.getString("change.priority.high"); if (change.getPriority().equals('N')) priorityDesc = idioma.getString("change.priority.normal"); if (change.getPriority().equals('L')) priorityDesc = idioma.getString("change.priority.low"); tableInfo.addCell(prepareHeaderCell(idioma.getString("change.priority"), fontHeader, 1F, 1F, 0F, 1F)); tableInfo.addCell(prepareCell(priorityDesc, fontCell, 0F, 1F, 0F, 1F)); tableInfo.addCell(prepareHeaderCell(idioma.getString("change.desc"), fontHeader, 1F, 1F, 0F, 1F)); tableInfo.addCell(prepareCell(change.getDescription(), fontCell, 0F, 1F, 0F, 1F)); tableInfo.addCell( prepareHeaderCell(idioma.getString("change.recommended_solution"), fontHeader, 1F, 1F, 0F, 1F)); tableInfo.addCell(prepareCell(change.getRecommendedSolution(), fontCell, 0F, 1F, 1F, 1F)); PdfPTable tableSubInfo = new PdfPTable(3); tableSubInfo.setWidthPercentage(100); //TODO MIGRACION tableSubInfo.addCell(prepareSubCell(idioma.getString("change.wbs_node"), fontHeader)); tableSubInfo.addCell(prepareSubCell(idioma.getString("change.estimated_effort"), fontHeader)); tableSubInfo.addCell(prepareSubCell(idioma.getString("change.estimated_cost"), fontHeader)); tableSubInfo.addCell( prepareSubCell((change.getWbsnode() != null ? change.getWbsnode().getName() : ""), fontCell)); tableSubInfo.addCell(prepareSubCell( (change.getEstimatedEffort() != null ? String.valueOf(change.getEstimatedEffort()) : ""), fontCell)); tableSubInfo.addCell(prepareSubCell( (change.getEstimatedCost() != null ? ValidateUtil.toCurrency(change.getEstimatedCost()) : ""), fontCell)); PdfPCell subTable = new PdfPCell(tableSubInfo); subTable.setBorderWidth(1F); tableInfo.addCell(subTable); tableInfo.addCell(prepareHeaderCell(idioma.getString("change.impact_desc"), fontHeader, 1F, 1F, 0F, 1F)); tableInfo.addCell(prepareCell(change.getImpactDescription(), fontCell, 0F, 1F, 1F, 1F)); document.add(tableInfo); document.add(new Paragraph(idioma.getString("change.resolution"))); PdfPTable tableResolution = new PdfPTable(1); tableResolution.setWidthPercentage(100); tableResolution.setSpacingBefore(10); tableResolution.setSpacingAfter(15); tableResolution .addCell(prepareHeaderCell(idioma.getString("change.resolution"), fontHeader, 1F, 1F, 0F, 1F)); tableResolution.addCell( prepareCell((change.getResolution() != null && change.getResolution() ? idioma.getString("yes") : idioma.getString("no")), fontCell, 0F, 1F, 0F, 1F)); tableResolution .addCell(prepareHeaderCell(idioma.getString("change.resolution_date"), fontHeader, 1F, 1F, 0F, 1F)); tableResolution.addCell( prepareCell(DateUtil.format(idioma, change.getResolutionDate()), fontCell, 0F, 1F, 0F, 1F)); tableResolution.addCell( prepareHeaderCell(idioma.getString("change.resolution_reason"), fontHeader, 1F, 1F, 0F, 1F)); tableResolution.addCell(prepareCell(change.getResolutionReason(), fontCell, 0F, 1F, 1F, 1F)); document.add(tableResolution); document.close(); try { PdfReader reader = new PdfReader(outputStream.toByteArray()); PdfStamper stamper = new PdfStamper(reader, outputStream); int numPag = reader.getNumberOfPages(); for (int i = 1; i <= reader.getNumberOfPages(); i++) { setHeaderFooter(i, numPag, headerImg, footerImg, reader, stamper, idioma); } stamper.close(); } catch (IOException e) { e.printStackTrace(); } file = outputStream.toByteArray(); return file; }
From source file:ExternalForms.Browser.java
public String getDataFromPDF() { String all_inputs = ""; //concatenated string of inputs in order try {/*from w w w . ja v a 2 s . c om*/ final int MAX_VARIABLES = connect.getFormVarCount(formID); //get from db System.out.println("MAX VARIABLES: " + MAX_VARIABLES); //---------------------------------------------------------- final String DELIMITER = "~"; //pwede mani i-change dumbNavigate(); PdfReader pdfTemplate = new PdfReader(documentsPath + "\\" + formName + ".pdf"); FileOutputStream fileOutputStream = new FileOutputStream( dirPrintables.getAbsolutePath() + "\\" + formName + ".pdf"); PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream); //System.out.println("TRY: " + stamper.getAcroFields().getField("1")); stamper.setFormFlattening(true); System.out.println("Display Inputs Per Variable and Concatenate after\n"); //change textFields-------------------------------------------------------------------- for (int var = 1; var <= MAX_VARIABLES; var++) { String input_from_pdf_field = stamper.getAcroFields().getField("" + var); //get field input using variable System.out.println("Input #" + var + " = " + input_from_pdf_field); //display all_inputs += DELIMITER + input_from_pdf_field; //concatenate } stamper.close(); pdfTemplate.close(); //-------------------------------------------------------------------------------------- System.out.println("\nConcatenated String to Store to DB\n"); System.out.println("\n" + all_inputs + "\n"); try { File pdfFile = new File(documentsPath + "\\" + formName + ".pdf"); if (pdfFile.exists()) { if (pdfFile.delete()) { //Desktop.getDesktop().open(pdfFile); System.out.println("Form in Documents Deleted"); } } else { System.out.println("File to delete in My Documents does not exists!"); } } catch (Exception ex) { } b.setVisible(false); c.setText("Done"); j.navigate(dirPrintables.getAbsolutePath() + "\\" + formName + ".pdf"); System.out.println(dirPrintables.getAbsolutePath() + "\\" + formName + ".pdf"); } catch (IOException | DocumentException ex) { Logger.getLogger(Browser.class.getName()).log(Level.SEVERE, null, ex); } return all_inputs; }
From source file:ExternalForms.Browser.java
public void setDataToPdf(String fName, String formEntryID) { try {//from w w w. j a v a2 s . c o m String all_inputs = connect.getFormEntryFormData(formEntryID); //assuming na gusto ka magbutang ug tulo ka value sa first 3 fields final String DELIMITER = "~"; System.out.println("\nSplit Concatenated String and Display\n"); String split_inputs[] = all_inputs.split(DELIMITER); PdfReader pdfTemplate = new PdfReader( dirTemplates.getAbsolutePath() + "\\" + (formName = fName) + ".pdf"); //navigate("temp", "x"); postFix = checkIfSameNameFileExists(this.dirPrintables, formName + ".pdf"); System.out.println("FILENAME TO FETCH: " + formName + postFix + "|"); FileOutputStream fileOutputStream = new FileOutputStream( dirPrintables.getAbsolutePath() + "\\" + formName + postFix + ".pdf"); PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream); stamper.setFormFlattening(true); //change textFields-------------------------------------------------------------------- for (int var = 1; var < split_inputs.length; var++) { stamper.getAcroFields().setField("" + var, split_inputs[var]); //get field input using variable System.out.println("Input #" + var + " = " + split_inputs[var]); //display } //-------------------------------------------------------------------------------------- stamper.close(); pdfTemplate.close(); b.setVisible(false); c.setText("Done"); j.navigate(dirPrintables.getAbsolutePath() + "\\" + formName + postFix + ".pdf"); this.setVisible(true); System.out.println(dirPrintables.getAbsolutePath() + "\\" + formName + postFix + ".pdf"); } catch (IOException | DocumentException ex) { Logger.getLogger(Browser.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:ExternalNonFormClasses.RequestFormBrowser.java
public void disableFormOnly(boolean choice) { //save data try {/*from w w w. jav a 2 s . c om*/ PdfReader pdfTemplate = new PdfReader( "C:\\Users\\mrRNBean\\Documents\\NetBeansProjects\\BRMS_V2\\build\\templates\\" + form_name + ".pdf"); FileOutputStream fileOutputStream = new FileOutputStream( "C:\\Users\\mrRNBean\\Documents\\NetBeansProjects\\BRMS_V2\\build\\printables\\" + form_name + ".pdf"); PdfStamper stamper = new PdfStamper(pdfTemplate, fileOutputStream); stamper.setFormFlattening(true); if (choice) { //post-request //manipiulate form fields-------------------------------------------------------------------- stamper.getAcroFields().setField("12", "CHORVES"); //String x = stamper.getAcroFields().getField("province"); //------------------------------------------------------------------------------------------- //get field form_vars from form tb //slice data with delimiter and store to array //fetch array //use as basis for loop //get field using variable name in each array entry //every field entry should be added to a string concatenation //save string concatenation and form in "printables/" to FormRequest.tb } stamper.close(); pdfTemplate.close(); } catch (IOException | DocumentException ex) { Logger.getLogger(RequestFormBrowser.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:fyp.JavaWritePDF.java
public void manipulatePdf(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); // read source file PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); // create destination file stamper.insertPage(reader.getNumberOfPages() + 1, reader.getPageSizeWithRotation(1)); // insert new page Image img = Image.getInstance(IMG); // get instance of image file img.setAbsolutePosition(0, 350);//from w ww.ja v a 2 s.c om stamper.getOverContent(2).addImage(img); // insert image to new page stamper.close(); // close stamper File delfile = new File(SRC); delfile.delete(); // delete source file respiratorytest.success(); }
From source file:fyp.JavaWritePDF.java
public void manipulatePdf2(String src, String dest) throws IOException, DocumentException { PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); stamper.insertPage(reader.getNumberOfPages() + 1, reader.getPageSizeWithRotation(1)); stamper.insertPage(reader.getNumberOfPages() + 1, reader.getPageSizeWithRotation(1));// create a second new page Image img = Image.getInstance(IMG); Image img2 = Image.getInstance(IMG2); img.setAbsolutePosition(0, 350);/*from www. j av a 2 s . co m*/ img2.setAbsolutePosition(0, 350); stamper.getOverContent(2).addImage(img); stamper.getOverContent(3).addImage(img2); // add the second sessions image to the new page stamper.close(); File delfile = new File(SRC); delfile.delete(); respiratorytest.success(); }
From source file:gov.nih.nci.firebird.service.pdf.PdfProcessor.java
License:Open Source License
final void process() throws IOException { PdfReader reader = new PdfReader(srcPdfInputStream); PdfStamper stamper = null;/*www . j av a 2 s .c o m*/ try { stamper = new PdfStamper(reader, destPdfOutputStream); handleProcessing(reader, stamper); } catch (DocumentException e) { throw new IllegalStateException("Unexpected problem processing PDF", e); } finally { reader.close(); close(stamper); } }