List of usage examples for com.itextpdf.text Font getBaseFont
public BaseFont getBaseFont()
BaseFont
inside this object. From source file:com.chaschev.itext.ColumnTextBuilder.java
License:Apache License
private static float calcApproximateFontHeight(Font font) { final BaseFont baseFont = font.getBaseFont(); return baseFont.getFontDescriptor(BaseFont.ASCENT, font.getSize()) - baseFont.getFontDescriptor(BaseFont.DESCENT, font.getSize()); }
From source file:com.ephesoft.dcma.imagemagick.MultiPageExecutor.java
License:Open Source License
/** * The <code>addImageToPdf</code> method is used to add image to pdf and make it searchable by adding image text in invisible mode * w.r.t parameter 'isPdfSearchable' passed. * // w ww. j a v a2 s . c om * @param pdfWriter {@link PdfWriter} writer of pdf in which image has to be added * @param htmlUrl {@link HocrPage} corresponding html file for fetching text and coordinates * @param imageUrl {@link String} url of image to be added in pdf * @param isPdfSearchable true for searchable pdf else otherwise * @param widthOfLine */ private void addImageToPdf(PdfWriter pdfWriter, HocrPage hocrPage, String imageUrl, boolean isPdfSearchable, final int widthOfLine) { if (null != pdfWriter && null != imageUrl && imageUrl.length() > 0) { try { LOGGER.info("Adding image" + imageUrl + " to pdf using iText"); Image pageImage = Image.getInstance(imageUrl); float dotsPerPointX = pageImage.getDpiX() / PDF_RESOLUTION; float dotsPerPointY = pageImage.getDpiY() / PDF_RESOLUTION; PdfContentByte pdfContentByte = pdfWriter.getDirectContent(); pageImage.scaleToFit(pageImage.getWidth() / dotsPerPointX, pageImage.getHeight() / dotsPerPointY); pageImage.setAbsolutePosition(0, 0); // Add image to pdf pdfWriter.getDirectContentUnder().addImage(pageImage); pdfWriter.getDirectContentUnder().add(pdfContentByte); // If pdf is to be made searchable if (isPdfSearchable) { LOGGER.info("Adding invisible text for image: " + imageUrl); float pageImagePixelHeight = pageImage.getHeight(); Font defaultFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD, CMYKColor.BLACK); // Fetch text and coordinates for image to be added Map<String, int[]> textCoordinatesMap = getTextWithCoordinatesMap(hocrPage, widthOfLine); Set<String> ketSet = textCoordinatesMap.keySet(); // Add text at specific location for (String key : ketSet) { int[] coordinates = textCoordinatesMap.get(key); float bboxWidthPt = (coordinates[2] - coordinates[0]) / dotsPerPointX; float bboxHeightPt = (coordinates[3] - coordinates[1]) / dotsPerPointY; pdfContentByte.beginText(); // To make text added as invisible pdfContentByte.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE); pdfContentByte.setLineWidth(Math.round(bboxWidthPt)); // Ceil is used so that minimum font of any text is 1 // For exception of unbalanced beginText() and endText() if (bboxHeightPt > 0.0) { pdfContentByte.setFontAndSize(defaultFont.getBaseFont(), (float) Math.ceil(bboxHeightPt)); } else { pdfContentByte.setFontAndSize(defaultFont.getBaseFont(), 1); } float xCoordinate = (float) (coordinates[0] / dotsPerPointX); float yCoordinate = (float) ((pageImagePixelHeight - coordinates[3]) / dotsPerPointY); pdfContentByte.moveText(xCoordinate, yCoordinate); pdfContentByte.showText(key); pdfContentByte.endText(); } } pdfContentByte.closePath(); } catch (BadElementException badElementException) { LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + badElementException.toString()); } catch (DocumentException documentException) { LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + documentException.toString()); } catch (MalformedURLException malformedURLException) { LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + malformedURLException.toString()); } catch (IOException ioException) { LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + ioException.toString()); } } }
From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java
License:Open Source License
public static BaseFont getFooterFont() { if (footerFont == null) { Font font = FontFactory.getFont("/" + TITLE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.5f, Font.NORMAL, BaseColor.BLACK); footerFont = font.getBaseFont(); }/* ww w .j a v a 2 s .c o m*/ return footerFont; }
From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java
License:Open Source License
public static BaseFont getLineFont() { if (lineFont == null) { Font font = FontFactory.getFont("/" + LINE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f, Font.NORMAL, BaseColor.BLACK); lineFont = font.getBaseFont(); }// ww w .j a va2 s. c o m return lineFont; }
From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java
License:Open Source License
public static BaseFont getLineItalicFont() { if (lineItalicFont == null) { Font font = FontFactory.getFont("/" + LINE_FONT_ITALIC_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f, Font.ITALIC, BaseColor.BLACK); lineItalicFont = font.getBaseFont(); }/* w w w. ja v a2 s . co m*/ return lineItalicFont; }
From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java
License:Open Source License
public static BaseFont getLineFontBold() { if (lineBoldFont == null) { Font font = FontFactory.getFont("/" + LINE_BOLD_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f, Font.BOLD, BaseColor.BLACK); lineBoldFont = font.getBaseFont(); }// w w w . j a va 2s. c o m return lineBoldFont; }
From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java
License:Open Source License
public static BaseFont getTitleFont() { if (titleFont == null) { Font font = FontFactory.getFont("/" + TITLE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f, Font.NORMAL, BaseColor.BLACK); titleFont = font.getBaseFont(); }/*from w ww . j av a 2 s . c o m*/ return titleFont; }
From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java
License:Open Source License
public static BaseFont getSubtitleFont() { if (tableSubtitleFont == null) { Font font = FontFactory.getFont("/" + TABLE_SUBTITLE_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f, Font.ITALIC, BaseColor.BLACK); tableSubtitleFont = font.getBaseFont(); }// w w w . j av a 2 s . co m return tableSubtitleFont; }
From source file:com.softwaremagico.tm.pdf.complete.FadingSunsTheme.java
License:Open Source License
public static BaseFont getHandwrittingFont() { if (handwrittingFont == null) { Font font = FontFactory.getFont("/" + HANDWRITTING_FONT_NAME, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 0.8f, Font.NORMAL, BaseColor.BLACK); handwrittingFont = font.getBaseFont(); }/*w ww .j ava 2s.co m*/ return handwrittingFont; }
From source file:com.vectorprint.report.itext.style.parameters.BaseFontWrapper.java
License:Open Source License
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject();/*from w w w . j a va 2 s .c o m*/ Font f = FontFactory.getFont(fontName); if (f.getBaseFont() == null) { throw new VectorPrintRuntimeException("No basefont for: " + fontName); } baseFont = f.getBaseFont(); }