/** * Returns the width of a certain character of this font. * * @param character a certain character * @return a width in Text Space */ float width(int character) { if (image == null) return font.getWidthPoint(character, size) * hScale; else return image.getScaledWidth(); }
float width(String s) { if (image == null) return font.getWidthPoint(s, size) * hScale; else return image.getScaledWidth(); }
/** * Returns the width of a certain character of this font. * * @param character a certain character * @return a width in Text Space */ float width(int character) { if (image == null) return font.getWidthPoint(character, size) * hScale; else return image.getScaledWidth(); }
float width(String s) { if (image == null) return font.getWidthPoint(s, size) * hScale; else return image.getScaledWidth(); }
float width(String s) { if (image == null) return font.getWidthPoint(s, size) * hScale; else return image.getScaledWidth(); }
/** * Returns the width of a certain character of this font. * * @param character a certain character * @return a width in Text Space */ float width(int character) { if (image == null) return font.getWidthPoint(character, size) * hScale; else return image.getScaledWidth(); }
Image image = Image.getInstance(IMAGE); float width = image.getScaledWidth(); float height = image.getScaledHeight();
PdfContentByte cb = writer.getDirectContent(); Image img = createBarcode(cb, "This is a 2D barcode", 1, 1); document.add(new Paragraph( String.format("This barcode measures %s by %s user units", img.getScaledWidth(), img.getScaledHeight()))); document.add(img); img = createBarcode(cb, "This is NOT a raster image", 3, 3); document.add(new Paragraph( String.format("This barcode measures %s by %s user units", img.getScaledWidth(), img.getScaledHeight()))); document.add(img); img = createBarcode(cb, "This is vector data drawn on a PDF page", 1, 3); document.add(new Paragraph( String.format("This barcode measures %s by %s user units", img.getScaledWidth(), img.getScaledHeight())));
/** * Gets the width of the <CODE>PdfChunk</CODE> taking into account the * extra character and word spacing. * @param charSpacing the extra character spacing * @param wordSpacing the extra word spacing * @return the calculated width */ public float getWidthCorrected(float charSpacing, float wordSpacing) { if (image != null) { return image.getScaledWidth() + charSpacing; } int numberOfSpaces = 0; int idx = -1; while ((idx = value.indexOf(' ', idx + 1)) >= 0) ++numberOfSpaces; return width() + (value.length() * charSpacing + numberOfSpaces * wordSpacing); }
public Image getWatermarkedImage(PdfContentByte cb, Image img, String watermark) throws DocumentException { float width = img.getScaledWidth(); float height = img.getScaledHeight(); PdfTemplate template = cb.createTemplate(width, height); template.addImage(img, width, 0, 0, height, 0, 0); ColumnText.showTextAligned(template, Element.ALIGN_CENTER, new Phrase(watermark, FONT), width / 2, height / 2, 30); return Image.getInstance(template); }
public Image cropImage(PdfWriter writer, Image image, float leftReduction, float rightReduction, float topReduction, float bottomReduction) throws DocumentException { float width = image.getScaledWidth(); float height = image.getScaledHeight(); PdfTemplate template = writer.getDirectContent().createTemplate( width - leftReduction - rightReduction, height - topReduction - bottomReduction); template.addImage(image, width, 0, 0, height, -leftReduction, -bottomReduction); return Image.getInstance(template); }
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open(); Image img = Image.getInstance(IMAGE); img.scaleToFit(770, 523); float offsetX = (770 - img.getScaledWidth()) / 2; float offsetY = (523 - img.getScaledHeight()) / 2; img.setAbsolutePosition(36 + offsetX, 36 + offsetY); document.add(img); document.close(); }
Document document = new Document(); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.open(); // step 4 // Adding a series of images Image img; for (int i = 0; i < RESOURCES.length; i++) { img = Image.getInstance(String.format("resources/img/%s", RESOURCES[i])); if (img.getScaledWidth() > 300 || img.getScaledHeight() > 300) { img.scaleToFit(300, 300); } document.add(new Paragraph( String.format("%s is an image of type %s", RESOURCES[i], img.getClass().getName()))); document.add(img); }
public static Image cropImage(Image image, PdfWriter writer, float x, float y, float width, float height) throws DocumentException { PdfContentByte cb = writer.getDirectContent(); PdfTemplate t = cb.createTemplate(width, height); float origWidth = image.getScaledWidth(); float origHeight = image.getScaledHeight(); t.addImage(image, origWidth, 0, 0, origHeight, -x, -y); return Image.getInstance(t); }
/** * Scales the image so that it fits a certain width and height. * * @param fitWidth * the width to fit * @param fitHeight * the height to fit */ public void scaleToFit(float fitWidth, float fitHeight) { scalePercent(100); float percentX = (fitWidth * 100) / getScaledWidth(); float percentY = (fitHeight * 100) / getScaledHeight(); scalePercent(percentX < percentY ? percentX : percentY); setWidthPercentage(0); }
/** * Scales the image so that it fits a certain width and height. * * @param fitWidth * the width to fit * @param fitHeight * the height to fit */ public void scaleToFit(float fitWidth, float fitHeight) { scalePercent(100); float percentX = (fitWidth * 100) / getScaledWidth(); float percentY = (fitHeight * 100) / getScaledHeight(); scalePercent(percentX < percentY ? percentX : percentY); setWidthPercentage(0); }
/** * Scales the image so that it fits a certain width and height. * * @param fitWidth * the width to fit * @param fitHeight * the height to fit */ public void scaleToFit(float fitWidth, float fitHeight) { scalePercent(100); float percentX = (fitWidth * 100) / getScaledWidth(); float percentY = (fitHeight * 100) / getScaledHeight(); scalePercent(percentX < percentY ? percentX : percentY); setWidthPercentage(0); }
/** * Gets the width of the Chunk in points. * * @return a width in points */ public float getWidthPoint() { if (getImage() != null) { return getImage().getScaledWidth(); } return font.getCalculatedBaseFont(true).getWidthPoint(getContent(), font.getCalculatedSize()) * getHorizontalScaling(); }
/** * Gets the width of the Chunk in points. * * @return a width in points */ public float getWidthPoint() { if (getImage() != null) { return getImage().getScaledWidth(); } return font.getCalculatedBaseFont(true).getWidthPoint(getContent(), font.getCalculatedSize()) * getHorizontalScaling(); }
/** * Gets the width of the Chunk in points. * * @return a width in points */ public float getWidthPoint() { if (getImage() != null) { return getImage().getScaledWidth(); } return font.getCalculatedBaseFont(true).getWidthPoint(getContent(), font.getCalculatedSize()) * getHorizontalScaling(); }