public void tableLayout(PdfPTable table, float[][] width, float[] height, int headerRows, int rowStart, PdfContentByte[] canvas) { float widths[] = width[0]; float x1 = widths[0]; float x2 = widths[widths.length - 1]; float y = height[height.length - 1]; PdfContentByte cb = canvas[PdfPTable.LINECANVAS]; cb.moveTo(x1, y); cb.lineTo(x2, y); cb.stroke(); }
PdfContentByte canvas = writer.getDirectContent(); canvas.moveTo(36, 36); canvas.lineTo(559, 36); canvas.stroke();
float b = 0.4477f; moveTo(x + r, y); lineTo(x + w - r, y); curveTo(x + w - r * b, y, x + w, y + r * b, x + w, y + r); lineTo(x + w, y + h - r); curveTo(x + w, y + h - r * b, x + w - r * b, y + h, x + w - r, y + h); lineTo(x + r, y + h); curveTo(x + r * b, y + h, x, y + h - r * b, x, y + h - r); lineTo(x, y + r); curveTo(x, y + r * b, x + r * b, y, x + r, y);
float b = 0.4477f; moveTo(x + r, y); lineTo(x + w - r, y); curveTo(x + w - r * b, y, x + w, y + r * b, x + w, y + r); lineTo(x + w, y + h - r); curveTo(x + w, y + h - r * b, x + w - r * b, y + h, x + w - r, y + h); lineTo(x + r, y + h); curveTo(x + r * b, y + h, x, y + h - r * b, x, y + h - r); lineTo(x, y + r); curveTo(x, y + r * b, x + r * b, y, x + r, y);
float b = 0.4477f; moveTo(x + r, y); lineTo(x + w - r, y); curveTo(x + w - r * b, y, x + w, y + r * b, x + w, y + r); lineTo(x + w, y + h - r); curveTo(x + w, y + h - r * b, x + w - r * b, y + h, x + w - r, y + h); lineTo(x + r, y + h); curveTo(x + r * b, y + h, x, y + h - r * b, x, y + h - r); lineTo(x, y + r); curveTo(x, y + r * b, x + r * b, y, x + r, y);
class DottedHeader implements PdfPTableEvent { public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { PdfContentByte canvas = canvases[PdfPTable.LINECANVAS]; canvas.setLineDash(3f, 3f); float x1 = widths[0][0]; float x2 = widths[0][widths.length]; canvas.moveTo(x1, heights[0]); canvas.lineTo(x2, heights[0]); canvas.moveTo(x1, heights[headerRows]); canvas.lineTo(x2, heights[headerRows]); canvas.stroke(); } }
Type3Font t3 = new Type3Font(writer, true); // Delta PdfContentByte d = t3.defineGlyph('D', 600, 0, 0, 600, 700); d.setColorStroke(new BaseColor(0xFF, 0x00, 0x00)); d.setColorFill(new GrayColor(0.7f)); d.setLineWidth(100); d.moveTo(5, 5); d.lineTo(300, 695); d.lineTo(595, 5); d.closePathFillStroke(); //Sigma PdfContentByte s = t3.defineGlyph('S', 600, 0, 0, 600, 700); s.setColorStroke(new BaseColor(0x00, 0x80, 0x80)); s.setLineWidth(100); s.moveTo(595,5); s.lineTo(5, 5); s.lineTo(300, 350); s.lineTo(5, 695); s.lineTo(595, 695); s.stroke(); // Use as regular font at size 12 Font f = new Font(t3, 12);
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open(); PdfContentByte canvas = writer.getDirectContent(); CMYKColor magentaColor = new CMYKColor(0.f, 1.f, 0.f, 0.f); canvas.setColorStroke(magentaColor); canvas.moveTo(36, 36); canvas.lineTo(36, 806); canvas.lineTo(559, 36); canvas.lineTo(559, 806); canvas.closePathStroke(); document.close(); }
class DottedCells implements PdfPTableEvent { @Override public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { PdfContentByte canvas = canvases[PdfPTable.LINECANVAS]; canvas.setLineDash(3f, 3f); float llx = widths[0][0]; float urx = widths[0][widths[0].length -1]; for (int i = 0; i < heights.length; i++) { canvas.moveTo(llx, heights[i]); canvas.lineTo(urx, heights[i]); } for (int i = 0; i < widths.length; i++) { for (int j = 0; j < widths[i].length; j++) { canvas.moveTo(widths[i][j], heights[i]); canvas.lineTo(widths[i][j], heights[i+1]); } } canvas.stroke(); } }
PdfContentByte canvas = writer.getDirectContent(); canvas.setColorStroke(BaseColor.RED); canvas.setLineWidth(3); canvas.moveTo(220, 330); canvas.lineTo(240, 370); canvas.arc(200, 350, 240, 390, 0, (float) 180); canvas.lineTo(220, 330); canvas.closePathStroke(); canvas.setColorFill(BaseColor.RED); canvas.circle(220, 370, 10); canvas.fill();
PdfContentByte cb = writer.getDirectContentUnder(); cb.saveState(); cb.setLineWidth(1.2); cb.setColor(BaseColor.DARK_GRAY); cb.moveTo(x, y); cb.lineTo(x + width, y); cb.stroke(); cb.restoreState();
class DottedCell implements PdfPCellEvent { public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { PdfContentByte canvas = canvases[PdfPTable.LINECANVAS]; canvas.setLineDash(3f, 3f); canvas.moveTo(position.getLeft(), position.getTop()); canvas.lineTo(position.getRight(), position.getTop()); canvas.moveTo(position.getLeft(), position.getBottom()); canvas.lineTo(position.getRight(), position.getBottom()); canvas.stroke(); } }
float y = line.getEndPoint().get(1); content.moveTo(lx, y); content.lineTo(rx, y); content.stroke();
public void onGenericTag(PdfWriter writer, Document document,Rectangle rect,String text){ float y = (rect.top() + rect.bottom())/2; if(GENERICTAG_HORIZONTAL.equals(text)){ cb_.setLineWidth(linewidth_); cb_.moveTo(document.left()+20,y); cb_.lineTo(document.right()-20,y); cb_.stroke(); }else if(GENERICTAG_TOC.equals(text)){ float x = rect.right() + 20; cb_.setLineWidth(linewidth_); cb_.setLineDash(1.0f,2.0f,0f); cb_.moveTo(x,y); cb_.lineTo(document.right()-80,y); cb_.stroke(); PdfTemplate currentPageTemplate_ = cb_.createTemplate(10,10); cb_.addTemplate(currentPageTemplate_,document.right()-70,y-3); templateList.add(currentPageTemplate_); if(needFooter){ document.resetPageCount(); needFooter = false; } }else if(GENERICTAG_CLOSETOC.equals(text)){ needFooter = true; // document.resetPageCount(); } }
public class UnderlinedCell implements PdfPCellEvent { public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { PdfContentByte canvas = canvases[PdfPTable.LINECANVAS]; canvas.setLineWidth(0.5f); canvas.setLineDash(3f, 3f); canvas.moveTo(position.getLeft(), position.getBottom()); canvas.lineTo(position.getRight(), position.getBottom()); canvas.stroke(); } }
@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 MyPdfPageEvent extends PdfPageEventHelper { public void onGenericTag(PdfWriter writer, Document doc, Rectangle rect, String tag) { PdfContentByte canvas = writer.getDirectContent(); canvas.saveState(); canvas.setColorStroke(Color.BLACK); // or whatever // You can also mess with the line's thickness, endcaps, dash style, etc. // Lots of options to play with. canvas.moveTo(rect.getLeft(), rect.getBottom()); canvas.lineTo(rect.getRight(), rect.getTop()); canvas.stroke(); canvas.restoreState(); } }
private void renderHeader(PdfWriter writer,Document document){ // header lines cb_.moveTo(document.left(),document.top()+10); cb_.lineTo(document.right(),document.top()+10); cb_.stroke(); // header contents cb_.beginText(); cb_.setFontAndSize(PdfUtils.BASEFONT_GOTHIC,size_); cb_.setTextMatrix(headerX_, headerY_); cb_.showText(headerTitle_); cb_.endText(); }
private void renderTitleFooter(PdfWriter writer, Document document){ String text = RomanList.toRomanLowerCase(writer.getPageNumber()); cb_.moveTo(document.left(),PAGEMARGIN_BOTTOM - 5); cb_.lineTo(document.right(),PAGEMARGIN_BOTTOM - 5); cb_.stroke(); // don't forget !! // footer contents cb_.beginText(); cb_.setFontAndSize(PdfUtils.BASEFONT_MINCHO,size_); cb_.setTextMatrix(footerX_, PAGEMARGIN_BOTTOM/2); cb_.showText(text); cb_.endText(); }
private void renderFooter(PdfWriter writer, Document document){ // footer lines // int num = writer.getPageNumber(); int num = document.getPageNumber(); String text = FOOTERPREFIX + num + FOOTERMIDDLE; float len = PdfUtils.BASEFONT_MINCHO.getWidthPoint(text, size_); cb_.moveTo(document.left(),PAGEMARGIN_BOTTOM - 5); cb_.lineTo(document.right(),PAGEMARGIN_BOTTOM - 5); cb_.stroke(); // don't forget !! // footer contents cb_.beginText(); cb_.setFontAndSize(PdfUtils.BASEFONT_MINCHO,size_); cb_.setTextMatrix(footerX_, PAGEMARGIN_BOTTOM/2); cb_.showText(text); cb_.endText(); // adding template point into direct content. cb_.addTemplate(template_,footerX_+len, PAGEMARGIN_BOTTOM/2); }