org.apache.pdfbox.pdmodel.edit.PDPageContentStream Java Examples
The following examples show how to use
org.apache.pdfbox.pdmodel.edit.PDPageContentStream.
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: ReportGenerator.java From carbon-apimgt with Apache License 2.0 | 7 votes |
private void drowTableGrid(PDPageContentStream contentStream, int numberOfRows) throws IOException { float nextY = TABLE_TOP_Y; // draw horizontal lines for (int i = 0; i <= numberOfRows + 1; i++) { contentStream.drawLine(CELL_MARGIN, nextY, CELL_MARGIN + TABLE_WIDTH, nextY); nextY -= ROW_HEIGHT; } // draw vertical lines final float tableYLength = ROW_HEIGHT + (ROW_HEIGHT * numberOfRows); final float tableBottomY = TABLE_TOP_Y - tableYLength; float nextX = CELL_MARGIN; for (int i = 0; i < COLUMN_WIDTH.length; i++) { contentStream.drawLine(nextX, TABLE_TOP_Y, nextX, tableBottomY); nextX += COLUMN_WIDTH[i]; } contentStream.drawLine(CELL_MARGIN + TABLE_WIDTH, TABLE_TOP_Y, CELL_MARGIN + TABLE_WIDTH, tableBottomY); }
Example #2
Source File: CourseCertificatePDFPainter.java From ctsms with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException { PDPageContentStream contentStream = writer.openContentStream(page); PDFUtil.renderTextLine( contentStream, fontA, PDFUtil.FontSize.TINY, Settings.getColor(CourseCertificatePDFSettingCodes.TEXT_COLOR, Bundle.COURSE_CERTIFICATE_PDF, CourseCertificatePDFDefaultSettings.TEXT_COLOR), L10nUtil.getCourseCertificatePDFLabel(Locales.COURSE_CERTIFICATE_PDF, CourseCertificatePDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages), Settings.getFloat(CourseCertificatePDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.COURSE_CERTIFICATE_PDF, CourseCertificatePDFDefaultSettings.PAGE_LEFT_MARGIN) + (pageWidth - Settings.getFloat(CourseCertificatePDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.COURSE_CERTIFICATE_PDF, CourseCertificatePDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings.getFloat(CourseCertificatePDFSettingCodes.PAGE_RIGHT_MARGIN, Bundle.COURSE_CERTIFICATE_PDF, CourseCertificatePDFDefaultSettings.PAGE_RIGHT_MARGIN)) / 2.0f, Settings.getFloat(CourseCertificatePDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.COURSE_CERTIFICATE_PDF, CourseCertificatePDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_CENTER); writer.closeContentStream(); }
Example #3
Source File: HorizontalRuler.java From pdfbox-layout with MIT License | 6 votes |
@Override public void draw(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, DrawListener drawListener) throws IOException { if (getColor() != null) { contentStream.setStrokingColor(getColor()); } if (getStroke() != null) { getStroke().applyTo(contentStream); float x = upperLeft.getX(); float y = upperLeft.getY() - getStroke().getLineWidth() / 2; contentStream.addLine(x, y, x + getWidth(), y); contentStream.stroke(); } if (drawListener != null) { drawListener.drawn(this, upperLeft, getWidth(), getHeight()); } }
Example #4
Source File: TrainingRecordPDFPainter.java From ctsms with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException { PDPageContentStream contentStream = writer.openContentStream(page); PDFUtil.renderTextLine( contentStream, fontA, PDFUtil.FontSize.TINY, Settings.getColor(TrainingRecordPDFSettingCodes.TEXT_COLOR, Bundle.TRAINING_RECORD_PDF, TrainingRecordPDFDefaultSettings.TEXT_COLOR), L10nUtil.getTrainingRecordPDFLabel(Locales.TRAINING_RECORD_PDF, TrainingRecordPDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages), Settings.getFloat(TrainingRecordPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.TRAINING_RECORD_PDF, TrainingRecordPDFDefaultSettings.PAGE_LEFT_MARGIN) + (pageWidth - Settings.getFloat(TrainingRecordPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.TRAINING_RECORD_PDF, TrainingRecordPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings.getFloat( TrainingRecordPDFSettingCodes.PAGE_RIGHT_MARGIN, Bundle.TRAINING_RECORD_PDF, TrainingRecordPDFDefaultSettings.PAGE_RIGHT_MARGIN)), Settings.getFloat(TrainingRecordPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.TRAINING_RECORD_PDF, TrainingRecordPDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_RIGHT); writer.closeContentStream(); }
Example #5
Source File: ProbandListEntryTagsPDFPainter.java From ctsms with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException { PDPageContentStream contentStream = writer.openContentStream(page); PDFUtil.renderTextLine( contentStream, fontA, PDFUtil.FontSize.TINY, Settings.getColor(ProbandListEntryTagsPDFSettingCodes.TEXT_COLOR, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF, ProbandListEntryTagsPDFDefaultSettings.TEXT_COLOR), L10nUtil.getProbandListEntryTagsPDFLabel(Locales.PROBAND_LIST_ENTRY_TAGS_PDF, EcrfPDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages), Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF, ProbandListEntryTagsPDFDefaultSettings.PAGE_LEFT_MARGIN) + (pageWidth - Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF, ProbandListEntryTagsPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings .getFloat( ProbandListEntryTagsPDFSettingCodes.PAGE_RIGHT_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF, ProbandListEntryTagsPDFDefaultSettings.PAGE_RIGHT_MARGIN)) / 2.0f, Settings.getFloat(ProbandListEntryTagsPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.PROBAND_LIST_ENTRY_TAGS_PDF, ProbandListEntryTagsPDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_CENTER); writer.closeContentStream(); }
Example #6
Source File: AbstractShape.java From pdfbox-layout with MIT License | 6 votes |
@Override public void draw(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, float width, float height, Color color, Stroke stroke, DrawListener drawListener) throws IOException { add(pdDocument, contentStream, upperLeft, width, height); if (stroke != null) { stroke.applyTo(contentStream); } if (color != null) { contentStream.setStrokingColor(color); } contentStream.stroke(); if (drawListener != null) { drawListener.drawn(this, upperLeft, width, height); } }
Example #7
Source File: PDFImprinter.java From ctsms with GNU Lesser General Public License v2.1 | 6 votes |
private PDPageContentStream openContentStream(PDPage page, boolean setPageSize, boolean applyPageOrientation) throws IOException { contentStream = new PDPageContentStream(doc, page, true, false); if (painter != null) { PDRectangle pageSize = page.findMediaBox(); if (PageOrientation.LANDSCAPE.equals(painter.getPageOrientation())) { if (setPageSize) { painter.setPageHeight(pageSize.getWidth()); painter.setPageWidth(pageSize.getHeight()); } if (applyPageOrientation) { contentStream.concatenate2CTM(0, 1, -1, 0, pageSize.getWidth(), 0); // cos(theta) sin(theta) -sin(theta) cos(theta) 0 0 cm } } else { if (setPageSize) { painter.setPageHeight(pageSize.getHeight()); painter.setPageWidth(pageSize.getWidth()); } } } return contentStream; }
Example #8
Source File: ReportGenerator.java From carbon-apimgt with Apache License 2.0 | 6 votes |
private void writeRowsContent(PDPageContentStream contentStream, String[] columnHeaders, List<RowEntry> rowEntries) throws IOException { float startX = CELL_MARGIN + CELL_PADDING; // space between entry and the column line float startY = TABLE_TOP_Y - (ROW_HEIGHT / 2) - ((TEXT_FONT.getFontDescriptor().getFontBoundingBox().getHeight() / 1000 * FONT_SIZE) / 4); // write table colum headers writeColumHeader(contentStream, startX, startY, columnHeaders); startY -= ROW_HEIGHT; startX = CELL_MARGIN + CELL_PADDING; // write content for (RowEntry entry : rowEntries) { writeToRow(contentStream, startX, startY, entry); startY -= ROW_HEIGHT; startX = CELL_MARGIN + CELL_PADDING; } }
Example #9
Source File: PDFUtil.java From ctsms with GNU Lesser General Public License v2.1 | 6 votes |
private static void setLineDashPattern(PDPageContentStream contentStream, LineStyle lineStyle) throws IOException { if (contentStream != null) { float[] pattern; float phase; switch (lineStyle) { case DASHED: pattern = new float[] { 3.0f }; phase = 0.0f; break; default: //solid else... pattern = new float[] {}; phase = 0.0f; break; } contentStream.setLineDashPattern(pattern, phase); } }
Example #10
Source File: AbstractShape.java From pdfbox-layout with MIT License | 6 votes |
@Override public void fill(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, float width, float height, Color color, DrawListener drawListener) throws IOException { add(pdDocument, contentStream, upperLeft, width, height); if (color != null) { contentStream.setNonStrokingColor(color); } CompatibilityHelper.fillNonZero(contentStream); if (drawListener != null) { drawListener.drawn(this, upperLeft, width, height); } }
Example #11
Source File: InputFieldPDFBlock.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
private float renderBooleanValue(float x, float y, PDPageContentStream contentStream, InputFieldPDFBlockCursor cursor) throws Exception { boolean isPresetColor = isPreset() || blank; PDFJpeg ximage; if (getBooleanValue(blank)) { ximage = isPresetColor ? cursor.getCheckboxCheckedPresetImage() : cursor.getCheckboxCheckedImage(); } else { ximage = cursor.getCheckboxUncheckedImage(); } PDFUtil.renderImage(contentStream, ximage, x, y, Alignment.TOP_LEFT); return ximage.getHeightPoints(); }
Example #12
Source File: InquiriesPDFPainter.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void drawPageBreakOldPage(PDPageContentStream contentStream) throws Exception { InquiriesPDFBlock block = blocks.get(blockIndex - 1); if (BlockType.INPUT_FIELD.equals(block.getType())) { drawBlock(contentStream, new InquiriesPDFBlock(BlockType.END_OF_CATEGORY, true)); } }
Example #13
Source File: RoundRect.java From pdfbox-layout with MIT License | 5 votes |
/** * Using lines won't give us a continuing path, which looks silly on fill. * So we are approximating lines with bezier curves... is there no better * way? */ private void addLine(final PDPageContentStream contentStream, float x1, float y1, float x2, float y2) throws IOException { float xMid = (x1 + x2) / 2f; float yMid = (y1 + y2) / 2f; CompatibilityHelper.curveTo1(contentStream, xMid, yMid, x2, y2); }
Example #14
Source File: InputFieldPDFBlock.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
private float renderTitle(float x, float y, PDPageContentStream contentStream, InputFieldPDFBlockCursor cursor) throws Exception { return PDFUtil.renderMultilineText( contentStream, cursor.getFontA(), PDFUtil.FontSize.MEDIUM, getTextColor(), getInputFieldTitle(), x + getXFrameIndent(), y, PDFUtil.Alignment.TOP_LEFT, isInputFieldLongTitle() ? (cursor.getBlockIndentedWidth() - 2.0f * getXFrameIndent()) : (getXFieldColumnIndent() - getXFrameIndent())); }
Example #15
Source File: ReportGenerator.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private void writeColumHeader(PDPageContentStream contentStream, float positionX, float positionY, String[] content) throws IOException { for (int i = 0; i < COLUMN_WIDTH.length; i++) { writeContent(contentStream, positionX, positionY, content[i]); positionX += COLUMN_WIDTH[i]; } }
Example #16
Source File: EcrfPDFPainter.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void drawPageBreakOldPage(PDPageContentStream contentStream) throws Exception { EcrfPDFBlock block = blocks.get(blockIndex - 1); if (BlockType.INPUT_FIELD.equals(block.getType()) || BlockType.AUDIT_TRAIL_VALUE.equals(block.getType()) || BlockType.FIELD_STATUS_ENTRY.equals(block.getType())) { drawBlock(contentStream, new EcrfPDFBlock(BlockType.END_OF_INDEX, true)); drawBlock(contentStream, new EcrfPDFBlock(BlockType.END_OF_SECTION, true)); } }
Example #17
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 #18
Source File: CVPDFPainter.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void drawPageNumber(PDFImprinter writer, PDPage page, int pageNumber, int totalPages) throws IOException { PDPageContentStream contentStream = writer.openContentStream(page); PDFUtil.renderTextLine( contentStream, fontA, PDFUtil.FontSize.TINY, Settings.getColor(CVPDFSettingCodes.TEXT_COLOR, Bundle.CV_PDF, CVPDFDefaultSettings.TEXT_COLOR), L10nUtil.getCVPDFLabel(Locales.CV_PDF, CVPDFLabelCodes.PAGE_NUMBER, "", pageNumber, totalPages), Settings.getFloat(CVPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LEFT_MARGIN) + (pageWidth - Settings.getFloat(CVPDFSettingCodes.PAGE_LEFT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LEFT_MARGIN) - Settings.getFloat( CVPDFSettingCodes.PAGE_RIGHT_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_RIGHT_MARGIN)), Settings.getFloat(CVPDFSettingCodes.PAGE_LOWER_MARGIN, Bundle.CV_PDF, CVPDFDefaultSettings.PAGE_LOWER_MARGIN), PDFUtil.Alignment.BOTTOM_RIGHT); writer.closeContentStream(); }
Example #19
Source File: InquiriesPDFPainter.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
protected void drawBlock(PDPageContentStream contentStream, InquiriesPDFBlock block) throws Exception { if (BlockType.NEW_PROBAND_TRIAL.equals(block.getType())) { cursor.setCategoryY(cursor.getBlockY()); } else if (BlockType.NEW_CATEGORY.equals(block.getType())) { cursor.setCategoryY(cursor.getBlockY()); } cursor.setBlocks(block); cursor.setBlockY(cursor.getBlockY() - block.renderBlock(contentStream, cursor)); }
Example #20
Source File: CompatibilityHelper.java From pdfbox-layout with MIT License | 5 votes |
public static void drawImage(final BufferedImage image, final PDDocument document, final PDPageContentStream contentStream, Position upperLeft, final float width, final float height) throws IOException { PDXObjectImage cachedImage = getCachedImage(document, image); float x = upperLeft.getX(); float y = upperLeft.getY() - height; contentStream.drawXObject(cachedImage, x, y, width, height); }
Example #21
Source File: TrainingRecordPDFBlock.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
private static float renderHasCourseCertificate(float x, float y, PDPageContentStream contentStream, TrainingRecordPDFBlockCursor cursor, CourseOutVO course) throws Exception { PDFJpeg ximage; if (course != null && course.getCertificate()) { //todo: check for uploaded certificate ... ximage = cursor.getCheckboxCheckedImage(); } else { ximage = cursor.getCheckboxUncheckedImage(); } PDFUtil.renderImage(contentStream, ximage, x, y, Alignment.TOP_CENTER); return ximage.getHeightPoints(); }
Example #22
Source File: Ellipse.java From pdfbox-layout with MIT License | 5 votes |
@Override protected void addRoundRect(PDPageContentStream contentStream, Position upperLeft, float width, float height, float cornerRadiusX, float cornerRadiusY) throws IOException { super.addRoundRect(contentStream, upperLeft, width, height, width/2f, height/2); }
Example #23
Source File: UnderlineAnnotationProcessor.java From pdfbox-layout with MIT License | 5 votes |
public void draw(PDPageContentStream contentStream) throws IOException { if (color != null) { contentStream.setStrokingColor(color); } if (stroke != null) { stroke.applyTo(contentStream); } contentStream.drawLine(start.getX(), start.getY(), end.getX(), end.getY()); }
Example #24
Source File: Stroke.java From pdfbox-layout with MIT License | 5 votes |
/** * Applies this stroke to the given content stream. * @param contentStream the content stream to apply this stroke to. * @throws IOException by PDFBox. */ public void applyTo(final PDPageContentStream contentStream) throws IOException { if (getCapStyle() != null) { contentStream.setLineCapStyle(getCapStyle().value()); } if (getJoinStyle() != null) { contentStream.setLineJoinStyle(getJoinStyle().value()); } if (getDashPattern() != null) { contentStream.setLineDashPattern(getDashPattern().getPattern(), getDashPattern().getPhase()); } contentStream.setLineWidth(getLineWidth()); }
Example #25
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 #26
Source File: VerticalSpacer.java From pdfbox-layout with MIT License | 5 votes |
@Override public void draw(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, DrawListener drawListener) throws IOException { if (drawListener != null) { drawListener.drawn(this, upperLeft, getWidth(), getHeight()); } }
Example #27
Source File: ImageElement.java From pdfbox-layout with MIT License | 5 votes |
@Override public void draw(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, DrawListener drawListener) throws IOException { CompatibilityHelper.drawImage(image, pdDocument, contentStream, upperLeft, getWidth(), getHeight()); if (drawListener != null) { drawListener.drawn(this, upperLeft, getWidth(), getHeight()); } }
Example #28
Source File: Frame.java From pdfbox-layout with MIT License | 5 votes |
@Override public void draw(PDDocument pdDocument, PDPageContentStream contentStream, Position upperLeft, DrawListener drawListener) throws IOException { setInnerMaxWidthIfNecessary(); float halfBorderWidth = 0; if (getBorderWidth() > 0) { halfBorderWidth = getBorderWidth() / 2f; } upperLeft = upperLeft.add(getMarginLeft() + halfBorderWidth, -getMarginTop() - halfBorderWidth); if (getShape() != null) { float shapeWidth = getWidth() - getMarginLeft() - getMarginRight() - getBorderWidth(); float shapeHeight = getHeight() - getMarginTop() - getMarginBottom() - getBorderWidth(); if (getBackgroundColor() != null) { getShape().fill(pdDocument, contentStream, upperLeft, shapeWidth, shapeHeight, getBackgroundColor(), drawListener); } if (hasBorder()) { getShape().draw(pdDocument, contentStream, upperLeft, shapeWidth, shapeHeight, getBorderColor(), getBorderStroke(), drawListener); } } Position innerUpperLeft = upperLeft.add(getPaddingLeft() + halfBorderWidth, -getPaddingTop() - halfBorderWidth); for (Drawable inner : innerList) { inner.draw(pdDocument, contentStream, innerUpperLeft, drawListener); innerUpperLeft = innerUpperLeft.add(0, -inner.getHeight()); } }
Example #29
Source File: ReportConvertPdf.java From yuzhouwan with Apache License 2.0 | 5 votes |
private static void drawImageWithScale(PDDocument doc, PDPageContentStream content, String imgPath, int bufferedImageType, float scale) throws IOException { BufferedImage bufferedImage = ImageIO.read(new File(imgPath)); BufferedImage image = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), bufferedImageType); image.createGraphics().drawRenderedImage(bufferedImage, null); PDXObjectImage xImage = new PDPixelMap(doc, image); content.drawXObject(xImage, 100, 100, xImage.getWidth() * scale, xImage.getHeight() * scale); }
Example #30
Source File: TextFlow.java From pdfbox-layout with MIT License | 5 votes |
@Override public void drawText(PDPageContentStream contentStream, Position upperLeft, Alignment alignment, DrawListener drawListener) throws IOException { TextSequenceUtil.drawText(this, contentStream, upperLeft, drawListener, alignment, getMaxWidth(), getLineSpacing(), isApplyLineSpacingToFirstLine()); }