public static void render(Drawable drawable, Rectangle2D bounds, File file) { initialize(); Rectangle size = new Rectangle((float) bounds.getWidth(), (float) bounds.getHeight()); Document document = new Document(size); FileOutputStream fos; try { fos = new FileOutputStream(file); } catch (FileNotFoundException e) { throw new RuntimeException("The file " + file + "could not be created", e); } PdfWriter writer; try { writer = PdfWriter.getInstance(document, fos); } catch (DocumentException e) { throw new RuntimeException("An error occurred while creating a PdfWriter object.", e); } document.open(); PdfContentByte contentByte = writer.getDirectContent(); Graphics2D g = new PdfGraphics2D(contentByte, (float) bounds.getWidth(), (float) bounds.getHeight(), fontMapper); g.translate(-bounds.getX(), -bounds.getY()); drawable.draw(g); g.dispose(); document.close(); }
/** Gets the maximum area that the barcode and the text, if * any, will occupy. The lower left corner is always (0, 0). * @return the size the barcode occupies. */ public Rectangle getBarcodeSize() { float width = ((code.length() + 1) * 5 + 1) * n + x; return new Rectangle(width, barHeight); }
/** Gets the maximum area that the barcode and the text, if * any, will occupy. The lower left corner is always (0, 0). * @return the size the barcode occupies. */ public Rectangle getBarcodeSize() { float width = ((code.length() + 1) * 5 + 1) * n + x; return new Rectangle(width, barHeight); }
/** Gets the size of the barcode grid. */ public Rectangle getBarcodeSize() { paintCode(); return new Rectangle(0, 0, bitColumns, codeRows); }
/** Sets the field dimension and position. * @param box the field dimension and position */ public void setBox(Rectangle box) { if (box == null) { this.box = null; } else { this.box = new Rectangle(box); this.box.normalize(); } }
/** * Rotates the rectangle. * Swaps the values of llx and lly and of urx and ury. * * @return the rotated <CODE>Rectangle</CODE> */ public Rectangle rotate() { Rectangle rect = new Rectangle(lly, llx, ury, urx); rect.setRotation(rotation + 90); return rect; }
/** Gets the size of the barcode grid. */ public Rectangle getBarcodeSize() { paintCode(); return new Rectangle(0, 0, bitColumns, codeRows); }
/** Creates a new event. This constructor will be used if you need to position fields with a Cell Event. * @throws DocumentException * @throws IOException*/ public FieldPositioningEvents(PdfWriter writer, PdfFormField parent, String text) throws IOException, DocumentException { this.parent = parent; TextField tf = new TextField(writer, new Rectangle(0, 0), text); tf.setFontSize(14); cellField = tf.getTextField(); }
/** Creates a new event. This constructor will be used if you need to position fields with a Cell Event. * @throws DocumentException * @throws IOException*/ public FieldPositioningEvents(PdfWriter writer, PdfFormField parent, String text) throws IOException, DocumentException { this.parent = parent; TextField tf = new TextField(writer, new Rectangle(0, 0), text); tf.setFontSize(14); cellField = tf.getTextField(); }
/** Creates a new event. This constructor will be used if you need to position fields with a Cell Event. * @throws DocumentException * @throws IOException*/ public FieldPositioningEvents(PdfWriter writer, String text) throws IOException, DocumentException { this.fieldWriter = writer; TextField tf = new TextField(writer, new Rectangle(0, 0), text); tf.setFontSize(14); cellField = tf.getTextField(); }
/** Gets the size of the barcode grid. */ public Rectangle getBarcodeSize() { return new Rectangle(0, 0, bm.getWidth(), bm.getHeight()); } }
public Rectangle getDocumentArtBox() { return new Rectangle( documentMargin.marginLeft, documentMargin.marginBottom, pageSize.getWidth() - documentMargin.marginRight, pageSize.getHeight() - documentMargin.marginTop); }
public PdfAnnotation createAnnotation(PdfWriter writer) { PdfAnnotation annotation = writer.createAnnotation(new Rectangle(llx, lly, urx, ury), null); if (newPage != 0) { PdfIndirectReference ref = writer.getPageReference(newPage); destination.set(0, ref); } if (destination != null) annotation.put(PdfName.DEST, destination); annotation.hashMap.putAll(parameters); return annotation; }
public PdfAnnotation createAnnotation(PdfWriter writer) { PdfAnnotation annotation = writer.createAnnotation(new Rectangle(llx, lly, urx, ury), null); if (newPage != 0) { PdfIndirectReference ref = writer.getPageReference(newPage); destination.set(0, ref); } if (destination != null) annotation.put(PdfName.DEST, destination); annotation.hashMap.putAll(parameters); return annotation; }
/** * Returns the high level version of this PdfRectangle * @return this PdfRectangle translated to class Rectangle */ public Rectangle getRectangle() { return new Rectangle(left(), bottom(), right(), top()); }
/** * Returns the high level version of this PdfRectangle * @return this PdfRectangle translated to class Rectangle */ public Rectangle getRectangle() { return new Rectangle(left(), bottom(), right(), top()); }
/** Normalizes a <CODE>Rectangle</CODE> so that llx and lly are smaller than urx and ury. * @param box the original rectangle * @return a normalized <CODE>Rectangle</CODE> */ public static Rectangle getNormalizedRectangle(final PdfArray box) { float llx = ((PdfNumber)getPdfObjectRelease(box.getPdfObject(0))).floatValue(); float lly = ((PdfNumber)getPdfObjectRelease(box.getPdfObject(1))).floatValue(); float urx = ((PdfNumber)getPdfObjectRelease(box.getPdfObject(2))).floatValue(); float ury = ((PdfNumber)getPdfObjectRelease(box.getPdfObject(3))).floatValue(); return new Rectangle(Math.min(llx, urx), Math.min(lly, ury), Math.max(llx, urx), Math.max(lly, ury)); }
private void createBlankN0() { PdfTemplate t = app[0] = new PdfTemplate(writer); t.setBoundingBox(new Rectangle(100, 100)); writer.addDirectTemplateSimple(t, new PdfName("n0")); t.setLiteral("% DSBlank\n"); }
private void createBlankN0() { PdfTemplate t = app[0] = new PdfTemplate(writer); t.setBoundingBox(new Rectangle(100, 100)); writer.addDirectTemplateSimple(t, new PdfName("n0")); t.setLiteral("% DSBlank\n"); }
public void writeNextDocument(int initialPageNo) throws DocumentException, IOException { List pages = _root.getLayer().getPages(); RenderingContext c = newRenderingContext(); c.setInitialPageNo(initialPageNo); PageBox firstPage = (PageBox) pages.get(0); com.itextpdf.text.Rectangle firstPageSize = new com.itextpdf.text.Rectangle(0, 0, firstPage.getWidth(c) / _dotsPerPoint, firstPage.getHeight(c) / _dotsPerPoint); _outputDevice.setStartPageNo(_writer.getPageNumber()); _pdfDoc.setPageSize(firstPageSize); _pdfDoc.newPage(); writePDF(pages, c, firstPageSize, _pdfDoc, _writer); }