List of usage examples for com.itextpdf.text Document Document
public Document(Rectangle pageSize)
Document
-object. From source file:com.alokomkar.aliensonearth.report.AbstractPdfReport.java
/** * // w w w . j a v a 2 s . co m * @param fileName file to be created (with location) * @return created fileName on success, else null */ public final String generateLandScapePage(String fileName) { if (fileName == null) throw new NullPointerException(ProjectMessages.EMPTY_FILE_NAME); if (fileName.endsWith(".pdf") == false) fileName += ".pdf"; Document document = new Document(PageSize.A4.rotate()); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileName)); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); addPageMetaData(document); addContent(document); document.close(); return fileName; } catch (DocumentException ex) { Logger.getLogger(AbstractPdfReport.class.getName()).log(Level.SEVERE, null, ex); document.close(); } catch (FileNotFoundException ex) { Logger.getLogger(AbstractPdfReport.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.atacadao.almoxarifado.model.GerandoPDF.java
public void pdfRelatorioSaida(ArrayList<Saida> saidas) { Document documento = new Document(PageSize.A4.rotate()); try {//from w ww . ja v a2 s. com PdfWriter pdf = PdfWriter.getInstance(documento, new FileOutputStream("relatorios.pdf")); Paragraph titulo = new Paragraph("Relatrio de Sada\n\n", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 20, Font.BOLD)); titulo.setAlignment(Element.ALIGN_CENTER); documento.open(); documento.add(titulo); PdfPTable table = new PdfPTable(8); PdfPCell cSaida = new PdfPCell(new Phrase("N Sada")); cSaida.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cNome = new PdfPCell(new Phrase("Nome")); cNome.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cPatrimonio = new PdfPCell(new Phrase("Patrimonio")); cPatrimonio.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cValor = new PdfPCell(new Phrase("Valor")); cValor.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cSolic = new PdfPCell(new Phrase("Solicitante")); cSolic.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cAtut = new PdfPCell(new Phrase("Autorizado")); cAtut.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cCodigo = new PdfPCell(new Phrase("Codigo")); cCodigo.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cDtSaida = new PdfPCell(new Phrase("Dt Sada")); cDtSaida.setBackgroundColor(BaseColor.DARK_GRAY); table.addCell(cSaida); table.addCell(cNome); table.addCell(cPatrimonio); table.addCell(cValor); table.addCell(cSolic); table.addCell(cAtut); table.addCell(cCodigo); table.addCell(cDtSaida); for (Saida saida : saidas) { PdfPCell sai = new PdfPCell(new Phrase(saida.getRegistro())); PdfPCell nomes = new PdfPCell(new Phrase(saida.getNome())); PdfPCell patrimonios = new PdfPCell(new Phrase(saida.getPatrimonio())); PdfPCell valores = new PdfPCell(new Phrase(String.valueOf(saida.getValor()))); PdfPCell solicitantes = new PdfPCell(new Phrase(saida.getSolicitador())); PdfPCell autorizados = new PdfPCell(new Phrase(saida.getAutorizador())); PdfPCell codigos = new PdfPCell(new Phrase(saida.getCodigo())); PdfPCell datas = new PdfPCell( new Phrase(FormatosDeData.formatarLongParaDatas(saida.getDatasaida().getTime()))); table.addCell(sai); table.addCell(nomes); table.addCell(patrimonios); table.addCell(valores); table.addCell(solicitantes); table.addCell(autorizados); table.addCell(codigos); table.addCell(datas); } documento.add(table); documento.close(); Desktop.getDesktop().open(new File("relatorios.pdf")); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.atacadao.almoxarifado.model.GerandoPDF.java
public void pdfImpressaoBarraDeCodigo(String codigo) { Document documento = new Document(new Rectangle(90, 65)); documento.setMargins(0, 0, 0, 0);/*from w ww . j av a2 s.com*/ PdfWriter pdf; try { pdf = PdfWriter.getInstance(documento, new FileOutputStream("codigodebarras.pdf")); documento.open(); PdfContentByte contB = pdf.getDirectContent(); Barcode128 barCode = new Barcode128(); barCode.setCode(codigo); barCode.setCodeType(Barcode128.CODE128); Image image = barCode.createImageWithBarcode(contB, BaseColor.BLACK, BaseColor.BLACK); Paragraph titulo = new Paragraph("ATCADO DOS PISOS\n", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 5)); titulo.setPaddingTop(0); titulo.setAlignment(Element.ALIGN_CENTER); float scaler = ((documento.getPageSize().getWidth() - documento.leftMargin() - documento.rightMargin() - 0) / image.getWidth()) * 60; image.scalePercent(scaler); image.setPaddingTop(0); image.setAlignment(Element.ALIGN_CENTER); documento.add(titulo); documento.add(image); documento.close(); Desktop.getDesktop().open(new File("codigodebarras.pdf")); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.betel.flowers.pdf.util.RemoveBlankPageFromPDF.java
public static void removeBlankPdfPages(String source, String destination) throws IOException, DocumentException { PdfReader r = null;//from www. ja v a2 s .c om RandomAccessSourceFactory rasf = null; RandomAccessFileOrArray raf = null; Document document = null; PdfCopy writer = null; try { r = new PdfReader(source); // deprecated // RandomAccessFileOrArray raf // = new RandomAccessFileOrArray(pdfSourceFile); // itext 5.4.1 rasf = new RandomAccessSourceFactory(); raf = new RandomAccessFileOrArray(rasf.createBestSource(source)); document = new Document(r.getPageSizeWithRotation(1)); writer = new PdfCopy(document, new FileOutputStream(destination)); document.open(); PdfImportedPage page = null; for (int i = 1; i <= r.getNumberOfPages(); i++) { // first check, examine the resource dictionary for /Font or // /XObject keys. If either are present -> not blank. PdfDictionary pageDict = r.getPageN(i); PdfDictionary resDict = (PdfDictionary) pageDict.get(PdfName.RESOURCES); boolean noFontsOrImages = true; if (resDict != null) { noFontsOrImages = resDict.get(PdfName.FONT) == null && resDict.get(PdfName.XOBJECT) == null; } if (!noFontsOrImages) { byte bContent[] = r.getPageContent(i, raf); ByteArrayOutputStream bs = new ByteArrayOutputStream(); bs.write(bContent); if (bs.size() > BLANK_THRESHOLD) { page = writer.getImportedPage(r, i); writer.addPage(page); } } } } finally { if (document != null) { document.close(); } if (writer != null) { writer.close(); } if (raf != null) { raf.close(); } if (r != null) { r.close(); } } }
From source file:com.bougsid.printers.PrintMission.java
public void printMission(Mission mission) { Document document = new Document(PageSize.A4); try {/* w w w .j av a2 s .c o m*/ File downloadDir = new File(msg.getMessage("application.mission.downloaddir")); if (!downloadDir.exists()) { downloadDir.mkdir(); } System.out.println("Dir =" + downloadDir.getPath()); PdfWriter.getInstance(document, new FileOutputStream(downloadDir.getPath() + "/" + mission.getUuid() + ".pdf")); document.open(); Paragraph p = new Paragraph(); p.setSpacingAfter(60); document.add(p); //header Paragraph paragraph = new Paragraph( msg.getMessage("mission.pdf.school") + " " + mission.getIdMission() + " ", DEFAULT_FONT); Phrase phrase = new Phrase(msg.getMessage("mission.pdf.city") + " " + LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); paragraph.add(phrase); paragraph.setSpacingAfter(50); document.add(paragraph); //title PdfPTable table = new PdfPTable(1); table.setWidthPercentage(40); PdfPCell cell = new PdfPCell(new Phrase(msg.getMessage("mission.pdf.title"), FontFactory.getFont(FontFactory.HELVETICA, 18))); cell.setBorderWidth(1); cell.setPadding(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setSpacingAfter(40); document.add(table); //content table = new PdfPTable(2); table.setWidthPercentage(100); //line 1 cell = new PdfPCell(new Paragraph(mission.getEmploye().getCivilite().getLabel(), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFullName(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 2 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.matricule"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getMatricule(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 3 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.grade"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(": " + mission.getEmploye().getFonction(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); if (mission.getEntreprise() != null) { //line 4 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.text_1_2"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 5 cell = new PdfPCell(new Paragraph(" ", DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph(" - " + mission.getEntreprise().getNom(), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); } //line 6 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.lieu"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); p = new Paragraph(); p.setFont(DEFAULT_FONT); for (Ville ville : mission.getVilles()) { p.add(ville.getNom() + "\n"); } cell = new PdfPCell(p); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 7 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.startdate"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph( ": " + mission.getStartDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + " Heure : " + mission.getStartDate().format(DateTimeFormatter.ofPattern("HH:mm")), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 8 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.enddate"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); cell = new PdfPCell(new Paragraph( ": " + mission.getEndDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + " Heure : " + mission.getEndDate().format(DateTimeFormatter.ofPattern("HH:mm")), DEFAULT_FONT)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); //line 9 cell = new PdfPCell(new Paragraph(msg.getMessage("mission.pdf.transport"), DEFAULT_FONT_BOLD)); cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); switch (mission.getTransportType()) { case PERSONNEL: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.perso") + " " + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; case Accompagnement: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.accomp") + " " + mission.getAccompEmploye().getCivilite() + " " + mission.getAccompEmploye().getFullName() + " " + msg.getMessage("mission.pdf.accomp.voitue") + " " + mission.getAccompEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getAccompEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; case Service: cell = new PdfPCell(new Paragraph(": " + msg.getMessage("mission.pdf.service") + " " + mission.getEmploye().getVehicule().getMarque() + " " + msg.getMessage("mission.pdf.mat") + " " + mission.getEmploye().getVehicule().getMatricule() + " ", DEFAULT_FONT)); break; default: { cell = new PdfPCell(new Paragraph( ": " + mission.getTransportType().getLabel() + " " + msg.getMessage("mission.pdf.taxi"), DEFAULT_FONT)); } } cell.setBorder(Rectangle.NO_BORDER); cell.setPaddingTop(20); table.addCell(cell); table.setSpacingAfter(40); document.add(table); //note document.add(new Paragraph(msg.getMessage("mission.pdf.TEXT_2"), DEFAULT_FONT)); //signature if (mission.getEmploye().getGrade().getType() == GradeType.DG) { } else { Employe dir = employeService.getDG(); if (dir != null) paragraph = new Paragraph(dir.getFullName(), DEFAULT_FONT); paragraph.setAlignment(Element.ALIGN_RIGHT); paragraph.setSpacingBefore(40); document.add(paragraph); paragraph = new Paragraph(msg.getMessage("mission.pdf.DG"), DEFAULT_FONT); paragraph.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph); } } catch (DocumentException ex) { ex.printStackTrace(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } document.close(); // try { // Desktop.getDesktop().open(new File("./order.pdf")); // } catch (IOException ex) { // JOptionPane.showMessageDialog(null, "Fichier gner mais ne peut pas etre ouvert vrifier le dossier"); // } }
From source file:com.cib.statementstamper.windows.StatementStamperMainWindow.java
License:Open Source License
protected ByteArrayOutputStream doStamper(ByteArrayOutputStream baos) throws IOException, DocumentException { map.clear();//from w ww . j ava2 s. c om ByteArrayOutputStream baosFinal = new ByteArrayOutputStream(); PdfReader reader = new PdfReader(baos.toByteArray()); PdfContentStreamProcessor processor = new PdfContentStreamProcessor(this); for (int i = 1; i <= reader.getNumberOfPages(); i++) { actualPage = i; PdfDictionary pageDic = reader.getPageN(i); PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES); processor.processContent(ContentByteUtils.getContentBytesForPage(reader, i), resourcesDic); } Document newDocument = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(newDocument, baosFinal); newDocument.open(); PdfContentByte canvas = writer.getDirectContent(); // Font myFont = FontFactory.getFont(FontFactory.COURIER, 7, Font.BOLD); Iterator<Entry<Integer, Map<Float, StringBuffer>>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Integer, Map<Float, StringBuffer>> pairs = (Map.Entry<Integer, Map<Float, StringBuffer>>) it .next(); Iterator<Entry<Float, StringBuffer>> iter = pairs.getValue().entrySet().iterator(); while (iter.hasNext()) { Map.Entry<Float, StringBuffer> actualEntry = iter.next(); canvas.beginText(); canvas.setFontAndSize(myFontBase, 7); canvas.showTextAligned(Element.ALIGN_LEFT, actualEntry.getValue().toString(), 25, actualEntry.getKey() + 60, 0); canvas.endText(); } newDocument.newPage(); } newDocument.close(); reader = new PdfReader(baosFinal.toByteArray()); PdfReaderContentParser parser = new PdfReaderContentParser(reader); TextMarginFinder finder; for (int i = 1; i <= reader.getNumberOfPages(); i++) { finder = parser.processContent(i, new TextMarginFinder()); if (finder.getLly() <= 68) { getWindow().showNotification("Hiba", "A(z) " + i + ".ik oldalon tl sok a szveg !!!", Notification.TYPE_ERROR_MESSAGE); return null; } } reader = new PdfReader(baosFinal.toByteArray()); PdfStamper stamper = new PdfStamper(reader, baosFinal); int n = reader.getNumberOfPages(); for (int i = 1; i <= n; i++) { PdfContentByte overContent = stamper.getOverContent(i); overContent.addImage(logo, 131, 0, 0, 32, 44, 775); getFooterTable(i, n).writeSelectedRows(0, -1, 27, 68, stamper.getOverContent(i)); // ez a jo getIspLogoTable(i, n).writeSelectedRows(0, -1, 425, 45, stamper.getOverContent(i)); } stamper.close(); reader.close(); return baosFinal; }
From source file:com.coderbd.pos.pdf.BarcodePdf.java
public void generateBarcodePdf(int amount) throws UnsupportedEncodingException { try {/* w w w . j av a 2 s. c o m*/ String filename = directory + "\\" + barcodeData + ".pdf"; Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte cb = writer.getDirectContent(); Barcode128 code25 = new Barcode128(); code25.setGenerateChecksum(true); code25.setCode(barcodeData); code25.setSize(10f); code25.setX(1.50f); PdfPTable pdfPTable = new PdfPTable(3); float[] widths = { 0.45f, .10f, .45f }; pdfPTable.setWidths(widths); String codeName = getCodeName(shop.getShopName(), shop.getShopId(), amount); System.out.println("BarCodeName:" + codeName); Image image = code25.createImageWithBarcode(cb, null, null); Paragraph paragraph = new Paragraph(codeName); paragraph.setSpacingBefore(10.0f); PdfPCell title = new PdfPCell(paragraph); title.setBorder(Rectangle.NO_BORDER); PdfPCell barcodeCell = new PdfPCell(image, true); barcodeCell.setBorder(Rectangle.NO_BORDER); PdfPCell blank = new PdfPCell(); blank.setBorder(Rectangle.NO_BORDER); Paragraph blankParagraph = new Paragraph("- -"); PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph); pdfPCellBlank.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < barcodeQuantity; i++) { /** * This is for barcode pdf title */ pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); /** * This is for barcode image */ pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); /** * Blank space after barcode image */ pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); } document.add(pdfPTable); document.close(); } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); } }
From source file:com.coderbd.pos.pdf.BarcodePdf.java
public void generateBarcodePdf(boolean fixedRate, Product p) throws UnsupportedEncodingException { try {// www . ja va2 s . c om String filename = directory + "\\" + barcodeData + ".pdf"; Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte cb = writer.getDirectContent(); Barcode128 code25 = new Barcode128(); code25.setGenerateChecksum(true); code25.setCode(barcodeData); code25.setSize(10f); code25.setX(1.50f); PdfPTable pdfPTable = new PdfPTable(3); float[] widths = { 0.45f, .10f, .45f }; pdfPTable.setWidths(widths); String codeName = getCodeName(shop.getShopName(), shop.getShopId(), (int) p.getProductBuyRate()); System.out.println("BarCodeName:" + codeName); Image image = code25.createImageWithBarcode(cb, null, null); Paragraph paragraph = new Paragraph(codeName); paragraph.setSpacingBefore(10.0f); PdfPCell title = new PdfPCell(paragraph); title.setBorder(Rectangle.NO_BORDER); PdfPCell barcodeCell = new PdfPCell(image, true); barcodeCell.setBorder(Rectangle.NO_BORDER); PdfPCell blank = new PdfPCell(); blank.setBorder(Rectangle.NO_BORDER); Paragraph blankParagraph = new Paragraph("- -"); PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph); pdfPCellBlank.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < barcodeQuantity; i++) { /** * This is for barcode pdf title */ pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); /** * This is for barcode image */ pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); /** * Blank space after barcode image */ pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); } document.add(pdfPTable); document.close(); } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); } }
From source file:com.coderbd.pos.pdf.CodePDF.java
public boolean genCodeVer2Pdf() throws UnsupportedEncodingException { if (isFixedRated == true) { barcodeQuantity = 12;//from w ww . ja v a 2 s . c o m } else { barcodeQuantity = 15; } try { String filename = ""; if (isFixedRated) { filename = directory + "\\" + product.getProductBarcode() + "_FIXED_TK" + ".pdf"; } else { filename = directory + "\\" + product.getProductBarcode() + ".pdf"; } Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); PdfContentByte cb = writer.getDirectContent(); Barcode128 code25 = new Barcode128(); code25.setGenerateChecksum(true); code25.setCode(product.getProductBarcode()); code25.setSize(10f); code25.setX(1.50f); PdfPTable pdfPTable = new PdfPTable(7); pdfPTable.setWidthPercentage(98); float[] widths = { 0.22f, 0.04f, 0.22f, 0.04f, 0.22f, 0.04f, 0.22f }; pdfPTable.setWidths(widths); String codeName = getCodeName(product.getShop().getShopName(), product.getShop().getShopId(), (int) product.getProductBuyRate()); System.out.println("BarCodeName:" + codeName); Image image = code25.createImageWithBarcode(cb, null, null); Font titleArialFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.NORMAL); Font priceFont = FontFactory.getFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, 8, Font.BOLD); Paragraph paragraph = new Paragraph(codeName, titleArialFont); paragraph.setSpacingBefore(10.0f); PdfPCell title = new PdfPCell(paragraph); title.setBorder(Rectangle.NO_BORDER); Paragraph fixedTKParagraph = new Paragraph("FIXED TK: " + product.getProductSellRate(), priceFont); PdfPCell fixedRateCell = new PdfPCell(fixedTKParagraph); fixedRateCell.setBorder(Rectangle.NO_BORDER); PdfPCell barcodeCell = new PdfPCell(image, true); barcodeCell.setBorder(Rectangle.NO_BORDER); PdfPCell blank = new PdfPCell(); blank.setBorder(Rectangle.NO_BORDER); Paragraph blankParagraph = new Paragraph("- -"); PdfPCell pdfPCellBlank = new PdfPCell(blankParagraph); pdfPCellBlank.setBorder(Rectangle.NO_BORDER); for (int i = 0; i < barcodeQuantity; i++) { /** * This is for barcode pdf title */ pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); pdfPTable.addCell(blank); pdfPTable.addCell(title); /** * This is for barcode image */ pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); pdfPTable.addCell(blank); pdfPTable.addCell(barcodeCell); /** * */ if (isFixedRated == true) { pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); pdfPTable.addCell(blank); pdfPTable.addCell(fixedRateCell); } /** * Blank space after barcode image */ pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); pdfPTable.addCell(blank); pdfPTable.addCell(pdfPCellBlank); } document.add(pdfPTable); document.add(new Paragraph( "Shop Name: " + product.getShop().getShopName() + ", Name:" + product.getProductName() + "\n,Qty: " + product.getProductStock() + ", " + new Date().toString(), titleArialFont)); document.close(); return true; } catch (DocumentException | FileNotFoundException dex) { System.out.println(dex.getMessage()); return false; } }
From source file:com.coderbd.pos.pdf.OrderFileBuilder.java
public String makePdf(ShopOrder shopOrder) { Document document = new Document(new Rectangle(205, 800)); String fileName = directory + "\\" + shopOrder.getCustomerOrder().getOrderBarcode() + ".pdf"; String receiptText = receipt.getIndentedOrder(shopOrder); System.out.println(receiptText); document.setMargins(3, 2, 2, 2);/* w ww .j a va 2s . c o m*/ Font courierFont = FontFactory.getFont("courier"); courierFont.setSize(10f); try { PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); document.add(new Paragraph(receiptText, courierFont)); document.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } return fileName; }