List of usage examples for com.itextpdf.text.pdf BaseFont createFont
public static BaseFont createFont(String name, String encoding, boolean embedded) throws DocumentException, IOException
From source file:de.aidger.utils.pdf.ProtocolConverter.java
License:Open Source License
/** * Writes the Table of activities./*from w w w . j a v a 2 s . c o m*/ */ private void writeTable() { try { Font tableTitleFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 9); String[] courseTitles = { _("Affected assistant"), _("Affected course"), _("Type"), _("Date"), _("Content"), _("Initiator"), _("Processor"), _("Remark") }; PdfPTable contentTable = new PdfPTable(1); PdfPTable titleTable = new PdfPTable(8); /* * Create the titles of the table entries. */ for (int i = 0; i < courseTitles.length; i++) { PdfPCell cell = new PdfPCell(new Phrase(courseTitles[i], tableTitleFont)); if (i != 0) { cell.setBorder(6); } else { cell.setBorder(2); } titleTable.addCell(cell); } PdfPCell cell = new PdfPCell(titleTable); cell.setPaddingTop(10.0f); cell.setBorder(0); contentTable.addCell(cell); document.add(contentTable); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.aidger.utils.pdf.ProtocolConverter.java
License:Open Source License
/** * Adds one activity to the activity table. * //ww w . j a va2 s . c o m * @param activity * The activity to add. * @return The PdfPTable of the row. * @throws DocumentException * @throws IOException */ private PdfPTable addRow(Object[] activity) throws DocumentException, IOException { Font tableContentFont = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 9); PdfPTable contentTable = new PdfPTable(8); for (int i = 0; i < 8; i++) { PdfPCell cell = new PdfPCell(new Phrase(activity[i].toString(), tableContentFont)); if (i != 0) { cell.setBorder(4 + Rectangle.TOP); } else { cell.setBorder(0 + Rectangle.TOP); } cell.setPaddingBottom(5); contentTable.addCell(cell); } return contentTable; }
From source file:de.beimax.talenttree.PDFGenerator.java
License:Open Source License
/** * Load fonts/*from w ww .ja va2 s. c o m*/ * @throws Exception */ protected void loadFonts() throws Exception { // try header font try { fontHeader = BaseFont.createFont(getClass().getResource("/fonts/LeagueGothic-Regular.otf").toString(), BaseFont.WINANSI, BaseFont.EMBEDDED); } catch (Exception e) { throw new Exception("Header font could not be loaded."); } // try regular font try { fontRegular = BaseFont.createFont( getClass().getResource("/fonts/LiberationSans-Regular.ttf").toString(), BaseFont.WINANSI, BaseFont.EMBEDDED); } catch (Exception e) { throw new Exception("Regular font could not be loaded."); } // try bold font try { fontBold = BaseFont.createFont(getClass().getResource("/fonts/LiberationSans-Bold.ttf").toString(), BaseFont.WINANSI, BaseFont.EMBEDDED); } catch (Exception e) { throw new Exception("Bold font could not be loaded."); } // try regular condensed font try { fontCondensedRegular = BaseFont.createFont( getClass().getResource("/fonts/LiberationSansNarrow-Regular.ttf").toString(), BaseFont.WINANSI, BaseFont.EMBEDDED); } catch (Exception e) { throw new Exception("Regular font could not be loaded."); } // try bold condensed font try { fontCondensedBold = BaseFont.createFont( getClass().getResource("/fonts/LiberationSansNarrow-Bold.ttf").toString(), BaseFont.WINANSI, BaseFont.EMBEDDED); } catch (Exception e) { throw new Exception("Bold font could not be loaded."); } // try symbol font try { fontSymbol = BaseFont.createFont(getClass().getResource("/fonts/EotE_Symbol-Regular_v1.otf").toString(), BaseFont.WINANSI, BaseFont.EMBEDDED); } catch (Exception e) { throw new Exception("Symbol font could not be loaded."); } }
From source file:de.jost_net.JVerein.io.FormularAufbereitung.java
License:Open Source License
private void goFormularfeld(PdfContentByte contentByte, Formularfeld feld, Object val) throws DocumentException, IOException { BaseFont bf = null;//from w w w .jav a2 s . c o m if (feld.getFont().startsWith("FreeSans")) { String filename = "/fonts/FreeSans"; if (feld.getFont().length() > 8) { filename += feld.getFont().substring(9); } bf = BaseFont.createFont(filename + ".ttf", BaseFont.IDENTITY_H, true); } else { bf = BaseFont.createFont(feld.getFont(), BaseFont.CP1250, false); } float x = mm2point(feld.getX().floatValue()); float y = mm2point(feld.getY().floatValue()); if (val == null) { return; } buendig = links; String stringVal = getString(val); stringVal = stringVal.replace("\\n", "\n"); stringVal = stringVal.replaceAll("\r\n", "\n"); String[] ss = stringVal.split("\n"); for (String s : ss) { contentByte.setFontAndSize(bf, feld.getFontsize().floatValue()); contentByte.beginText(); float offset = 0; if (buendig == rechts) { offset = contentByte.getEffectiveStringWidth(s, true); } contentByte.moveText(x - offset, y); contentByte.showText(s); contentByte.endText(); y -= feld.getFontsize().floatValue() + 3; } }
From source file:de.mat.utils.pdftools.PdfAddPageNum.java
License:Mozilla Public License
/** * <h4>FeatureDomain:</h4>/*from w ww .j av a2s. c o m*/ * PublishingTools * <h4>FeatureDescription:</h4> * adds pagenum with stamper to pages from reader * <h4>FeatureResult:</h4> * <ul> * <li>updates stamper - updates the stamper * </ul> * <h4>FeatureKeywords:</h4> * PDF Publishing * @param reader - reader with the pages * @param stamper - stamper to add the canvas * @param pageOffset - add to pagenumber * @throws DocumentException * @throws IOException */ public void addPageNumber(PdfReader reader, PdfStamper stamper, int pageOffset) throws DocumentException, IOException { // ierate all pages from reader for (int zaehler = 1; zaehler <= reader.getNumberOfPages(); zaehler++) { // read pagesize Rectangle pageSize = reader.getPageSize(zaehler); float xpos = pageSize.getLeft() + pageSize.getWidth() / 2; float ypos = 20; float fontSize = 7; // Default-Positions for --page-width 150mm --page-height 212mm == 601px if (pageSize.getHeight() > 602 || pageSize.getHeight() < 598) { // correct it relative float factor = pageSize.getHeight() / 601; if (LOGGER.isDebugEnabled()) LOGGER.debug(" PageHeight:" + pageSize.getHeight() + " Factor:" + factor); ypos = ypos * factor; fontSize = fontSize * factor; } // add pagenumber-canvas PdfContentByte canvas = stamper.getOverContent(zaehler); BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false); canvas.setFontAndSize(bf_helv, fontSize); canvas.beginText(); canvas.showTextAligned(PdfContentByte.ALIGN_CENTER, "" + new Integer(zaehler + pageOffset - 1), xpos, ypos, 0); canvas.endText(); } }
From source file:dk.dma.epd.common.util.FALPDFGenerator.java
License:Apache License
public void generateFal1Form(FALForm1 fal1form, String filename) { try {//from w ww . ja v 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:edu.avans.ivh5.shared.util.generateInvoicePDF2.java
private void initializeFonts() { try {/*from www . j a va 2 s . c o m*/ bfBold = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:englishrusbook.Writer.java
public void write(Document document, HashMap<String, String> wordTranslateMap) { document.open();/* w w w. j a v a 2 s .c o m*/ String delimiter = " : "; try { BaseFont helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Font font = new Font(helvetica, 12); for (Entry<String, String> entry : wordTranslateMap.entrySet()) { document.add(new Paragraph(entry.getKey() + delimiter + entry.getValue(), font)); } } catch (DocumentException | IOException e) { System.out.println("ERROR in writing: " + e); } finally { document.close(); } }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
public String insertComment(String sx, String sy, String id, String deptValue, String userInit, String comment, int pageNum, int masterHeight, int masterWidth, int pinned, int customFontSize) throws DocumentException, IOException { float ratio = getRatio(masterHeight, masterWidth, pageNum); float x = Float.parseFloat(sx); float y = Float.parseFloat(sy); float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum); PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(1);//from w ww . j a v a 2s . c om if (customFontSize > 0) fontSize = customFontSize; PdfContentByte fg = pds.getOverContent(pageNum); fg.setGState(gs1); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight, masterWidth, pageNum); // comment tag image (width=35pts, height=8pts) float[] scalar = scale(trans[0], trans[1], 35, 8, masterHeight, masterWidth, pageNum); /* Addition. ftorres - 7/21/2015 - Added to account for rotated pages * with the origin (0,0) not set to the bottom-left of the page. [1400] */ float coords[] = translateRotation(trans[0], trans[1], pageNum); coords = checkBounds(coords[0], coords[1], pageNum); /* Addition. ftorres - 10/20/2015 - If the comment was pinned in EPC, then * render the comment inside a comment box. */ if (pinned == 1) { insertPinnedComment(coords[0], coords[1], id + " - " + deptValue + " (" + userInit + ")", comment, pageNum, masterHeight, masterWidth); // Add the pinned comment text to page annotation -Jon Changkachith 11/24/2015 Rectangle rect = new Rectangle(0, 0, 0, 0); PdfAnnotation annotation = PdfAnnotation.createText(pds.getWriter(), rect, id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), true, id); pds.addAnnotation(annotation, pds.getWriter().getCurrentPageNumber()); } else { Image image = Image.getInstance(commentIMGPath); image.setAbsolutePosition(coords[0] + (scalar[0] * (id.length() / 5f)), coords[1]); /* * Commented out by Jon Changkachith 12/09/2015 because it was throwing * DocumentException with the message "The image must have absolute positioning." image.scaleAbsoluteHeight(1); image.scaleAbsoluteWidth(1); */ image.scalePercent(ratio); //Added to fix DocumentException "The image must have absolute positioning." Jon Changkachith 12/09/2015 image.setAnnotation(new Annotation(id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), 0, 0, 0, 0)); fg.addImage(image); } fg.setLineWidth(.5f * ratio); fg.setColorStroke(new BaseColor(Color.decode("0x6E2405").getRGB())); fg.setColorFill(new BaseColor(Color.decode("0x6E2405").getRGB())); float tHeight = scalar[1]; float tWidth = 0; if (id.length() > 3) { tWidth = (scalar[0] * (id.length() / 5f)); } else { tWidth = (scalar[0]); } fg.moveTo(coords[0], coords[1]); fg.lineTo(coords[0] + (10f * ratio), coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] - (tHeight / 2)); fg.lineTo(coords[0] + tWidth, coords[1] + (tHeight / 2)); fg.lineTo(coords[0] + (10f * ratio), coords[1] + (tHeight / 2)); fg.lineTo(coords[0], coords[1]); fg.closePathFillStroke(); fg.fill(); // Comment number that goes on the comment tag image Phrase p = new Phrase(id); p.getFont().setColor(BaseColor.WHITE); p.getFont().setSize(8f * ratio); //comment number font size = 8f //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id)); float fs[] = translateRotation(f[0], f[1], pageNum); fs = checkBounds(fs[0], fs[1], pageNum); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, p, (float) (fs[0] + (9 * ratio)), (float) (fs[1] - (3 * ratio)), 0); return ""; }
From source file:EplanPrinter.PDFPrint.java
License:Open Source License
private void insertPinnedComment(float xCoord, float yCoord, String id, String comment, int pageNum, int masterHeight, int masterWidth) throws DocumentException, IOException { int standardHeight = 38; int standardWidth = 130; int lineHeight = 7; if (fontSize == 8) { standardHeight = 48;/*from ww w.j a va 2 s .c o m*/ standardWidth = 180; lineHeight = 10; } else if (fontSize == 10) { standardHeight = 70; standardWidth = 210; lineHeight = 12; } // comment box position defines lower-left corner xCoord += 41; // x-coordinate of comment text box yCoord -= 7; // lower offset moves box up float f = (float) 0.4; PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(f); PdfContentByte fg = pds.getOverContent(pageNum); fg.setGState(gs1); fg.setLineWidth(.5f * getRatio(masterHeight, masterWidth, pageNum)); // Calculate additional needed height for the comment, based on length of comment. List<String> lines = createComment(cleanupComment(comment)); int numLines = lines.size(); int commentHeight = (numLines - 1) * lineHeight; // Draw the comment box String color = "0xF2F3E4"; Color c = Color.decode(color); color = "0xFAFAF4"; Color c2 = Color.decode(color); fg.setLineWidth(1f); fg.setColorStroke(new BaseColor(c.getRGB())); fg.setColorFill(new BaseColor(c2.getRGB())); float newCoords[] = pinnedCoords(xCoord, yCoord, standardWidth, standardHeight + commentHeight); fg.roundRectangle(xCoord, newCoords[1], standardWidth, standardHeight + commentHeight, 2f); fg.fillStroke(); //BaseFont bf = BaseFont.createFont(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, true); BaseFont bfb = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, true); fg.setColorFill(BaseColor.RED); gs1.setFillOpacity(0.8f); fg.setGState(gs1); // Adding comment title text Phrase phrase = new Phrase("Comment", new Font(bfb, fontSize)); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, xCoord + 3, yCoord - 7, 0); // Adding comment number phrase = new Phrase(id, new Font(bf, fontSize)); float offset = xCoord + 35; if (fontSize == 8) offset = xCoord + 45; else if (fontSize == 10) offset = xCoord + 55; ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, offset, yCoord - 7, 0); /* Remove 10/27/2015 Jon Changkachith // Adding 'comment' label text phrase = new Phrase("Comment", new Font(bfb, fontSize)); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, xCoord + 3, yCoord - 20f, 0); */ // Adding comment text int commentYOffset = 32; for (int i = 0; i < lines.size(); i++) { //phrase = new Phrase(lines.get(i), new Font(bf, fontSize)); phrase = composePhrase(lines.get(i), bf, bfb); ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, phrase, xCoord + 3, yCoord - commentYOffset, 0); commentYOffset += lineHeight; } }