List of usage examples for com.itextpdf.text.pdf PdfContentByte rectangle
public void rectangle(final double x, final double y, final double w, final double h)
From source file:org.javad.stamp.pdf.PdfGenerator.java
License:Apache License
protected void generatePage(GenerateBean bean, PdfWriter writer, float center, Element elm, int currentPage) { EventBus.publish(new StatusEvent(StatusType.Progress, currentPage)); EventBus.publish(new StatusEvent(StatusType.Message, MessageFormat.format(Resources.getString("message.generatingPage"), (currentPage)))); Object p = factory.getParser(elm.getTagName()).parse(elm, config); if (p != null) { if (p instanceof Page) { Page page = (Page) p;/* w ww . j a v a2s . c o m*/ ISetContent[] content = new ISetContent[page.getContent().size()]; content = page.getContent().toArray(content); createPage(writer, center, page.getTitle(), content); } else if (p instanceof TitlePage) { TitlePage page = (TitlePage) p; createTitlePage(writer, center, page.getTitlePageContent()); } if (bean.isDrawBorder() || debug || (elm.hasAttribute("border") && Boolean.parseBoolean(elm.getAttribute("border")))) { PdfContentByte handler = writer.getDirectContent(); float width = PdfUtil.convertFromMillimeters( config.getWidth() - config.getMarginLeft() - config.getMarginRight()); float height = PdfUtil.convertFromMillimeters( config.getHeight() - config.getMarginTop() - config.getMarginBottom()); handler.rectangle(PdfUtil.convertFromMillimeters(config.getMarginLeft()), PdfUtil.convertFromMillimeters(config.getMarginBottom()), width, height); handler.stroke(); } } }
From source file:org.javad.stamp.pdf.SetTenant.java
License:Apache License
void drawBorder(PdfContentByte content, OutputBounds rect) { content.setColorStroke(BaseColor.BLACK); content.setLineWidth(0.8f);/*from w w w .j a v a 2 s. co m*/ content.rectangle(rect.x, rect.y, rect.width, rect.height); content.stroke(); }
From source file:org.javad.stamp.pdf.StampBox.java
License:Apache License
private void drawPath(PdfContentByte content, OutputBounds rect) { switch (shape) { case rectangle: content.rectangle(rect.x, rect.y, rect.width, rect.height); break;//from ww w . ja va2s .c o m case triangle: // calculation of delta x based on triangle and cosine dimensions //float delta_x = (getPadding() / 2.0f) * (rect.width / 2.0f) / (float) Math.sqrt(Math.pow(rect.height, 2.0) + Math.pow(rect.width / 2.0, 2.0)); content.moveTo(rect.x, rect.y); content.lineTo(rect.x + rect.width, rect.y); content.lineTo(rect.x + rect.width / 2.0f, rect.y + rect.height); content.lineTo(rect.x, rect.y); break; case triangleInverted: content.moveTo(rect.x + rect.width / 2.0f, rect.y); content.lineTo(rect.x + rect.width, rect.y + rect.height); content.lineTo(rect.x, rect.y + rect.height); content.lineTo(rect.x + rect.width / 2.0f, rect.y); break; case diamond: content.moveTo(rect.x, rect.y + rect.height / 2.0f); content.lineTo(rect.x + rect.width / 2.0f, rect.y); content.lineTo(rect.x + rect.width, rect.y + rect.height / 2.0f); content.lineTo(rect.x + rect.width / 2.0f, rect.y + rect.height); content.lineTo(rect.x, rect.y + rect.height / 2.0f); break; } }
From source file:PDF.CrearPDF_Ficha.java
public static void drawRectangle(PdfContentByte content, float x, float y, float width, float height) { try {// w w w. j a v a 2 s . com content.saveState(); PdfGState state = new PdfGState(); content.setGState(state); content.setRGBColorFill(232, 232, 232); content.setColorStroke(BaseColor.BLUE); content.setLineWidth((float) .5); content.rectangle(x, y, width, height); content.fillStroke(); content.restoreState(); BaseFont bf = BaseFont.createFont(); float fontSize = 15f; Phrase phrase = new Phrase("Foto", new Font(bf, fontSize)); ColumnText.showTextAligned(content, Element.ALIGN_CENTER, phrase, 475, 687, 0); } catch (DocumentException ex) { Logger.getLogger(CrearPDF_Ficha.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CrearPDF_Ficha.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:printInv.GenerateInvoice.java
public void generateLayout(Document doc, PdfContentByte cb) { try {//from w w w.ja va 2 s.co m cb.setLineWidth(1f); // Invoice Header box layout cb.rectangle(420, 700, 150, 60); cb.moveTo(420, 720); cb.lineTo(570, 720); cb.moveTo(420, 740); cb.lineTo(570, 740); cb.moveTo(480, 700); cb.lineTo(480, 760); cb.stroke(); // Invoice Header box Text Headings createHeadings(cb, 422, 743, "Invoice No."); createHeadings(cb, 422, 723, "Name"); createHeadings(cb, 422, 703, "Invoice Date"); // Invoice Detail box layout cb.rectangle(20, 50, 550, 600); cb.moveTo(20, 630); cb.lineTo(570, 630); cb.moveTo(50, 50); cb.lineTo(50, 650); cb.moveTo(360, 50); cb.lineTo(360, 650); cb.moveTo(430, 50); cb.lineTo(430, 650); cb.moveTo(500, 50); cb.lineTo(500, 650); cb.stroke(); // Invoice Detail box Text Headings createHeadings(cb, 22, 633, "SNo."); createHeadings(cb, 52, 633, "Product ID"); createHeadings(cb, 362, 633, "Quantity"); createHeadings(cb, 432, 633, "Unit Price"); createHeadings(cb, 502, 633, "Line Total"); //add the images Image companyLogo = Image.getInstance("src/image/icon.png"); companyLogo.setAbsolutePosition(25, 700); companyLogo.scalePercent(25); doc.add(companyLogo); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:ryerson.daspub.artifact.PublishQRTagSheetTask.java
License:Open Source License
/** * Draw rectangle/*from w w w . j av a 2 s. co m*/ * @param Writer * @param x Start X coordinate * @param y Start Y coordinate * @param w Width * @param h Height * @param t Stroke thickness */ private static void drawRectangle(PdfWriter Writer, int x, int y, int w, int h, float t) { PdfContentByte cb = Writer.getDirectContent(); cb.rectangle(x, y, w, h); cb.setLineWidth(t); cb.stroke(); }
From source file:se.billes.pdf.renderer.model.QRCode.java
License:Open Source License
@SuppressWarnings("unchecked") public void onRender(PdfContentByte cb) throws PdfRenderException { float[] positions = new BlockFactory().getBoundsInPs(this); try {/*from w w w . java2 s . c o m*/ @SuppressWarnings("rawtypes") Hashtable hintMap = new Hashtable(); hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); PdfDocument req = getPage().getPdfDocument(); QRCodeWriter qrCodeWriter = new QRCodeWriter(); BitMatrix byteMatrix = qrCodeWriter.encode(getText(), BarcodeFormat.QR_CODE, (int) (positions[2]), (int) (positions[3]), hintMap); int matrixWidth = byteMatrix.getWidth(); int matrixHeight = byteMatrix.getHeight(); float pageHeight = req.getSize()[1]; float top = getPosition()[1]; if (getPage().getPdfDocument().getCutmarks() != null) { pageHeight += SizeFactory.CUT_MARK * 2; top += SizeFactory.CUT_MARK; } cb.setColorFill(getBaseColor()); float pageHeightInPs = SizeFactory.millimetersToPostscriptPoints(pageHeight); float topInPs = SizeFactory.millimetersToPostscriptPoints(top); for (int i = byteMatrix.getTopLeftOnBit()[0]; i < matrixWidth; i++) { for (int j = byteMatrix.getTopLeftOnBit()[0]; j < matrixHeight; j++) { if (byteMatrix.get(i, j)) { cb.rectangle(positions[0] + (i - byteMatrix.getTopLeftOnBit()[0]), pageHeightInPs - ((topInPs + 1) + (j - byteMatrix.getTopLeftOnBit()[0])), 1, 1); } } } cb.fill(); cb.setColorFill(new ColorFactory().getBlack()); } catch (Exception e) { } }
From source file:se.inera.intyg.intygstyper.fk7263.pdf.PdfAbstractGenerator.java
License:Open Source License
protected void createSignatureNotRequiredField(PdfStamper pdfStamper, int lastPage) throws DocumentException, IOException { PdfContentByte addOverlay; addOverlay = pdfStamper.getOverContent(lastPage); addOverlay.saveState();// w ww .ja v a 2 s.co m addOverlay.setColorFill(SIGNATURE_NOT_REQUIRED_COLOR); addOverlay.setColorStroke(CMYKColor.BLACK); addOverlay.rectangle(SIGNATURE_NOT_REQUIRED_START_X, SIGNATURE_NOT_REQUIRED_START_Y, SIGNATURE_NOT_REQUIRED_WIDTH, SIGNATURE_NOT_REQUIRED_HEIGHT); addOverlay.setLineWidth(LINE_WIDTH); addOverlay.fillStroke(); addOverlay.restoreState(); // Do text addOverlay = pdfStamper.getOverContent(lastPage); addOverlay.saveState(); BaseFont bf = BaseFont.createFont(); addOverlay.beginText(); addOverlay.setFontAndSize(bf, SIGNATURE_NOT_REQUIRED_FONT_SIZE); addOverlay.setTextMatrix(SIGNATURE_NOT_REQUIRED_START_X + SIGNATURE_NOT_REQUIRED_PADDING_LEFT, SIGNATURE_NOT_REQUIRED_START_Y + SIGNATURE_NOT_REQUIRED_PADDING_BOTTOM); addOverlay.showText(SIGNATURE_NOT_REQUIRED_TEXT); addOverlay.endText(); addOverlay.restoreState(); }
From source file:se.inera.intyg.intygstyper.fk7263.pdf.PdfAbstractGenerator.java
License:Open Source License
protected void maskSendToFkInformation(PdfStamper pdfStamper) { PdfContentByte addOverlay; addOverlay = pdfStamper.getOverContent(1); addOverlay.saveState();/* ww w. ja v a 2 s . c o m*/ addOverlay.setColorFill(CMYKColor.WHITE); addOverlay.setColorStroke(CMYKColor.WHITE); addOverlay.rectangle(MASK_START_X, MASK_START_Y, MASK_WIDTH, MASK_HEIGTH); addOverlay.fillStroke(); addOverlay.restoreState(); }
From source file:se.inera.intyg.intygstyper.fk7263.pdf.PdfAbstractGenerator.java
License:Open Source License
protected void mark(PdfStamper pdfStamper, String watermarkText, int startX, int startY, int height, int width) throws DocumentException, IOException { PdfContentByte addOverlay; addOverlay = pdfStamper.getOverContent(1); addOverlay.saveState();/*w w w .j a va2 s . com*/ addOverlay.setColorFill(CMYKColor.WHITE); addOverlay.setColorStroke(CMYKColor.RED); addOverlay.rectangle(startX, startY, width, height); addOverlay.stroke(); addOverlay.restoreState(); // Do text addOverlay = pdfStamper.getOverContent(1); ColumnText ct = new ColumnText(addOverlay); BaseFont bf = BaseFont.createFont(); Font font = new Font(bf, WATERMARK_FONTSIZE); int llx = startX + WATERMARK_TEXT_PADDING; int lly = startY + WATERMARK_TEXT_PADDING; int urx = llx + width - 2 * WATERMARK_TEXT_PADDING; int ury = lly + height - 2 * WATERMARK_TEXT_PADDING; Phrase phrase = new Phrase(watermarkText, font); ct.setSimpleColumn(phrase, llx, lly, urx, ury, WATERMARK_FONTSIZE, Element.ALIGN_LEFT | Element.ALIGN_TOP); ct.go(); }