Java Code Examples for org.apache.pdfbox.pdmodel.edit.PDPageContentStream#beginText()
The following examples show how to use
org.apache.pdfbox.pdmodel.edit.PDPageContentStream#beginText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReportConvertPdf.java From yuzhouwan with Apache License 2.0 | 5 votes |
private static void drawString(PDPageContentStream content, PDFont font, float fontSize, float x, float y, String text) throws IOException { content.beginText(); content.setFont(font, fontSize); content.moveTextPositionByAmount(x, y); content.drawString(text); content.endText(); }
Example 2
Source File: ReportGenerator.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private void writeContent(PDPageContentStream contentStream, float positionX, float positionY, String text) throws IOException { contentStream.beginText(); contentStream.moveTextPositionByAmount(positionX, positionY); contentStream.drawString(text != null ? text : ""); contentStream.endText(); }
Example 3
Source File: TextLine.java From pdfbox-layout with MIT License | 4 votes |
public void drawAligned(PDPageContentStream contentStream, Position upperLeft, Alignment alignment, float availableLineWidth, DrawListener drawListener) throws IOException { contentStream.saveGraphicsState(); contentStream.beginText(); float x = upperLeft.getX(); float y = upperLeft.getY() - getAscent(); // the baseline float offset = TextSequenceUtil.getOffset(this, availableLineWidth, alignment); x += offset; CompatibilityHelper.setTextTranslation(contentStream, x, y); float extraWordSpacing = 0; if (alignment == Alignment.Justify && (getNewLine() instanceof WrappingNewLine) ){ extraWordSpacing = (availableLineWidth - getWidth()) / (styledTextList.size()-1); } FontDescriptor lastFontDesc = null; float lastBaselineOffset = 0; Color lastColor = null; float gap = 0; for (StyledText styledText : styledTextList) { if (!styledText.getFontDescriptor().equals(lastFontDesc)) { lastFontDesc = styledText.getFontDescriptor(); contentStream.setFont(lastFontDesc.getFont(), lastFontDesc.getSize()); } if (!styledText.getColor().equals(lastColor)) { lastColor = styledText.getColor(); contentStream.setNonStrokingColor(lastColor); } if (styledText.getLeftMargin() > 0) { gap += styledText.getLeftMargin(); } boolean moveBaseline = styledText.getBaselineOffset() != lastBaselineOffset; if (moveBaseline || gap > 0) { float baselineDelta = lastBaselineOffset - styledText.getBaselineOffset(); lastBaselineOffset = styledText.getBaselineOffset(); CompatibilityHelper.moveTextPosition(contentStream, gap, baselineDelta); x += gap; } if (styledText.getText().length() > 0) { CompatibilityHelper.showText(contentStream, styledText.getText()); } if (drawListener != null) { float currentUpperLeft = y + styledText.getAsent(); drawListener.drawn(styledText, new Position(x, currentUpperLeft), styledText.getWidthWithoutMargin(), styledText.getHeight()); } x += styledText.getWidthWithoutMargin(); gap = extraWordSpacing; if (styledText.getRightMargin() > 0) { gap += styledText.getRightMargin(); } } contentStream.endText(); contentStream.restoreGraphicsState(); }