/** {@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 static void absText(String text, int x, int y) { try { PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); cb.saveState(); cb.beginText(); cb.moveText(x, y); cb.setFontAndSize(bf, 12); cb.showText(text); cb.endText(); cb.restoreState(); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
/** * Shows the <CODE>text</CODE> kerned. * * @param text the text to write */ public void showTextKerned(String text) { if (state.fontDetails == null) throw new NullPointerException("Font and size must be set before writing any text"); BaseFont bf = state.fontDetails.getBaseFont(); if (bf.hasKernPairs()) showText(getKernArray(text, bf)); else showText(text); }
/** * Shows the <CODE>text</CODE> kerned. * * @param text the text to write */ public void showTextKerned(String text) { if (state.fontDetails == null) throw new NullPointerException(MessageLocalization.getComposedMessage("font.and.size.must.be.set.before.writing.any.text")); BaseFont bf = state.fontDetails.getBaseFont(); if (bf.hasKernPairs()) showText(getKernArray(text, bf)); else showText(text); }
/** * Shows the <CODE>text</CODE> kerned. * * @param text the text to write */ public void showTextKerned(String text) { if (state.fontDetails == null) throw new NullPointerException(MessageLocalization.getComposedMessage("font.and.size.must.be.set.before.writing.any.text")); BaseFont bf = state.fontDetails.getBaseFont(); if (bf.hasKernPairs()) showText(getKernArray(text, bf)); else showText(text); }
int pageCount = 0; @Override public void onEndPage(PdfWriter writer, Document document) { PdfContentByte imp = writer.getDirectContent(); imp.beginText(); //Play around here and adjust to values that fit nicely on your page imp.setTextMatrix(65f, 30f); imp.showText("Page " + (++pageCount)); //End Text imp.endText(); }
PdfContentByte over = ...; over.setFontAndSize(bf, 50); over.beginText(); over.setTextMatrix(110, 384); over.showText("Hello World!"); over.endText();
public void drawString(String s, float x, float y, JustificationInfo info) { if (s.length() == 0) return; PdfContentByte cb = _currentPage; ensureFillColor(); AffineTransform at = (AffineTransform)getTransform().clone(); at.translate(x, y); AffineTransform inverse = normalizeMatrix(at); AffineTransform flipper = AffineTransform.getScaleInstance(1, -1); inverse.concatenate(flipper); inverse.scale(_dotsPerPoint, _dotsPerPoint); double[] mx = new double[6]; inverse.getMatrix(mx); cb.beginText(); cb.setFontAndSize(_font.getFontDescription().getFont(), _font.getSize2D() / _dotsPerPoint); cb.setTextMatrix((float)mx[0], (float)mx[1], (float)mx[2], (float)mx[3], (float)mx[4], (float)mx[5]); if (info == null) { cb.showText(s); } else { PdfTextArray array = makeJustificationArray(s, info); cb.showText(array); } cb.endText(); }
public void drawString(String s, float x, float y, JustificationInfo info) { if (s.length() == 0) return; PdfContentByte cb = _currentPage; ensureFillColor(); AffineTransform at = (AffineTransform)getTransform().clone(); at.translate(x, y); AffineTransform inverse = normalizeMatrix(at); AffineTransform flipper = AffineTransform.getScaleInstance(1, -1); inverse.concatenate(flipper); inverse.scale(_dotsPerPoint, _dotsPerPoint); double[] mx = new double[6]; inverse.getMatrix(mx); cb.beginText(); cb.setFontAndSize(_font.getFontDescription().getFont(), _font.getSize2D() / _dotsPerPoint); cb.setTextMatrix((float)mx[0], (float)mx[1], (float)mx[2], (float)mx[3], (float)mx[4], (float)mx[5]); if (info == null) { cb.showText(s); } else { PdfTextArray array = makeJustificationArray(s, info); cb.showText(array); } cb.endText(); }
private void printPageNumber(final PdfWriter writer, final Document document) { PdfContentByte cb = writer.getDirectContent(); cb.saveState(); float textBase = document.bottom() - 20; try { cb.setFontAndSize( BaseFont.createFont("Helvetica", BaseFont.WINANSI, false), 12); } catch (DocumentException e) { LOG.error("Can not print page number", e); } catch (IOException e) { LOG.error("Can not print page number", e); } cb.beginText(); cb.setTextMatrix(document.right() - 10, textBase); cb.showText(String.valueOf(writer.getPageNumber())); cb.endText(); cb.saveState(); } }
void writeLine(PdfLine line, PdfContentByte text, PdfContentByte graphics) { PdfFont currentFont = null; PdfChunk chunk; for (Iterator j = line.iterator(); j.hasNext(); ) { chunk = (PdfChunk) j.next(); if (chunk.font().compareTo(currentFont) != 0) { currentFont = chunk.font(); text.setFontAndSize(currentFont.getFont(), currentFont.size()); } Color color = chunk.color(); if (color != null) text.setColorFill(color); text.showText(chunk.toString()); if (color != null) text.resetRGBColorFill(); } }
void writeLine(PdfLine line, PdfContentByte text, PdfContentByte graphics) { PdfFont currentFont = null; PdfChunk chunk; for (Iterator j = line.iterator(); j.hasNext(); ) { chunk = (PdfChunk) j.next(); if (chunk.font().compareTo(currentFont) != 0) { currentFont = chunk.font(); text.setFontAndSize(currentFont.getFont(), currentFont.size()); } Color color = chunk.color(); if (color != null) text.setColorFill(color); text.showText(chunk.toString()); if (color != null) text.resetRGBColorFill(); } }
void writeLine(PdfLine line, PdfContentByte text, PdfContentByte graphics) { PdfFont currentFont = null; PdfChunk chunk; for (Iterator j = line.iterator(); j.hasNext(); ) { chunk = (PdfChunk) j.next(); if (chunk.font().compareTo(currentFont) != 0) { currentFont = chunk.font(); text.setFontAndSize(currentFont.getFont(), currentFont.size()); } Color color = chunk.color(); if (color != null) text.setColorFill(color); text.showText(chunk.toString()); if (color != null) text.resetRGBColorFill(); } }
/** {@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); }
PdfContentByte content= stamper.getUnderContent(1); LocationTextExtractionStrategy lteStrategy = new LocationTextExtractionStrategy(); String texte= PdfTextExtractor.getTextFromPage(read, 1, lteStrategy); pdflayer= new PdfLayer("Overrite", stamper.getWriter()); content.setColorFill(BaseColor.BLACK); content.beginLayer(pdflayer); content.fill(); PdfGState pgState = new PdfGState(); content.setGState(pgState); content.setColorFill(BaseColor.WHITE); content.setCharacterSpacing((float)6); content.beginText(); content.setTextMatrix(15, 385); content.showText("hello"); content.endText(); content.endLayer(); stamper.close(); read.close();
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(); }
@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 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); }
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(); }