List of usage examples for com.lowagie.text DocumentException DocumentException
public DocumentException(String message)
DocumentException
with a message. From source file:org.eclipse.birt.report.engine.emitter.postscript.truetypefont.TrueTypeFont.java
License:Open Source License
/** * Reads the glyphs widths. The widths are extracted from the table 'hmtx'. * The glyphs are normalized to 1000 units. * //from w w w .j av a 2 s .c o m * @throws DocumentException * the font is invalid * @throws IOException * the font file could not be read */ protected void readGlyphWidths() throws DocumentException, IOException { int table_location[]; table_location = (int[]) positionTables.get("hmtx"); if (table_location == null) throw new DocumentException("Table 'hmtx' does not exist in " + fileName + style); rf.seek(table_location[0]); GlyphWidths = new int[hhea.numberOfHMetrics]; for (int k = 0; k < hhea.numberOfHMetrics; ++k) { GlyphWidths[k] = (rf.readUnsignedShort() * 1000) / head.unitsPerEm; rf.readUnsignedShort(); } }
From source file:org.eclipse.birt.report.engine.emitter.postscript.truetypefont.TrueTypeFont.java
License:Open Source License
private void readBbox() throws DocumentException, IOException { int tableLocation[]; tableLocation = (int[]) positionTables.get("head"); if (tableLocation == null) throw new DocumentException("Table 'head' does not exist in " + fileName + style); rf.seek(tableLocation[0] + HEAD_LOCA_FORMAT_OFFSET); boolean locaShortTable = (rf.readUnsignedShort() == 0); tableLocation = (int[]) positionTables.get("loca"); if (tableLocation == null) return;/*w w w . j ava 2 s . c o m*/ rf.seek(tableLocation[0]); int locaTable[]; if (locaShortTable) { int entries = tableLocation[1] / 2; locaTable = new int[entries]; for (int k = 0; k < entries; ++k) locaTable[k] = rf.readUnsignedShort() * 2; } else { int entries = tableLocation[1] / 4; locaTable = new int[entries]; for (int k = 0; k < entries; ++k) locaTable[k] = rf.readInt(); } tableLocation = (int[]) positionTables.get("glyf"); if (tableLocation == null) throw new DocumentException("Table 'glyf' does not exist in " + fileName + style); int tableGlyphOffset = tableLocation[0]; bboxes = new int[locaTable.length - 1][]; for (int glyph = 0; glyph < locaTable.length - 1; ++glyph) { int start = locaTable[glyph]; if (start != locaTable[glyph + 1]) { rf.seek(tableGlyphOffset + start + 2); bboxes[glyph] = new int[] { (rf.readShort() * 1000) / head.unitsPerEm, (rf.readShort() * 1000) / head.unitsPerEm, (rf.readShort() * 1000) / head.unitsPerEm, (rf.readShort() * 1000) / head.unitsPerEm }; } } }
From source file:org.eclipse.birt.report.engine.emitter.postscript.truetypefont.TrueTypeFont.java
License:Open Source License
/** * Reads the several maps from the table 'cmap'. The maps of interest are * 1.0 for symbolic fonts and 3.1 for all others. A symbolic font is defined * as having the map 3.0./*from w w w .j a v a2s .co m*/ * * @throws DocumentException * the font is invalid * @throws IOException * the font file could not be read */ public void readCMaps() throws DocumentException, IOException { int table_location[]; table_location = (int[]) positionTables.get("cmap"); if (table_location == null) throw new DocumentException("Table 'cmap' does not exist in " + fileName + style); rf.seek(table_location[0]); rf.skipBytes(2); int num_tables = rf.readUnsignedShort(); fontSpecific = false; int map10 = 0; int map31 = 0; int map30 = 0; for (int k = 0; k < num_tables; ++k) { int platId = rf.readUnsignedShort(); int platSpecId = rf.readUnsignedShort(); int offset = rf.readInt(); if (platId == 3 && platSpecId == 0) { fontSpecific = true; map30 = offset; } else if (platId == 3 && platSpecId == 1) { map31 = offset; } if (platId == 1 && platSpecId == 0) { map10 = offset; } } if (map10 > 0) { rf.seek(table_location[0] + map10); int format = rf.readUnsignedShort(); switch (format) { case 0: cmap10 = readFormat0(); break; case 4: cmap10 = readFormat4(); break; case 6: cmap10 = readFormat6(); break; } } if (map31 > 0) { rf.seek(table_location[0] + map31); int format = rf.readUnsignedShort(); if (format == 4) { cmap31 = readFormat4(); } } if (map30 > 0) { rf.seek(table_location[0] + map30); int format = rf.readUnsignedShort(); if (format == 4) { cmap10 = readFormat4(); } } }
From source file:org.egov.works.web.actions.measurementbook.MeasurementBookPDFGenerator.java
License:Open Source License
private PdfPTable createApprovalDetailsTable(final MBHeader mbHeader) throws DocumentException { try {/*ww w . j av a 2s . c o m*/ final PdfPTable approvaldetailsTable = new PdfPTable(5); approvaldetailsTable.setWidthPercentage(100); approvaldetailsTable.setWidths(new float[] { 2f, 1f, 1f, 1.5f, 2f }); addRow(approvaldetailsTable, true, makePara(8, pdfLabel.get("mbpdf.aprvalstep")), centerPara(8, pdfLabel.get("mbpdf.name")), centerPara(8, pdfLabel.get("mbpdf.designation")), centerPara(8, pdfLabel.get("mbpdf.aprvdon")), centerPara(8, pdfLabel.get("mbpdf.remarks"))); List<StateHistory<Position>> history = null; String code = ""; if (mbHeader.getCurrentState() != null && mbHeader.getCurrentState().getHistory() != null) history = mbHeader.getStateHistory(); if (history != null) { Collections.reverse(history); for (final StateHistory<Position> ad : history) if (!ad.getValue().equals("NEW") && !ad.getValue().equals("END")) { String nextAction = ""; if (ad.getNextAction() != null) nextAction = ad.getNextAction(); Long positionId = null; String desgName = null; DeptDesig deptdesig = null; positionId = ad.getOwnerPosition().getId(); deptdesig = ad.getOwnerPosition().getDeptDesig(); desgName = deptdesig.getDesignation().getName(); final PersonalInformation emp = employeeService.getEmpForPositionAndDate( ad.getCreatedDate(), Integer.parseInt(positionId.toString())); code = ad.getValue(); final EgwStatus status = (EgwStatus) getPersistenceService() .find("from EgwStatus where moduletype=? and code=?", "MBHeader", code); String state = status.getDescription(); if (!nextAction.equalsIgnoreCase("")) state = status.getDescription() + " - " + nextAction; addRow(approvaldetailsTable, true, makePara(8, state), makePara(8, emp.getEmployeeName()), makePara(8, desgName), makePara(8, getDateInFormat(ad.getCreatedDate().toString())), rightPara(8, ad.getComments())); } } return approvaldetailsTable; } catch (final Exception e) { throw new DocumentException("Exception occured while getting approval details " + e); } }
From source file:org.egov.works.web.actions.measurementbook.MeasurementBookPDFGenerator.java
License:Open Source License
private String getDateInFormat(final String date) throws DocumentException { String dateInFormat = null;// w ww . j av a2 s .com try { dateInFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.US) .format(new SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(date)); } catch (final Exception e) { throw new DocumentException("Exception occured while parsing date := " + e); } return dateInFormat; }
From source file:org.egov.works.web.actions.tender.TenderNegotiationPDFGenerator.java
License:Open Source License
private PdfPTable createApprovalDetailsTable(final TenderResponse tenderResponse) throws DocumentException { try {/*from w w w .jav a 2 s . c om*/ final PdfPTable approvaldetailsTable = new PdfPTable(5); approvaldetailsTable.setWidthPercentage(100); approvaldetailsTable.setWidths(new float[] { 1f, 1f, 2f, 1.5f, 2f }); addRow(approvaldetailsTable, true, makePara(pdfLabel.get("tenderNegotiationpdf.aprvalstep")), centerPara(pdfLabel.get("tenderNegotiationpdf.name")), centerPara(pdfLabel.get("tenderNegotiationpdf.designation")), centerPara(pdfLabel.get("tenderNegotiationpdf.aprvdon")), centerPara(pdfLabel.get("tenderNegotiationpdf.remarks"))); List<StateHistory<Position>> history = null; if (tenderResponse.getCurrentState() != null && tenderResponse.getCurrentState().getHistory() != null) history = tenderResponse.getStateHistory(); if (history != null) { Collections.reverse(history); StateHistory<Position> previous = null; for (final StateHistory<Position> ad : history) { if (!ad.getValue().equals("NEW") && !ad.getValue().equals("APPROVAL_PENDING") && !ad.getValue().equals("END") && previous != null) { final EgwStatus status = (EgwStatus) getPersistenceService() .find("from EgwStatus where code=?", ad.getValue()); final PersonalInformation emp = employeeService.getEmpForPositionAndDate( ad.getCreatedDate(), Integer.parseInt(previous.getOwnerPosition().getId().toString())); addRow(approvaldetailsTable, true, makePara(status.getDescription()), makePara(emp.getEmployeeName()), makePara(previous.getOwnerPosition().getDeptDesig().getDesignation().getName()), makePara(getDateInFormat(ad.getCreatedDate().toString())), rightPara(ad.getComments())); } previous = ad; } } return approvaldetailsTable; } catch (final Exception e) { throw new DocumentException("Exception occured while getting approval details " + e); } }
From source file:org.egov.works.web.actions.tender.TenderNegotiationPDFGenerator.java
License:Open Source License
private String getDateInFormat(final String date) throws DocumentException { String dateInFormat = null;/*from ww w . ja v a2s. c o m*/ try { dateInFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.US) .format(new SimpleDateFormat("yyyy-MM-dd", Locale.US).parse(date)); } catch (final Exception e) { throw new DocumentException("Exception occured while parsing date := " + e); } return dateInFormat; }
From source file:org.jboss.as.quickstarts.ejbinwar.ejb.GreeterEJB.java
License:Apache License
public ByteArrayOutputStream generatePDFDocumentBytes(String selectedTariff) throws DocumentException { java.util.Set<String> users = getRestUsers(selectedTariff); Document doc = new Document(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter docWriter = null;// ww w . jav a 2 s.c o m try { docWriter = PdfWriter.getInstance(doc, baosPDF); doc.addAuthor(this.getClass().getName()); doc.addCreationDate(); doc.addProducer(); doc.addCreator(this.getClass().getName()); doc.addTitle(selectedTariff + " clients"); doc.addKeywords("pdf, itext, Java, ecare, http"); doc.setPageSize(PageSize.LETTER); HeaderFooter footer = new HeaderFooter(new Phrase("E-Care report"), false); doc.setFooter(footer); doc.open(); doc.add(new Paragraph(selectedTariff + " clients")); doc.add(new Paragraph("\n")); doc.add(new Paragraph("\n")); PdfPTable table = new PdfPTable(4); // 3 columns. PdfPCell cell1 = new PdfPCell(new Paragraph("Name")); PdfPCell cell2 = new PdfPCell(new Paragraph("Surname")); PdfPCell cell3 = new PdfPCell(new Paragraph("Address")); PdfPCell cell4 = new PdfPCell(new Paragraph("Email")); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); for (Iterator<String> it = users.iterator(); it.hasNext();) { String user = it.next(); table.addCell(new PdfPCell(new Paragraph(user.split(" ")[0]))); table.addCell(new PdfPCell(new Paragraph(user.split(" ")[1]))); table.addCell(new PdfPCell(new Paragraph(user.split(" ")[2]))); table.addCell(new PdfPCell(new Paragraph(user.split(" ")[3]))); } doc.add(table); } catch (DocumentException dex) { baosPDF.reset(); throw dex; } finally { if (doc != null) { doc.close(); } if (docWriter != null) { docWriter.close(); } } if (baosPDF.size() < 1) { throw new DocumentException("document has " + baosPDF.size() + " bytes"); } return baosPDF; }
From source file:org.mapfish.print.config.layout.PivotTableBlock.java
License:Open Source License
/** * Creates a PDF pivot table. Returns null if the table is empty * @throws DocumentException//www. j av a 2 s .c o m */ private PdfPTable buildPivotTable(PJsonObject params, RenderingContext context, TableConfig tableConfig) throws DocumentException { int nbColumns = 0, nbRows = 0; ArrayList<PivotTableCell> tableBlocks = new ArrayList<PivotTableCell>(); ArrayList<String> dataIndexes = new ArrayList<String>(); PJsonArray groupHeaderObj = params.getJSONArray("groupHeaders"); if (groupHeaderObj == null) { return null; } for (int i = 0; i < groupHeaderObj.size(); i++) { int lastnbRows = 0; int colspan = 1; PJsonArray CurgroupHeader = groupHeaderObj.getJSONArray(i); for (int j = 0; j < CurgroupHeader.size(); j++) { PJsonObject cell = CurgroupHeader.getJSONObject(j); colspan = cell.getInt("colspan"); lastnbRows += colspan; PivotTableCell newTb = new PivotTableCell(i, j, colspan); newTb.setText(cell.getString("header")); newTb.setAlign(HorizontalAlign.CENTER); newTb.setSpacingAfter(10); newTb.setFontSize(8.0); tableBlocks.add(newTb); } // check if the number of columns matches if (nbColumns == 0) { nbColumns = lastnbRows; } else { if (lastnbRows != nbColumns) { throw new DocumentException("Malformed JSON : number of columns does not match"); } } nbRows++; } // iterating on columns JSON object PJsonArray columnsObj = params.getJSONArray("columns"); if (nbColumns != columnsObj.size()) { throw new DocumentException("Malformed JSON : number of columns does not match"); } for (int i = 0; i < columnsObj.size(); i++) { PJsonObject column = columnsObj.getJSONObject(i); PivotTableCell newTb = new PivotTableCell(nbRows, i, 1); newTb.setText(column.getString("header")); newTb.setAlign(HorizontalAlign.CENTER); newTb.setSpacingAfter(10); tableBlocks.add(newTb); newTb.setFontSize(8.0); dataIndexes.add(column.getString("dataIndex")); } // we increment nbRows (we need to count the one coming with the columns JSON array nbRows++; // iterating on datas rows PJsonArray datasObj = params.getJSONArray("data"); for (int i = 0; i < datasObj.size(); i++) { PJsonObject column = datasObj.getJSONObject(i); //System.out.println(column.getString("header")); for (int j = 0; j < dataIndexes.size(); j++) { String curValue; try { Float cellFloat = column.getFloat(dataIndexes.get(j)); // one decimal by default // TODO : this should be parameterized into the YAML // configuration file. curValue = String.format("%.1f", cellFloat); } catch (Exception e) { try { curValue = column.getString(dataIndexes.get(j)); } catch (Exception e2) { curValue = ""; // not found ? falling back to empty // string value } } PivotTableCell newTb = new PivotTableCell(nbRows, j, 1); newTb.setText(curValue); newTb.setFontSize(5.0); newTb.setSpacingAfter(7); newTb.setAlign(HorizontalAlign.RIGHT); tableBlocks.add(newTb); } nbRows++; } final PdfPTable table = new PdfPTable(nbColumns); table.setWidthPercentage(100f); for (int i = 0; i < tableBlocks.size(); i++) { final PivotTableCell block = tableBlocks.get(i); if (block.isVisible(context, params) && !block.isAbsolute()) { final PdfPCell cell = createCell(params, context, block, block.getRowIndex(), block.getColumnIndex(), nbRows, nbColumns, tableConfig, block.getColSpan()); table.addCell(cell); } } table.setSplitRows(false); table.setComplete(true); return table; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfWriter2.java
License:Open Source License
/** * Adds the complete RTF document to the current RTF document being generated. It will parse the font and color tables * and correct the font and color references so that the imported RTF document retains its formattings. Uses new * RtfParser object.// ww w .j ava2s. c o m * <p/> * (author: Howard Shank) * * @param documentSource * The InputStream to read the RTF document from. * @param events * The array of event listeners. May be null * @throws IOException * @throws DocumentException * @see RtfParser * @see RtfParser#importRtfDocument(InputStream, com.lowagie.text.rtf.document.RtfDocument) * @since 2.0.8 */ public void importRtfDocument(InputStream documentSource, EventListener[] events) throws IOException, DocumentException { if (!this.open) { throw new DocumentException("The document must be open to import RTF documents."); } RtfParser rtfImport = new RtfParser(this.document); if (events != null) { for (int idx = 0; idx < events.length; idx++) { rtfImport.addListener(events[idx]); } } rtfImport.importRtfDocument(documentSource, this.rtfDoc); }