List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell
public PdfPCell()
PdfPCell
. From source file:com.pureinfo.srm.patent.action.PatentPrintPdfAction.java
License:Open Source License
/** * @see com.pureinfo.ark.interaction.ActionBase#executeAction() *///from w ww .ja va2 s . c o m public ActionForward executeAction() throws PureException { int nYear = request.getRequiredInt("year", ""); Rectangle rectPageSize = new Rectangle(PageSize.A4); rectPageSize.setBackgroundColor(Color.WHITE); rectPageSize.setBorderColor(Color.BLACK); rectPageSize = rectPageSize.rotate(); Document doc = new Document(rectPageSize, 10, 10, 10, 10); doc.addTitle(nYear + ""); doc.addAuthor("PureInfo"); try { BaseFont bfontTitle = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font fontTitle = new Font(bfontTitle, 18, Font.NORMAL); Paragraph paraTitle = new Paragraph(nYear + "", fontTitle); paraTitle.setAlignment(ElementTags.ALIGN_CENTER); BaseFont bfontContent = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font fontContent = new Font(bfontContent, 10, Font.NORMAL); FileFactory fileFactory = FileFactory.getInstance(); String sPath = fileFactory.lookupPathConfigByFlag(FileFactory.FLAG_DOWNLOADTEMP, true).getLocalPath(); FileUtil.insurePathExists(sPath); PdfWriter.getInstance(doc, new FileOutputStream(new File(sPath, "patent.pdf"))); doc.open(); doc.add(paraTitle); doc.add(new Paragraph(" ")); String[] arrTitles = new String[] { "", "", "", "", "", "", "", "", "" }; PdfPTable pTable = new PdfPTable(arrTitles.length); pTable.setWidths(new int[] { 5, 10, 9, 9, 20, 15, 12, 10, 10 }); for (int i = 0; i < arrTitles.length; i++) { PdfPCell pCell = new PdfPCell(); Paragraph para = new Paragraph(arrTitles[i], fontContent); para.setAlignment(ElementTags.ALIGN_CENTER); pCell.addElement(para); pTable.addCell(pCell); } /** * */ IPatentMgr mgr = (IPatentMgr) ArkContentHelper.getContentMgrOf(Patent.class); List patents = mgr.findAllAuthorizedOf(nYear); int i = 0; for (Iterator iter = patents.iterator(); iter.hasNext(); i++) { Patent patent = (Patent) iter.next(); this.addPatentCell(pTable, String.valueOf(i + 1), fontContent); this.addPatentCell(pTable, patent.getPatentSid(), fontContent); this.addPatentCell(pTable, ForceConstants.DATE_FORMAT.format(patent.getApplyDate()), fontContent); this.addPatentCell(pTable, patent.getWarrantDate() == null ? "" : ForceConstants.DATE_FORMAT.format(patent.getWarrantDate()), fontContent); this.addPatentCell(pTable, patent.getName(), fontContent); this.addPatentCell(pTable, patent.getAllAuthosName(), fontContent); this.addPatentCell(pTable, patent.getRightPerson(), fontContent); this.addPatentCell(pTable, getCollegeName(patent), fontContent); this.addPatentCell(pTable, patent.getPatentTypeName(), fontContent); } doc.add(pTable); doc.close(); } catch (DocumentException ex) { // TODO Auto-generated catch block ex.printStackTrace(System.err); } catch (IOException ex) { // TODO Auto-generated catch block ex.printStackTrace(System.err); } List list = new ArrayList(); list.add(new Pair("/download/patent.pdf", "")); request.setAttribute("forward", list); return mapping.findForward("success"); }
From source file:com.pureinfo.srm.patent.action.PatentPrintPdfAction.java
License:Open Source License
private void addPatentCell(PdfPTable _pTable, String _sValue, Font _font) { PdfPCell pCell = new PdfPCell(); Paragraph para = new Paragraph(_sValue, _font); para.setAlignment(Align.CENTER);/*from w w w. j a va 2s.c om*/ pCell.addElement(para); _pTable.addCell(pCell); // return _pTable; }
From source file:com.qcadoo.mes.orders.print.OrderReportPdf.java
License:Open Source License
private PdfPCell createCell(String content, int alignment) { PdfPCell cell = new PdfPCell(); float border = 0.2f; cell.setPhrase(new Phrase(content, FontUtils.getDejavuRegular7Dark())); cell.setHorizontalAlignment(alignment); cell.setBorderWidth(border);//w ww . j a v a 2 s .c o m cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.setPadding(5); return cell; }
From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java
License:Open Source License
private void addWorkPlanTitle(Document document, Entity workPlan, String title, Locale locale) throws DocumentException { PdfPTable headerTable = pdfHelper.createPanelTable(2); PdfPCell titleCell = new PdfPCell(); titleCell.setBorder(Rectangle.NO_BORDER); Paragraph workPlanTitle = new Paragraph( new Phrase(getWorkPlanTitle(locale), FontUtils.getDejavuBold11Light())); workPlanTitle.add(new Phrase(" " + getWorkPlanName(workPlan), FontUtils.getDejavuBold11Dark())); titleCell.addElement(workPlanTitle); PdfPCell divisionCell = new PdfPCell(); divisionCell.setBorder(Rectangle.NO_BORDER); Paragraph divisionTitle = new Paragraph( new Phrase(getDivisionTitle(locale), FontUtils.getDejavuBold11Light())); divisionTitle.add(new Phrase(" " + getDivisionFromTitle(title, locale), FontUtils.getDejavuBold11Dark())); divisionTitle.setAlignment(Element.ALIGN_RIGHT); divisionCell.addElement(divisionTitle); headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headerTable.setTableEvent(null);//from w w w .ja v a 2s . c o m headerTable.setSpacingAfter(4.0f); headerTable.addCell(titleCell); headerTable.addCell(divisionCell); document.add(headerTable); }
From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java
License:Open Source License
private void addOperationTable(PdfWriter pdfWriter, GroupingContainer groupingContainer, Document document, OrderOperationComponent orderOperationComponent, Locale locale) throws DocumentException { Map<Long, Map<OperationProductColumn, ColumnAlignment>> outputProductsMap = groupingContainer .getOperationComponentIdProductOutColumnToAlignment(); Map<Long, Map<OperationProductColumn, ColumnAlignment>> inputProductsMap = groupingContainer .getOperationComponentIdProductInColumnToAlignment(); Entity operationComponent = orderOperationComponent.getOperationComponent(); Entity order = orderOperationComponent.getOrder(); Entity product = order.getBelongsToField(OrderFields.PRODUCT); Map<OperationProductColumn, ColumnAlignment> inputProductColumnAlignmentMap = inputProductsMap .get(operationComponent.getId()); Map<OperationProductColumn, ColumnAlignment> outputProductColumnAlignmentMap = outputProductsMap .get(operationComponent.getId()); PdfPTable table = pdfHelper.createPanelTable(3); PdfPCell headerCell = new PdfPCell(); headerCell.setBorder(Rectangle.NO_BORDER); headerCell.setColspan(2);//from www . ja v a2 s. com PdfPCell inputCell = new PdfPCell(); inputCell.setBorder(Rectangle.NO_BORDER); PdfPCell outputCell = new PdfPCell(); outputCell.setBorder(Rectangle.NO_BORDER); PdfPCell codeCell = new PdfPCell(); codeCell.setBorder(Rectangle.NO_BORDER); codeCell.setHorizontalAlignment(Element.ALIGN_CENTER); codeCell.setVerticalAlignment(Element.ALIGN_TOP); codeCell.setRowspan(2); // addOperationSummary(headerCell, operationComponent); addOrderSummary(headerCell, order, product, operationComponent); addOperationProductsTable(inputCell, operationProductInComponents(operationComponent, order), inputProductColumnAlignmentMap, ProductDirection.IN, locale); addOperationProductsTable(outputCell, operationProductOutComponents(operationComponent, order), outputProductColumnAlignmentMap, ProductDirection.OUT, locale); codeCell.addElement(createBarcode(pdfWriter, operationComponent)); float[] tableColumnWidths = new float[] { 70f, 70f, 10f }; table.setWidths(tableColumnWidths); table.setTableEvent(null); table.addCell(headerCell); table.addCell(codeCell); table.addCell(inputCell); table.addCell(outputCell); table.setKeepTogether(true); document.add(table); }
From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java
License:Open Source License
private void addOperationSummary(PdfPCell cell, Entity operationComponent) throws DocumentException { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); PdfPTable operationTable = pdfHelper.createPanelTable(1); PdfPCell numberCell = new PdfPCell(); numberCell.setBorder(Rectangle.NO_BORDER); Paragraph operationName = new Paragraph(operation.getStringField(OperationFields.NUMBER) + " - " + operation.getStringField(OperationFields.NAME), FontUtils.getDejavuBold7Dark()); numberCell.addElement(operationName); PdfPCell descriptionCell = new PdfPCell(); descriptionCell.setBorder(Rectangle.NO_BORDER); String comment = operation.getStringField(OperationFields.COMMENT); Paragraph description = null;/*from w w w. j a v a 2 s . com*/ if (!StringUtils.isEmpty(comment)) { description = new Paragraph(comment, FontUtils.getDejavuBold7Dark()); } operationTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); operationTable.setTableEvent(null); operationTable.addCell(numberCell); if (description != null) { descriptionCell.addElement(description); operationTable.addCell(descriptionCell); } else { operationTable.addCell(""); } cell.addElement(operationTable); }
From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java
License:Open Source License
private void addOrderSummary(PdfPCell cell, Entity order, Entity product, Entity operationComponent) throws DocumentException { Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION); PdfPTable orderTable = pdfHelper.createPanelTable(3); PdfPCell operationCell = new PdfPCell(); operationCell.setBorder(Rectangle.NO_BORDER); Paragraph operationName = new Paragraph(operation.getStringField(OperationFields.NUMBER) + " - " + operation.getStringField(OperationFields.NAME), FontUtils.getDejavuBold7Dark()); operationCell.addElement(operationName); PdfPCell numberCell = new PdfPCell(); numberCell.setBorder(Rectangle.NO_BORDER); Paragraph number = new Paragraph(order.getStringField(OrderFields.NUMBER), FontUtils.getDejavuBold7Dark()); number.setAlignment(Element.ALIGN_RIGHT); numberCell.addElement(number);/* w ww. j av a2 s . c o m*/ PdfPCell quantityCell = new PdfPCell(); quantityCell.setBorder(Rectangle.NO_BORDER); Paragraph quantity = new Paragraph( numberService.formatWithMinimumFractionDigits(order.getDecimalField(OrderFields.PLANNED_QUANTITY), 0) + " " + product.getStringField(ProductFields.UNIT), FontUtils.getDejavuBold7Dark()); quantity.setAlignment(Element.ALIGN_CENTER); quantityCell.addElement(quantity); PdfPCell descriptionCell = new PdfPCell(); descriptionCell.setBorder(Rectangle.NO_BORDER); descriptionCell.setColspan(3); String comment = operationComponent.getStringField(TechnologyOperationComponentFields.COMMENT); Paragraph description = null; if (!StringUtils.isEmpty(comment)) { description = new Paragraph(comment, FontUtils.getDejavuBold7Dark()); } float[] tableColumnWidths = new float[] { 160f, 30f, 10f }; orderTable.setWidths(tableColumnWidths); orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); orderTable.setTableEvent(null); orderTable.addCell(operationCell); orderTable.addCell(numberCell); orderTable.addCell(quantityCell); if (description != null) { descriptionCell.addElement(description); orderTable.addCell(descriptionCell); } cell.addElement(orderTable); }
From source file:de.ipbhalle.metfrag.tools.renderer.WritePDFTable.java
License:Open Source License
/** * Instantiates a new write pdf table. This is mainly for debugging the gasteiger marsili charges * // w w w. j a va 2 s.c o m * @param odir the odir * @param width the width * @param height the height * @param chargeResults the charge results */ public WritePDFTable(String odir, int width, int height, List<ChargeResult> chargeResults) { this.width = width; this.height = height; try { File file = new File(odir); document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); float[] widths = new float[ncol]; for (int i = 0; i < ncol; i += 3) { widths[i] = 2.5f; widths[i + 1] = 0.75f; widths[i + 2] = 0.75f; } table = new PdfPTable(widths); document.open(); boolean drawPartialCharges = true; for (ChargeResult result : chargeResults) { if (drawPartialCharges) { PdfPCell cellBonds = new PdfPCell(); PdfPCell cellBondsDist = new PdfPCell(); Phrase phraseBonds = new Phrase(); Phrase phraseBondsDist = new Phrase(); com.lowagie.text.Image image = com.lowagie.text.Image .getInstance(writeMOL2PNGFile(result.getOriginalMol()).getAbsolutePath()); image.setAbsolutePosition(0, 0); table.addCell(image); String stringAtoms = ""; String stringAtomsCharge = ""; for (IAtom atom : result.getOriginalMol().atoms()) { if (!atom.getSymbol().equals("H") && !atom.getSymbol().equals("C")) { stringAtoms += atom.getSymbol() + (Integer.parseInt(atom.getID()) + 1) + "\n"; stringAtomsCharge += Math.round(atom.getCharge() * 100.0) / 100.0 + "\n"; } } addProperty(phraseBonds, stringAtoms); addProperty(phraseBondsDist, stringAtomsCharge); cellBonds.addElement(phraseBonds); cellBondsDist.addElement(phraseBondsDist); table.addCell(cellBonds); table.addCell(cellBondsDist); drawPartialCharges = false; } PdfPCell cellBonds = new PdfPCell(); PdfPCell cellBondsDist = new PdfPCell(); Phrase phraseBonds = new Phrase(); Phrase phraseBondsDist = new Phrase(); com.lowagie.text.Image image = com.lowagie.text.Image.getInstance( writeMOL2PNGFile(result.getOriginalMol(), result.getMolWithProton()).getAbsolutePath()); image.setAbsolutePosition(0, 0); table.addCell(image); String stringPDFBonds = ""; String stringPDFBondsDist = ""; String[] lines = result.getChargeString().split("\n"); for (int i = 0; i < lines.length; i++) { boolean carbonHydrogenBond = lines[i].matches("[A-Z]+[0-9]+-H[0-9]+.*"); if (!carbonHydrogenBond) { String[] linesArr = lines[i].split("\t"); stringPDFBondsDist += linesArr[1] + "\n"; stringPDFBonds += linesArr[0] + "\n"; } } addProperty(phraseBonds, stringPDFBonds); addProperty(phraseBondsDist, stringPDFBondsDist); cellBonds.addElement(phraseBonds); cellBondsDist.addElement(phraseBondsDist); table.addCell(cellBonds); table.addCell(cellBondsDist); } document.add(table); document.close(); } catch (Exception exc) { exc.printStackTrace(); } }
From source file:edu.harvard.mcz.imagecapture.encoder.LabelEncoder.java
License:Open Source License
@SuppressWarnings("hiding") public static boolean printList(List<UnitTrayLabel> taxa) throws PrintFailedException { boolean result = false; UnitTrayLabel label = new UnitTrayLabel(); LabelEncoder encoder = new LabelEncoder(label); Image image = encoder.getImage(); int counter = 0; try {/*from w w w. jav a 2 s . com*/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("labels.pdf")); document.setPageSize(PageSize.LETTER); document.open(); PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100f); //table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); float[] cellWidths = { 30f, 20f, 30f, 20f }; table.setWidths(cellWidths); UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle(); if (taxa == null) { taxa = uls.findAll(); } Iterator<UnitTrayLabel> i = taxa.iterator(); PdfPCell cell = null; PdfPCell cell_barcode = null; // Create two lists of 12 cells, the first 6 of each representing // the left hand column of 6 labels, the second 6 of each // representing the right hand column. // cells holds the text for each label, cells_barcode the barcode. ArrayList<PdfPCell> cells = new ArrayList<PdfPCell>(12); ArrayList<PdfPCell> cells_barcode = new ArrayList<PdfPCell>(12); for (int x = 0; x < 12; x++) { cells.add(null); cells_barcode.add(null); } int cellCounter = 0; while (i.hasNext()) { // Loop through all of the taxa (unit tray labels) found to print label = i.next(); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { // For each taxon, loop through the number of requested copies // Generate a text and a barcode cell for each, and add to array for page log.debug("Label " + toPrint + " of " + label.getNumberToPrint()); cell = new PdfPCell(); cell.setBorderColor(Color.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.disableBorderSide(PdfPCell.RIGHT); cell.setPaddingLeft(3); String higherNames = ""; if (label.getTribe().trim().length() > 0) { higherNames = label.getFamily() + ": " + label.getSubfamily() + ": " + label.getTribe(); } else { higherNames = label.getFamily() + ": " + label.getSubfamily(); } Paragraph higher = new Paragraph(); higher.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); higher.add(new Chunk(higherNames)); cell.addElement(higher); Paragraph name = new Paragraph(); Chunk genus = new Chunk(label.getGenus().trim() + " "); genus.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); Chunk species = new Chunk(label.getSpecificEpithet().trim()); Chunk normal = null; // normal font prefix to preceed specific epithet (nr. <i>epithet</i>) if (label.getSpecificEpithet().contains(".") || label.getSpecificEpithet().contains("[")) { if (label.getSpecificEpithet().startsWith("nr. ")) { normal = new Chunk("nr. "); normal.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); species = new Chunk(label.getSpecificEpithet().trim().substring(4)); species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } else { species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); } } else { species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } String s = ""; if (label.getSubspecificEpithet().trim().length() > 0) { s = " "; } else { s = ""; } Chunk subspecies = new Chunk(s + label.getSubspecificEpithet().trim()); if (label.getSubspecificEpithet().contains(".") || label.getSubspecificEpithet().contains("[")) { subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); } else { subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } if (label.getInfraspecificRank().trim().length() > 0) { s = " "; } else { s = ""; } Chunk infraRank = new Chunk(s + label.getInfraspecificRank().trim()); infraRank.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); if (label.getInfraspecificEpithet().trim().length() > 0) { s = " "; } else { s = ""; } Chunk infra = new Chunk(s + label.getInfraspecificEpithet().trim()); infra.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); if (label.getUnNamedForm().trim().length() > 0) { s = " "; } else { s = ""; } Chunk unNamed = new Chunk(s + label.getUnNamedForm().trim()); unNamed.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); name.add(genus); if (normal != null) { name.add(normal); } name.add(species); name.add(subspecies); name.add(infraRank); name.add(infra); name.add(unNamed); cell.addElement(name); Paragraph authorship = new Paragraph(); authorship.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); if (label.getAuthorship() != null && label.getAuthorship().length() > 0) { Chunk c_authorship = new Chunk(label.getAuthorship()); authorship.add(c_authorship); } cell.addElement(authorship); //cell.addElement(new Paragraph(" ")); if (label.getDrawerNumber() != null && label.getDrawerNumber().length() > 0) { Paragraph drawerNumber = new Paragraph(); drawerNumber.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); Chunk c_drawerNumber = new Chunk(label.getDrawerNumber()); drawerNumber.add(c_drawerNumber); cell.addElement(drawerNumber); } else { if (label.getCollection() != null && label.getCollection().length() > 0) { Paragraph collection = new Paragraph(); collection.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); Chunk c_collection = new Chunk(label.getCollection()); collection.add(c_collection); cell.addElement(collection); } } cell_barcode = new PdfPCell(); cell_barcode.setBorderColor(Color.LIGHT_GRAY); cell_barcode.disableBorderSide(PdfPCell.LEFT); cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP); encoder = new LabelEncoder(label); image = encoder.getImage(); image.setAlignment(Image.ALIGN_TOP); cell_barcode.addElement(image); cells.add(cellCounter, cell); cells_barcode.add(cellCounter, cell_barcode); cellCounter++; // If we have hit a full set of 12 labels, add them to the document // in two columns, filling left column first, then right if (cellCounter == 12) { // add a page of 12 cells in columns of two. for (int x = 0; x < 6; x++) { if (cells.get(x) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x)); table.addCell(cells_barcode.get(x)); } if (cells.get(x + 6) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x + 6)); table.addCell(cells_barcode.get(x + 6)); } } // Reset to begin next page cellCounter = 0; document.add(table); table = new PdfPTable(4); table.setWidthPercentage(100f); table.setWidths(cellWidths); for (int x = 0; x < 12; x++) { cells.set(x, null); cells_barcode.set(x, null); } } } // end loop through toPrint (for a taxon) counter++; } // end while results has next (for all taxa requested) // get any remaining cells in pairs for (int x = 0; x < 6; x++) { if (cells.get(x) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x)); table.addCell(cells_barcode.get(x)); } if (cells.get(x + 6) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x + 6)); table.addCell(cells_barcode.get(x + 6)); } } // add any remaining cells document.add(table); try { document.close(); } catch (Exception e) { throw new PrintFailedException("No labels to print." + e.getMessage()); } // Check to see if there was content in the document. if (counter == 0) { result = false; } else { // Printed to pdf ok. result = true; // Increment number printed. i = taxa.iterator(); while (i.hasNext()) { label = i.next(); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { label.setPrinted(label.getPrinted() + 1); } label.setNumberToPrint(0); try { uls.attachDirty(label); } catch (SaveFailedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new PrintFailedException("File not found."); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new PrintFailedException("Error buiding PDF document."); } catch (OutOfMemoryError e) { System.out.println("Out of memory error. " + e.getMessage()); System.out.println("Failed. Too many labels."); throw new PrintFailedException("Ran out of memory, too many labels at once."); } return result; }
From source file:etc.Exporter.java
License:Open Source License
public static void saveAsPDF(File file, Task task) { try {//w w w .j a va2s . com Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); Paragraph taskid = new Paragraph("ID e Detyres: " + task.getIdentifier(), FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)); document.add(taskid); Paragraph creator = new Paragraph("Krijuar nga " + task.getCreator().toString() + "[" + task.getCreationTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy - HH.mm")) + "]", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)); document.add(creator); Paragraph executor = new Paragraph("Per zbatim prej: " + task.getExecutor().toString(), FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)); document.add(executor); Paragraph title = new Paragraph(task.getTitle().toUpperCase(), FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD)); document.add(title); Paragraph description = new Paragraph(task.getDescription(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL)); document.add(description); PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.BOTTOM); PdfPTable table = new PdfPTable(1); table.addCell(cell); table.setWidthPercentage(100f); document.add(table); if (task instanceof dc.CompletedTask) { document.add(new Paragraph( "Gjendja: Perfunduar [" + ((dc.CompletedTask) task).getCompletitionTime() .format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm")) + "]", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC))); document.add(new Paragraph("Shenimet e Zbatuesit".toUpperCase(), FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD))); document.add(new Paragraph(((dc.CompletedTask) task).getAnnotations(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL))); } else if (task instanceof dc.RejectedTask) { document.add(new Paragraph( "Gjendja: Refuzuar [" + ((dc.RejectedTask) task).getRejectionTime() .format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm")) + "]", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC))); document.add(new Paragraph("Shenimet e Zbatuesit".toUpperCase(), FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD))); document.add(new Paragraph(((dc.RejectedTask) task).getAnnotations(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL))); } else { document.add(new Paragraph("Gjendja: Ne Pritje", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC))); } document.close(); Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file.getAbsolutePath()); p.waitFor(); } catch (DocumentException | InterruptedException | IOException ex) { Logger.getLogger(Exporter.class.getName()).log(Level.SEVERE, null, ex); } }