List of usage examples for com.itextpdf.text PageSize A4
Rectangle A4
To view the source code for com.itextpdf.text PageSize A4.
Click Source Link
From source file:PDF.PDF.java
/** * * @param fname this is the filename passed in from the jsp * @param k this is all the details from the order to be passed to pdf * @exception FileNotFoundException this will catch an error if the file to * be or written to is not found OutputStream file outputs the given file to * bytes PdfWriter writer creates a pdf version of the given file (file) to * the given format (doc) HTMLWorker htmlWorker converts the data from the * String (k) to the PDF format doc.close() closes access the document * file.close() closes access to the file /*from w w w. j a va 2 s . com*/ */ public PDF(String fname, String k) throws FileNotFoundException { filename = "Order" + fname + ".pdf"; try { f = new File(filename); OutputStream file = new FileOutputStream(f); Document doc = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(doc, file); doc.open(); HTMLWorker htmlWorker = new HTMLWorker(doc); htmlWorker.parse(new StringReader(k)); doc.close(); file.close(); } catch (IOException | DocumentException e) { System.err.println("IOExcetpion"); } }
From source file:pdf.PdfBuilder.java
/** * Creates an accessible PDF with images and text. * @param dest the path to the resulting PDF * @throws IOException/*from www. jav a 2 s .c o m*/ * @throws DocumentException */ public String createPdf(Invoice invoice) throws IOException, DocumentException { DEST = "C://temp/"; SimpleDateFormat sdf = new SimpleDateFormat("MM"); DEST += invoice.getCar().getId() + "month" + sdf.format(invoice.getSeriesOfLocationsOnRoad().get(0).getLocations().get(0).getDate()) + ".pdf"; File file = new File(DEST); file.getParentFile().mkdirs(); Document document = new Document(PageSize.A4.rotate()); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST)); writer.setPdfVersion(PdfWriter.VERSION_1_7); //TAGGED PDF //Make document tagged writer.setTagged(); //=============== //PDF/UA //Set document metadata writer.setViewerPreferences(PdfWriter.DisplayDocTitle); document.addLanguage("en-US"); document.addTitle("Factuur voor auto " + invoice.getCar().getLicensePlate()); writer.createXmpMetadata(); //===================== document.open(); Font font = FontFactory.getFont(FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 20); double amountPaidForDistance = invoice.getTotalAmount(); double amountPaidForCordons = 0; for (Cordon c : invoice.getCordonOccurrences()) { amountPaidForDistance -= c.getAmount(); amountPaidForCordons += c.getAmount(); } Paragraph p = new Paragraph("\n", font); p.add(new Chunk("Aantal gereden kilometers:")); p.add(new Chunk("\n")); p.add(new Chunk(String.valueOf(invoice.getTotalDistance()) + " kilometer")); p.add(new Chunk("\n")); p.add(new Chunk("Met een gemiddeld tarief van " + (amountPaidForDistance / invoice.getTotalDistance() * 100) + " eurocent per kilometer")); p.add(new Chunk("\n")); p.add(new Chunk("Bedrag dat betaald dient te worden over de kilometers: ")); p.add(new Chunk("\n")); p.add(new Chunk(amountPaidForDistance + " euro")); document.add(p); p = new Paragraph("\n\n", font); p.add(new Chunk(invoice.cordonOccurrencesString())); p.add(new Chunk("\n")); p.add(new Chunk("Bedrag dat betaald dient te worden over de cordons: ")); p.add(new Chunk("\n")); p.add(new Chunk(amountPaidForCordons + " euro")); document.add(p); p = new Paragraph("\n\n", font); p.add(new Chunk("Totaal bedrag dat betaald dient te worden: ")); p.add(new Chunk("\n")); p.add(new Chunk(String.valueOf(invoice.getTotalAmount()) + " euro")); document.add(p); document.close(); return DEST; }
From source file:pdf.PdfUtility.java
public void createPdf() { Logger.getLogger(PdfUtility.class.getName()).log(Level.INFO, "Creating pdf..."); Document document = new Document(); try {//from ww w .ja v a2 s . c o m document.setPageSize(PageSize.A4); document.setMargins(62, 48, 36, 36); baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); addTitle(document); addData(document); } catch (DocumentException ex) { Logger.getLogger(PdfUtility.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(PdfUtility.class.getName()).log(Level.SEVERE, null, ex); } finally { document.close(); } }
From source file:pdfMaker.MakePdfFile.java
MakePdfFile(String text1, String text2, String text3) throws IOException, DocumentException, RuntimeException { // // www. ja v a 2s .c o m url = text1; Document document = null; String fileDir = "TEST_MAT.pdf"; // step 1 document = new Document(PageSize.A4, 20, 20, 20, 20); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileDir)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); Image image = ZxingUti.getQRCode(url); // SHIFT_JIS com.itextpdf.text.Image iTextImage = com.itextpdf.text.Image.getInstance(image, null); // http://d.hatena.ne.jp/MoonMtLab/20130920/1379626380 //Image?? com.itextpdf.text.Image img = iTextImage; //??() img.setAbsolutePosition(document.getPageSize().getWidth() - 30, document.getPageSize().getHeight() - 30); System.out.println(document.getPageSize().getWidth()); System.out.println(document.getPageSize().getHeight()); //? img.scaleAbsolute(30, 30); //PdfContentByte?? PdfContentByte pdfContentByte = writer.getDirectContent(); //??? pdfContentByte.addImage(img); /* writer.setEncryption("Hello".getBytes(), "World".getBytes(), PdfWriter.ALLOW_SCREENREADERS, PdfWriter.STANDARD_ENCRYPTION_128); // */ document.close(); }
From source file:pdfMaker.MakePdfFile.java
public void createPdf(String mainTitle, String subTitle, String url, String userName, //String scanType, String comment,/* w w w. java 2 s .c om*/ //String thisPassCode, String passCodeA, String passCodeB, String fileDir, Boolean noBarCodePrint) throws IOException, DocumentException, RuntimeException { Document document = null; try { // step 1 document = new Document(PageSize.A4, 60, 50, 50, 35); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileDir)); // step 3 document.open(); // step 4 PdfContentByte cb = writer.getDirectContent(); /* Properties props = new Properties(); String jarPath = System.getProperty("java.class.path"); String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator)+1); FontFactory.registerDirectory("/res"); FontFactory.register("ipag.ttf"); Font ipaGothic = FontFactory.getFont("ipag", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); //10 is the size InputStream is = getClass().getResourceAsStream("/res/ipag.ttf"); */ Properties props = new Properties(); String jarPath = System.getProperty("java.class.path"); String dirPath = jarPath.substring(0, jarPath.lastIndexOf(File.separator) + 1); System.out.println(jarPath); System.out.println(dirPath); System.out.println(System.getProperty("user.dir")); Font ipaGothic = new Font(BaseFont.createFont(System.getProperty("user.dir") + "\\res\\ipag.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 11); //?(2) PdfPTable pdfPTable = new PdfPTable(2); pdfPTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); pdfPTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.getDefaultCell().setFixedHeight(150); pdfPTable.setWidthPercentage(100f); int pdfPTableWidth[] = { 10, 90 }; pdfPTable.setWidths(pdfPTableWidth); PdfPCell cell_1_1 = new PdfPCell(new Paragraph("??", ipaGothic)); cell_1_1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_1_1.setHorizontalAlignment(Element.ALIGN_CENTER); cell_1_1.setFixedHeight(50); PdfPCell cell_1_2 = new PdfPCell(new Paragraph(mainTitle, ipaGothic)); cell_1_2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_1_2.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell_2_1 = new PdfPCell(new Paragraph("", ipaGothic)); cell_2_1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_2_1.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell cell_2_2 = new PdfPCell(new Paragraph(subTitle, ipaGothic)); cell_2_2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_2_2.setHorizontalAlignment(Element.ALIGN_CENTER); cell_2_2.setFixedHeight(50); pdfPTable.addCell(cell_1_1); pdfPTable.addCell(cell_1_2); pdfPTable.addCell(cell_2_1); pdfPTable.addCell(cell_2_2); PdfPCell cellUrlKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellUrlKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlKey.setRowspan(2); pdfPTable.addCell(cellUrlKey); PdfPCell cellUrlValue = new PdfPCell(new Paragraph(url, ipaGothic)); cellUrlValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlValue.setFixedHeight(50); pdfPTable.addCell(cellUrlValue); /* */ //cellUrlValue.getImage(); writer.getDirectContent().addImage(cellUrlValue.getImage(), 100, 100, 100, 100, 100, 100); if (url.length() != 0 && !noBarCodePrint) { /* ? BarcodeQRCode qr = new BarcodeQRCode(url, 50, 50, null); PdfPCell cellUrlValueQr = new PdfPCell(qr.getImage()); cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlValueQr.setFixedHeight(80); pdfPTable.addCell(cellUrlValueQr); */ Image image = ZxingUti.getQRCode(url); // SHIFT_JIS com.itextpdf.text.Image iTextImage = com.itextpdf.text.Image.getInstance(image, null); PdfPCell cell = new PdfPCell(iTextImage); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setFixedHeight(100); pdfPTable.addCell(cell); // SIFT_JIS } else { PdfPCell cellUrlValueQr = new PdfPCell(new Paragraph("", ipaGothic)); cellUrlValueQr.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUrlValueQr.setHorizontalAlignment(Element.ALIGN_CENTER); cellUrlValueQr.setFixedHeight(80); pdfPTable.addCell(cellUrlValueQr); } PdfPCell cellUserNameKey = new PdfPCell(new Paragraph("", ipaGothic)); cellUserNameKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameKey.setRowspan(2); pdfPTable.addCell(cellUserNameKey); PdfPCell cellUserNameValue = new PdfPCell(new Paragraph(userName, ipaGothic)); cellUserNameValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValue.setFixedHeight(30); pdfPTable.addCell(cellUserNameValue); if (userName.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(userName); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellUserNameValueBc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValueBc.setFixedHeight(80); pdfPTable.addCell(cellUserNameValueBc); } else { PdfPCell cellUserNameValueBc = new PdfPCell(new Paragraph("---", ipaGothic)); cellUserNameValueBc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellUserNameValueBc.setHorizontalAlignment(Element.ALIGN_CENTER); cellUserNameValueBc.setFixedHeight(80); pdfPTable.addCell(cellUserNameValueBc); } PdfPCell cellPassCodeKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellPassCodeKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeKey.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeKey.setRowspan(3); pdfPTable.addCell(cellPassCodeKey); PdfPCell cellPassCodeValue = new PdfPCell(new Paragraph(passCodeA + passCodeB, ipaGothic)); cellPassCodeValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeValue.setFixedHeight(30); pdfPTable.addCell(cellPassCodeValue); if (passCodeA.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(passCodeA); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellPassCodeA_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeA_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeA_Bc); } else { PdfPCell cellPassCodeA_Bc = new PdfPCell(new Paragraph("---", ipaGothic)); cellPassCodeA_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeA_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeA_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeA_Bc); } if (passCodeB.length() != 0 && !noBarCodePrint) { Barcode128 code128 = new Barcode128(); code128.setCode(passCodeB); code128.setFont(ipaGothic.getBaseFont()); code128.setBarHeight(40f); PdfPCell cellPassCodeB_Bc = new PdfPCell(code128.createImageWithBarcode(cb, null, null)); cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeB_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeB_Bc); } else { PdfPCell cellPassCodeB_Bc = new PdfPCell(new Paragraph("---", ipaGothic)); cellPassCodeB_Bc.setVerticalAlignment(Element.ALIGN_MIDDLE); cellPassCodeB_Bc.setHorizontalAlignment(Element.ALIGN_CENTER); cellPassCodeB_Bc.setFixedHeight(80); pdfPTable.addCell(cellPassCodeB_Bc); } PdfPCell cellCommentKey = new PdfPCell(new Paragraph("?", ipaGothic)); cellCommentKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellCommentKey.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cellCommentKey); PdfPCell cellCommentValue = new PdfPCell(new Paragraph(comment, ipaGothic)); cellCommentValue.setVerticalAlignment(Element.ALIGN_TOP); cellCommentValue.setHorizontalAlignment(Element.ALIGN_LEFT); cellCommentValue.setFixedHeight(150); pdfPTable.addCell(cellCommentValue); PdfPCell cellIssueKey = new PdfPCell(new Paragraph("", ipaGothic)); cellIssueKey.setVerticalAlignment(Element.ALIGN_MIDDLE); cellIssueKey.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cellIssueKey); Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm"); String strDate = sdf.format(cal.getTime()); PdfPCell cellIssueValue = new PdfPCell(new Paragraph(strDate, ipaGothic)); cellIssueValue.setVerticalAlignment(Element.ALIGN_MIDDLE); cellIssueValue.setHorizontalAlignment(Element.ALIGN_CENTER); cellIssueValue.setFixedHeight(20); pdfPTable.addCell(cellIssueValue); //?? document.add(pdfPTable); /* // CODE 128 document.add(new Paragraph("?? : " + mainTitle, ipaGothic)); document.add(new Paragraph(" : " + subTitle, ipaGothic)); document.add(new Paragraph("-------------------------------------------------------")); document.add(new Paragraph(" " + strDate)); document.add(new Paragraph("-------------------------------------------------------")); BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.WINANSI, BaseFont.EMBEDDED); Font font = new Font(bf, 12); document.add(new Paragraph("", ipaGothic)); document.add(new Paragraph(url, ipaGothic)); code128.setCode(url); code128.setFont(bf); code128.setX(1); //document.add(code128.createImageWithBarcode(cb, null, null)); document.add(new Paragraph("USER", ipaGothic)); if (userName.length() != 0) { document.add(new Paragraph(userName, ipaGothic)); code128.setCode(userName); code128.setFont(bf); code128.setBarHeight(40f); document.add(code128.createImageWithBarcode(cb, null, null)); } document.add(new Paragraph("CODE", ipaGothic)); if (passCode.length() != 0) { document.add(new Paragraph(passCode, ipaGothic)); code128.setCode(passCode); code128.setFont(bf); document.add(code128.createImageWithBarcode(cb, null, null)); } document.add(new Paragraph("?", ipaGothic)); document.add(new Paragraph(comment, ipaGothic)); */ // step 5 document.close(); } catch (RuntimeException ex) { document.close(); throw ex; } }
From source file:pdfpruefbericht.PdfPruefbericht.java
License:Open Source License
public static void main(String[] args) throws IOException, DocumentException, SAXException, ParserConfigurationException, URISyntaxException { String RESULT = args[1];/*from w ww . jav a 2 s . c o m*/ String RESOURCE = args[0]; ContentParser cp; float compression; try { compression = Float.parseFloat(args[2]); } catch (NumberFormatException e) { System.out.println("Kompresion konnte nicht geparsed werden ... : " + e.getMessage()); compression = 0.5f; } try { Document document = new Document(PageSize.A4); document.setMargins(36, 72, 36, 144); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setTagged(); document.open(); PdfStructureTreeRoot root = writer.getStructureTreeRoot(); root.mapRole(new PdfName("Report"), PdfName.ROOT); root.mapRole(new PdfName("Norm"), PdfName.SECT); root.mapRole(new PdfName("Test"), PdfName.SEPARATION); root.mapRole(new PdfName("Comment"), PdfName.CO); root.mapRole(new PdfName("img"), PdfName.PI); root.mapRole(new PdfName("log"), PdfName.L); root.mapRole(new PdfName("Setup"), PdfName.SETTINGS); root.mapRole(new PdfName("device"), PdfName.D); root.mapRole(new PdfName("parameter"), PdfName.P); PdfStructureElement top = new PdfStructureElement(root, new PdfName("Report")); SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); List<PdfStructureElement> elements = new ArrayList<>(); cp = new ContentParser(document, writer, elements); parser.parse(new InputSource(new FileInputStream(RESOURCE)), new StructureParser(top, elements)); parser.parse(new InputSource(new FileInputStream(RESOURCE)), cp); PdfBuilder pdf = new PdfBuilder(document, writer, cp.getReport(), compression); pdf.build(); document.close(); } catch (IOException | DocumentException | SAXException | ParserConfigurationException e) { System.out.println(e.getMessage()); } //watermark watermark = new watermark(); }
From source file:Print.Print.java
private void printToPDF(BufferedImage bufferedImage) { // define pdfprinter and within try clause create for (int i = 0; i < quantity; i++) { PdfWriter writer = null;/*from ww w . ja va 2s . c o m*/ try { // define fileoutputstream and within try clause create FileOutputStream fos = null; document = new Document(PageSize.A4.rotate()); fos = new FileOutputStream(output + photoID + "-" + Integer.toString(i + 1) + ".pdf"); // create the writer object try { writer = PdfWriter.getInstance(document, fos); } catch (DocumentException ex) { System.out.println(ex.getMessage()); } // open the writer and the document and add the image into the document writer.open(); document.open(); try { PdfContentByte pdfCB = new PdfContentByte(writer); if (bufferedImage == null) { Image image = Image.getInstance(input); image.scaleToFit(640, 480); document.add(image); } else { Image image = Image.getInstance(pdfCB, bufferedImage, 1); image.scaleToFit(640, 480); document.add(Image.getInstance(image)); } } catch (DocumentException ex) { System.out.println(ex.getMessage()); } catch (IOException ex) { System.out.println(ex.getMessage()); } // close the document and writer document.close(); writer.close(); System.out.println("Printer done."); } catch (Exception e) { System.out.println(e.getMessage()); } } }
From source file:Print.Print.java
public void printIndex(ArrayList<String> imagesPath, String customer) { try {/*from w w w.ja va 2 s .c o m*/ //ArrayList<Image> images = new ArrayList<Image>(); Map<Image, String> dict = new HashMap<Image, String>(); for (String path : imagesPath) { try { System.out.println("path = /home/student" + path); int index = path.lastIndexOf("/"); String photoId = path.substring(index + 1, path.length()); Image newImage = Image.getInstance("/home/student" + path); //images.add(newImage); dict.put(newImage, photoId); } catch (BadElementException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } } System.out.println("Total images = " + dict.size()); Document index = new Document(PageSize.A4.rotate()); FileOutputStream fos = new FileOutputStream("/home/student/Pictures/index.pdf"); PdfWriter writer = PdfWriter.getInstance(index, fos); writer.open(); index.open(); PdfPTable adresTable = new PdfPTable(3); PdfPCell adresCell = new PdfPCell(new Paragraph(customer)); adresCell.setColspan(3); adresTable.addCell(adresCell); adresTable.setHorizontalAlignment(Element.ALIGN_CENTER); adresTable.setWidthPercentage(100); index.add(adresTable); PdfPTable table = new PdfPTable(imagesPath.size()); for (Map.Entry<Image, String> image : dict.entrySet()) { PdfPCell cell = new PdfPCell(); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(10); table.addCell(image.getValue()); cell.addElement(image.getKey()); table.addCell(cell); } index.add(table); //index.add(adresTable); index.close(); writer.close(); System.out.println("Index printed"); // // define pdfprinter and within try clause create // PdfWriter writer = null; // FileOutputStream fos = null; // Document index = new Document(PageSize.A4.rotate()); // File file; // try { // file = new File("/home/student/Pictures/index.pdf"); // if(!file.exists()){ // file.createNewFile(); // // } // String test = "test data"; // fos = new FileOutputStream(file); // fos.write(test.getBytes()); // fos.flush(); // } catch (FileNotFoundException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } catch (IOException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } // // for (BufferedImage image : bufferedImages) { // try { // writer = PdfWriter.getInstance(index, fos); // } catch (DocumentException ex) { // System.out.println(ex.getMessage()); // } // writer.open(); // index.open(); // try { // PdfContentByte pdfCB = new PdfContentByte(writer); // Image newImage = Image.getInstance(pdfCB, image, 1); // index.add(Image.getInstance(newImage)); // } catch (DocumentException ex) { // System.out.println(ex.getMessage()); // } catch (IOException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } // } // index.close(); // writer.close(); // System.out.println("Index done."); } catch (DocumentException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:printers.AbstractHorariosPrinter.java
License:Open Source License
private void creaUnSoloDocumento() throws DocumentException, FileNotFoundException { Rectangle hoja;/*from w w w . j a v a 2 s. c o m*/ if (rotated) { hoja = PageSize.A4.rotate(); } else { hoja = PageSize.A4; } Document doc = new Document(hoja); PdfWriter.getInstance(doc, new FileOutputStream(fileDst)); doc.open(); int size = hojasHorarios.size(); for (int n = 0; n < size; n++) { printCabecera(doc, cabeceras.get(n)); printHojaHorario(doc, hojasHorarios.get(n)); printPieDePagina(doc, piesDePagina.get(n)); doc.newPage(); } doc.close(); }
From source file:printers.AbstractHorariosPrinter.java
License:Open Source License
private void creaVariosDocumentos() throws DocumentException, FileNotFoundException { Rectangle hoja;// w ww . j a v a 2 s. c om if (rotated) { hoja = PageSize.A4.rotate(); } else { hoja = PageSize.A4; } int size = hojasHorarios.size(); for (int n = 0; n < size; n++) { String nombreArchivo = getNombreDocumento(parNombreDocumento.get(n)) + ".pdf"; // System.out.println("Creo archivo " + nombreArchivo); Document doc = new Document(hoja); File fichero = new File(fileDst, nombreArchivo);//Aqu tengo que unir el directorio y el nombre del fichero PdfWriter.getInstance(doc, new FileOutputStream(fichero)); doc.open(); printCabecera(doc, cabeceras.get(n)); printHojaHorario(doc, hojasHorarios.get(n)); printPieDePagina(doc, piesDePagina.get(n)); doc.close(); } }