/** {@inheritDoc} */ @Override public void onEndPage(PdfWriter writer, Document document) { final int pageN = writer.getPageNumber(); final String text = pageN + " / "; final float len = bf.getWidthPoint(text, 8); cb.beginText(); cb.setFontAndSize(bf, 8); final float width = document.getPageSize().getWidth(); cb.setTextMatrix(width / 2, 30); cb.showText(text); cb.endText(); cb.addTemplate(template, width / 2 + len, 30); }
class PDFBackground extends PdfPageEventHelper { @Override void onEndPage(PdfWriter writer, Document document) { Image background = Image.getInstance("myimage.png"); // This scales the image to the page, // use the image's width & height if you don't want to scale. float width = document.getPageSize().getWidth(); float height = document.getPageSize().getHeight(); writer.getDirectContentUnder() .addImage(background, width, 0, 0, height, 0, 0); } }
class PDFBackground extends PdfPageEventHelper { @Override public void onEndPage(PdfWriter writer, Document document) { try { Image background = Image.getInstance("F:/gmc_report.jpg"); background.setAbsolutePosition(250, 500); // This scales the image to the page, // use the image's width & height if you don't want to scale. float width = document.getPageSize().getWidth(); float height = document.getPageSize().getHeight(); writer.getDirectContentUnder().addImage(background, false); } catch (DocumentException ex) { Logger.getLogger(MoneryRecipt.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(MoneryRecipt.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MoneryRecipt.class.getName()).log(Level.SEVERE, null, ex); } }
public void setOrientation( PageOrientation orientation ) { if ( !this.orientation.equals( orientation ) ) { super.getPageSize().rotate(); } this.orientation = orientation; } }
public void setOrientation( PageOrientation orientation ) { if ( !this.orientation.equals( orientation ) ) { super.getPageSize().rotate(); } this.orientation = orientation; } }
private void pathBox(int x1, int y1, int width, int height,int curve) { if (curve==0) { cb.rectangle( (x1+xofs)/10.0f, document.getPageSize().getHeight()-(y1+yofs)/10.0f, width/10.0f, height/-10.0f); } else { cb.roundRectangle( (x1+xofs)/10.0f, document.getPageSize().getHeight()-(y1+yofs)/10.0f, width/10.0f, height/-10.0f,curve/10.0f); } }
public static float getPageWidth(Document doc) { return doc.getPageSize().width() - doc.leftMargin() - doc.rightMargin(); }
public static float getPageHeight(Document doc) { return doc.getPageSize().height() - doc.topMargin() - doc.bottomMargin(); }
private float getHeadTopMargin(Document doc, PdfPTable table) { return doc.getPageSize().height() - doc.topMargin() + table.getTotalHeight(); }
@Override public void drawLine(int x1, int y1, int x2, int y2, int width) { //cb.closePath(); cb.setColorStroke(color); cb.setLineWidth(width/10.0f); cb.moveTo( (xofs+x1)/10f, document.getPageSize().getHeight()-(y1+yofs)/10.0f); cb.lineTo( (xofs+x2)/10f, document.getPageSize().getHeight()-(y2+yofs)/10.0f); cb.stroke(); }
public class Background extends PdfPageEventHelper { @Override public void onEndPage(PdfWriter writer, Document document) { int pagenumber = writer.getPageNumber(); if (pagenumber % 2 == 1 && pagenumber != 1) return; PdfContentByte canvas = writer.getDirectContentUnder(); Rectangle rect = document.getPageSize(); canvas.setColorFill(pagenumber < 3 ? BaseColor.BLUE : BaseColor.LIGHT_GRAY); canvas.rectangle(rect.getLeft(), rect.getBottom(), rect.getWidth(), rect.getHeight()); canvas.fill(); } }
@Override public void drawImage(Image img, int x, int y, int width, int height) { try { cb.addImage(com.lowagie.text.Image.getInstance(img,null), width/10.0f,0,0,height/10.0f, (xofs+x)/10.0f, document.getPageSize().getHeight()-(y+yofs+height)/10.0f ); } catch (BadElementException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
public class RedBorder extends PdfPageEventHelper { @Override public void onEndPage(PdfWriter writer, Document document) { PdfContentByte canvas = writer.getDirectContent(); Rectangle rect = document.getPageSize(); rect.setBorder(Rectangle.BOX); // left, right, top, bottom border rect.setBorderWidth(5); // a width of 5 user units rect.setBorderColor(BaseColor.RED); // a red border rect.setUseVariableBorders(true); // the full width will be visible canvas.rectangle(rect); } }
final Rectangle pageSize = document.getPageSize(); final PdfContentByte directContent = writer.getDirectContent();
private void addHeaderAndFooter(PdfWriter writer, Document document) { if (document.getPageNumber() == 1) { return; } String header = docInstallArgs.getDocName() + " version" + docInstallArgs.getVersion(); PdfContentByte directContent = writer.getDirectContent(); Phrase headerPhare = ItextUtil.getFontSelector(9, Font.NORMAL, Color.LIGHT_GRAY).process(header); headerPhare.add(new LineSeparator(0.5f, 2.5f, Color.LIGHT_GRAY, Element.ALIGN_LEFT, -5f)); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, headerPhare, document.left(), document.top() + 20, 0); String footer = Integer.valueOf(document.getPageNumber()).toString(); ColumnText.showTextAligned(directContent, Element.ALIGN_LEFT, textbFont.process(footer), document.getPageSize().getWidth() / 2.0f - 20, document.bottom() - 20, 0); }
/** {@inheritDoc} */ @Override public void onEndPage(PdfWriter writer, Document document) { final int pageN = writer.getPageNumber(); final String text = pageN + " / "; final float len = bf.getWidthPoint(text, 8); cb.beginText(); cb.setFontAndSize(bf, 8); final float width = document.getPageSize().getWidth(); cb.setTextMatrix(width / 2, 30); cb.showText(text); cb.endText(); cb.addTemplate(template, width / 2 + len, 30); }
private void formatTable(final PdfPTable table) { Rectangle page = document.getPageSize(); table.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); table.getDefaultCell().setPaddingBottom(tablePaddingBottom); table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); table.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); table.setSpacingBefore(20); }
@Override public void drawString(String text, int x, int y, boolean transparent) { cb.beginText(); if (color!=null) { cb.setColorFill(color); } else { cb.setColorFill(Color.BLACK); } cb.setFontAndSize(font.getBaseFont(),font.getSize()); cb.setTextMatrix((x+xofs)/10, document.getPageSize().getHeight()-(y+yofs)/10 -font.getSize()); cb.showText(text); cb.endText(); }
private void renderSidebar(PdfWriter writer, Document document){ // sidebar cb_.rectangle(0,0,PAGEMARGIN_LEFT/2,document.getPageSize().top()); cb_.setColorFill(cmykSpc_,cmykSpc_.getTint()); cb_.fill(); cb_.resetCMYKColorFill(); // sidebar contents cb_.beginText(); cb_.setFontAndSize(PdfUtils.BASEFONT_GOTHIC,size_*1.5f); cb_.setColorFill(Color.BLUE); cb_.setTextMatrix(0,1,-1,0,PAGEMARGIN_LEFT/3,document.top()/2); cb_.showText(CREATER_APPLICATION); cb_.resetRGBColorFill(); cb_.endText(); }
public Toc() { toc = new Document(PageSize.A4, 50, 50, 110, 50); content = new PdfPTable(2); Rectangle page = toc.getPageSize(); content.setTotalWidth(page.getWidth() - toc.leftMargin() - toc.rightMargin()); content.getDefaultCell().setUseVariableBorders(true); content.getDefaultCell().setBorderColorBottom(Color.WHITE); content.getDefaultCell().setBorderColorRight(Color.WHITE); content.getDefaultCell().setBorderColorLeft(Color.WHITE); content.getDefaultCell().setBorderColorTop(Color.WHITE); content.getDefaultCell().setBorderWidthBottom(2f); }