/** {@inheritDoc} */ @Override public void onOpenDocument(PdfWriter writer, Document document) { cb = writer.getDirectContent(); template = cb.createTemplate(50, 50); }
PdfContentByte cb = writer.getDirectContent(); float entireHeight = _numberOfPages * _pageHeight; PdfTemplate hugeTempl = cb.createTemplate( 0, -entireHeight, pageWidth, _pageHeight ); g2 = hugeTempl.createGraphics(0, -entireHeight, _pageWidth, _pageHeight ); draw(g2); g2.dispose(); for (int curPg = 0; curPg < _numberOfPages; ++curPg) { cb.addTemplateSimple( hugeTempl, 0, -_pageHeight * curPg ); document.newPage(); }
PdfContentByte cb = writer.getDirectContent(); PdfTemplate map = cb.createTemplate(6000, 6000); drawSvg(map, CITY); cb.addTemplate(map, 0, 0);
/** * Creates a new template. * <P> * Creates a new template that is nothing more than a form XObject. This template can be included * in this <CODE>PdfContentByte</CODE> or in another template. Templates are only written * to the output when the document is closed permitting things like showing text in the first page * that is only defined in the last page. * * @param width the bounding box width * @param height the bounding box height * @return the created template */ public PdfTemplate createTemplate(float width, float height) { return createTemplate(width, height, null); }
PdfContentByte canvas = writer.getDirectContent(); PdfTemplate template = canvas.createTemplate( table.getTotalWidth(), table.getTotalHeight());
public Image createBarcode(PdfContentByte cb, String text, float mh, float mw) throws BadElementException { BarcodePDF417 pf = new BarcodePDF417(); pf.setText("BarcodePDF417 barcode"); Rectangle size = pf.getBarcodeSize(); PdfTemplate template = cb.createTemplate( mw * size.getWidth(), mh * size.getHeight()); pf.placeBarcode(template, BaseColor.BLACK, mh, mw); return Image.getInstance(template); }
PdfContentByte canvas = writer.getDirectContent(); int origWidth = myPanel.getWidth(); int origHeight = myPanel.getHeight(); PdfTemplate template = canvas.createTemplate(origWidth, origHeight); Graphics2D g2 = new PdfGraphics2D(template, origWidth, origHeight); myPanel.paint(g2); g2.dispose(); Image image = Image.getInstance(template); float width = document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(); image.scaleToFit(width, 1000); document.add(image)
String text = "\u0936\u093e\u0902\u0924\u093f"; PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(100, 50); Graphics2D g2 = tp.createGraphicsShapes(100, 50); java.awt.Font font = new java.awt.Font( "Arial Unicode MS", java.awt.Font.PLAIN, 12); g2.setFont(font); g2.drawString("Graphics2D: " + text, 0, 40); g2.dispose(); cb.addTemplate(tp, 36, 750);
/** {@inheritDoc} */ @Override public void onOpenDocument(PdfWriter writer, Document document) { cb = writer.getDirectContent(); template = cb.createTemplate(50, 50); }
int w = 400; int h = 150; PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D g2 = tp.createGraphicsShapes(w, h); g2.drawString("your persian text", 20, 100); // put your persian text in place of "your persian text" ,above. g2.dispose(); cb.addTemplate(tp, 50, 400);
public PdfTemplate createPdfTemplate(float width, float height) { return getPdfContent().createTemplate(width, height); }
/** Creates a template with the barcode. * @param cb the <CODE>PdfContentByte</CODE> to create the template. It * serves no other use * @param barColor the color of the bars. It can be <CODE>null</CODE> * @param textColor the color of the text. It can be <CODE>null</CODE> * @return the template * @see #placeBarcode(PdfContentByte cb, Color barColor, Color textColor) */ public PdfTemplate createTemplateWithBarcode(PdfContentByte cb, Color barColor, Color textColor) { PdfTemplate tp = cb.createTemplate(0, 0); Rectangle rect = placeBarcode(tp, barColor, textColor); tp.setBoundingBox(rect); return tp; }
/** * Methode qui ajoute une image dans le fichier pdf * @param BufferedImage image a insrer * @author Adrien Hadoux */ public static void addImageToPdf(BufferedImage _img,PdfWriter _writer,int w,int h){ PdfContentByte cb = _writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D graphics = tp.createGraphics(w, h); //-- dessin de l'image --// graphics.drawImage(_img,0,0,null); graphics.dispose(); cb.addTemplate(tp, 0, 0); }
/** * Methode qui ajoute une image dans le fichier pdf * @param BufferedImage image a insrer * @author Adrien Hadoux */ public static void addImageToPdf(BufferedImage _img,PdfWriter _writer,int w,int h){ PdfContentByte cb = _writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(w, h); Graphics2D graphics = tp.createGraphics(w, h); //-- dessin de l'image --// graphics.drawImage(_img,0,0,null); graphics.dispose(); cb.addTemplate(tp, 0, 0); }
/** Creates a template with the barcode. * @param cb the <CODE>PdfContentByte</CODE> to create the template. It * serves no other use * @param barColor the color of the bars. It can be <CODE>null</CODE> * @param textColor the color of the text. It can be <CODE>null</CODE> * @return the template * @see #placeBarcode(PdfContentByte cb, Color barColor, Color textColor) */ public PdfTemplate createTemplateWithBarcode(PdfContentByte cb, Color barColor, Color textColor) { PdfTemplate tp = cb.createTemplate(0, 0); Rectangle rect = placeBarcode(tp, barColor, textColor); tp.setBoundingBox(rect); return tp; }
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); }
/** * Initializes context size. * * @param rectangle rectangle */ public void initSize(Rectangle rectangle) { template = writer.getDirectContent().createTemplate(rectangle.getWidth(), rectangle.getHeight()); }
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); }
Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("big-panel.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(PageSize.A4.getWidth(), 3 * PageSize.A4.getHeight()); // draw all your content on tp cb.addTemplate(tp, 0, -2 * PageSize.A4.getHeight()); document.newPage(); cb.addTemplate(tp, 0, -PageSize.A4.getHeight()); document.newPage(); cb.addTemplate(tp, 0, 0); document.newPage(); cb.addTemplate(tp, 0.3333f, 0, 0, 0.3333f, PageSize.A4.getWidth() / 3, 0); document.close();
public void onOpenDocument(PdfWriter writer, Document document){ cb_ = writer.getDirectContent(); template_ = cb_.createTemplate(50,50); float width = document.right() - document.left(); headerX_ = (PAGEMARGIN_LEFT + width - PdfUtils.BASEFONT_GOTHIC.getWidthPoint(headerTitle_,size_))/2; headerY_ = document.top() + PAGEMARGIN_TOP/2; footerX_ = (PAGEMARGIN_LEFT + width - PdfUtils.BASEFONT_GOTHIC.getWidthPoint(FOOTERPREFIX + " " + FOOTERMIDDLE + " ",size_))/2; }