当前位置: 首页>>代码示例>>Java>>正文


Java PDPageContentStream.moveTo方法代码示例

本文整理汇总了Java中org.apache.pdfbox.pdmodel.PDPageContentStream.moveTo方法的典型用法代码示例。如果您正苦于以下问题:Java PDPageContentStream.moveTo方法的具体用法?Java PDPageContentStream.moveTo怎么用?Java PDPageContentStream.moveTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.pdfbox.pdmodel.PDPageContentStream的用法示例。


在下文中一共展示了PDPageContentStream.moveTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawTableLine

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
private void drawTableLine(PDPageContentStream contentStream, TableAttribute tableAttribute, String[][] tableContent) throws IOException {
    final int rows = tableContent.length;
    final int cols = tableContent[0].length;
    final float rowHeight = Optional.of(tableAttribute.getRowHeight())
            .orElse(PdfBoxStyle.DEFAULT_TABLE_ROW_HEIGHT);
    log.debug("The row height of the table is: " + rowHeight);

    //set border color
    contentStream.setStrokingColor(tableAttribute.getBorderColor());

    //draw the rows
    final float tableWidth = calculateTableWidth(tableAttribute.getColumns());
    log.debug("The number of the table rows is: " + tableAttribute.getColumns().size());
    float nextLineY = tableAttribute.getYCoordinate();
    for (int i = 0; i <= rows; i++) {
        contentStream.moveTo(tableAttribute.getXCoordinate(), nextLineY);
        contentStream.lineTo(tableAttribute.getXCoordinate() + tableWidth, nextLineY);
        contentStream.stroke();
        nextLineY -= rowHeight;
    }

    //draw the columns
    final float tableHeight = rowHeight * rows;
    float nextLineX = tableAttribute.getXCoordinate();
    for (int i = 0; i < cols; i++) {
        contentStream.moveTo(nextLineX, tableAttribute.getYCoordinate());
        contentStream.lineTo(nextLineX, tableAttribute.getYCoordinate() - tableHeight);
        contentStream.stroke();
        nextLineX += tableAttribute.getColumns().get(i).getCellWidth();
    }
    //draw the right border
    contentStream.moveTo(nextLineX, tableAttribute.getYCoordinate());
    contentStream.lineTo(nextLineX, tableAttribute.getYCoordinate() - tableHeight);
    contentStream.stroke();
}
 
开发者ID:bhits,项目名称:pcm-api,代码行数:36,代码来源:PdfBoxServiceImpl.java

示例2: addTextSimpleUnderlined

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
public static void addTextSimpleUnderlined(PDPageContentStream stream, PdfTextStyle textConfig, float textX, float textY, String text) {
    addTextSimple(stream, textConfig, textX, textY, text);
    try {
        float lineOffset = textConfig.getFontSize() / 8F;
        stream.setStrokingColor(textConfig.getColor());
        stream.setLineWidth(0.5F);
        stream.moveTo(textX, textY - lineOffset);
        stream.lineTo(textX + getTextWidth(textConfig.getCurrentFontStyle(), textConfig.getFontSize(), text), textY - lineOffset);
        stream.stroke();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Catalysts,项目名称:cat-boot,代码行数:14,代码来源:PdfBoxHelper.java

示例3: testAddEmptySignatureField

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/37601092/pdfbox-identify-specific-pages-and-functionalities-recommendations">
 * PDFBox identify specific pages and functionalities recommendations
 * </a>
 * 
 * <p>
 * This test shows how to add an empty signature field with a custom appearance
 * to an existing PDF.
 * </p>
 */
@Test
public void testAddEmptySignatureField() throws IOException
{
    try (   InputStream sourceStream = getClass().getResourceAsStream("test.pdf");
            OutputStream output = new FileOutputStream(new File(RESULT_FOLDER, "test-with-empty-sig-field.pdf")))
    {
        PDFont font = PDType1Font.HELVETICA;
        PDResources resources = new PDResources();
        resources.put(COSName.getPDFName("Helv"), font);

        PDDocument document = PDDocument.load(sourceStream);
        PDAcroForm acroForm = new PDAcroForm(document);
        acroForm.setDefaultResources(resources);
        document.getDocumentCatalog().setAcroForm(acroForm);

        PDRectangle rect = new PDRectangle(50, 750, 200, 50);

        PDAppearanceDictionary appearanceDictionary = new PDAppearanceDictionary();
        PDAppearanceStream appearanceStream = new PDAppearanceStream(document);
        appearanceStream.setBBox(rect.createRetranslatedRectangle());
        appearanceStream.setResources(resources);
        appearanceDictionary.setNormalAppearance(appearanceStream);
        PDPageContentStream contentStream = new PDPageContentStream(document, appearanceStream);
        contentStream.setStrokingColor(Color.BLACK);
        contentStream.setNonStrokingColor(Color.LIGHT_GRAY);
        contentStream.setLineWidth(2);
        contentStream.addRect(0, 0, rect.getWidth(), rect.getHeight());
        contentStream.fill();
        contentStream.moveTo(1 * rect.getHeight() / 4, 1 * rect.getHeight() / 4);
        contentStream.lineTo(2 * rect.getHeight() / 4, 3 * rect.getHeight() / 4);
        contentStream.moveTo(1 * rect.getHeight() / 4, 3 * rect.getHeight() / 4);
        contentStream.lineTo(2 * rect.getHeight() / 4, 1 * rect.getHeight() / 4);
        contentStream.moveTo(3 * rect.getHeight() / 4, 1 * rect.getHeight() / 4);
        contentStream.lineTo(rect.getWidth() - rect.getHeight() / 4, 1 * rect.getHeight() / 4);
        contentStream.stroke();
        contentStream.setNonStrokingColor(Color.DARK_GRAY);
        contentStream.beginText();
        contentStream.setFont(font, rect.getHeight() / 5);
        contentStream.newLineAtOffset(3 * rect.getHeight() / 4, -font.getBoundingBox().getLowerLeftY() * rect.getHeight() / 5000);
        contentStream.showText("Customer");
        contentStream.endText();
        contentStream.close();

        PDSignatureField signatureField = new PDSignatureField(acroForm);
        signatureField.setPartialName("SignatureField");
        PDPage page = document.getPage(0);

        PDAnnotationWidget widget = signatureField.getWidgets().get(0);
        widget.setAppearance(appearanceDictionary);
        widget.setRectangle(rect);
        widget.setPage(page);

        page.getAnnotations().add(widget);
        acroForm.getFields().add(signatureField);

        document.save(output);
        document.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:70,代码来源:TestEmptySignatureField.java

示例4: testDrawTextLineText

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
/**
 * <a href="https://stackoverflow.com/questions/44503236/how-to-write-text-draw-a-line-and-then-again-write-text-in-a-pdf-file-using-pdf">
 * How to write text, draw a line and then again write text in a pdf file using PDFBox
 * </a>
 * <p>
 * This test shows how to draw tetx, then graphics, then again text.
 * </p>
 */
@Test
public void testDrawTextLineText() throws IOException
{
    PDFont font = PDType1Font.HELVETICA;
    float fontSize = 14;
    float fontHeight = fontSize;
    float leading = 20;
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd");
    Date date = new Date();

    PDDocument doc = new PDDocument();
    PDPage page = new PDPage();
    doc.addPage(page);

    PDPageContentStream contentStream = new PDPageContentStream(doc, page);
    contentStream.setFont(font, fontSize);

    float yCordinate = page.getCropBox().getUpperRightY() - 30;
    float startX = page.getCropBox().getLowerLeftX() + 30;
    float endX = page.getCropBox().getUpperRightX() - 30;

    contentStream.beginText();
    contentStream.newLineAtOffset(startX, yCordinate);
    contentStream.showText("Entry Form � Header");
    yCordinate -= fontHeight;  //This line is to track the yCordinate
    contentStream.newLineAtOffset(0, -leading);
    yCordinate -= leading;
    contentStream.showText("Date Generated: " + dateFormat.format(date));
    yCordinate -= fontHeight;
    contentStream.endText(); // End of text mode

    contentStream.moveTo(startX, yCordinate);
    contentStream.lineTo(endX, yCordinate);
    contentStream.stroke();
    yCordinate -= leading;

    contentStream.beginText();
    contentStream.newLineAtOffset(startX, yCordinate);
    contentStream.showText("Name: XXXXX");
    contentStream.endText();

    contentStream.close();
    doc.save(new File(RESULT_FOLDER, "textLineText.pdf"));
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox2,代码行数:53,代码来源:TextAndGraphics.java

示例5: drawBorder

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
/**
 * Renders the borders
 * 
 * @param stream
 *            The stream used to render the borders
 * @param left
 *            The coordinate of the left edge of the object
 * @param top
 *            The coordinate of the top edge of the object
 * @param width
 *            The width the object will be rendered
 * @param height
 *            The height the object will be rendered
 * @throws IOException
 *             If writing to the stream fails
 */
protected void drawBorder(final PDPageContentStream stream, final float left, final float top, final float width, final float height) throws IOException {
	stream.moveTo(left, top);
	float lineWidth = -1;
	if (topBorder > 0) {
		stream.setLineWidth(topBorder);
		lineWidth = topBorder;
		stream.lineTo(left + width, top);
	} else {
		stream.moveTo(left + width, top);
	}
	if (rightBorder > 0) {
		if (lineWidth != rightBorder) {
			stream.setLineWidth(rightBorder);
		}
		lineWidth = rightBorder;
		stream.lineTo(left + width, top - height);
	} else {
		stream.moveTo(left + width, top - height);
	}
	if (bottomBorder > 0) {
		if (lineWidth != bottomBorder) {
			stream.setLineWidth(bottomBorder);
		}
		lineWidth = bottomBorder;
		stream.lineTo(left, top - height);
	} else {
		stream.moveTo(left, top - height);
	}
	if (leftBorder > 0) {
		if (lineWidth != leftBorder) {
			stream.setLineWidth(leftBorder);
		}
		lineWidth = leftBorder;
		stream.setLineWidth(leftBorder);
		stream.lineTo(left, top);
	} else {
		stream.moveTo(left, top);
	}
	if (topBorder > 0) {
		if (lineWidth != topBorder) {
			stream.setLineWidth(topBorder);
		}
		lineWidth = topBorder;
		stream.setLineWidth(topBorder);
		stream.lineTo(left + width, top);
	}
	stream.stroke();
}
 
开发者ID:errt,项目名称:BoxTable,代码行数:65,代码来源:Bordered.java

示例6: drawTable

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
public void drawTable(PDPage page, PDPageContentStream contentStream, String[][] content) throws IOException {
	final int rows = content.length;
	final int cols = content[0].length;
	final float rowHeight = 20f;
	final float tableWidth = page.getMediaBox().getWidth() - margin - margin;
	final float tableHeight = rowHeight * rows;
	final float colWidth = tableWidth / (float) cols;
	final float cellMargin = 5f;

	//draw the rows
	float nexty = y;
	for (int i = 0; i <= rows; i++) {

		contentStream.moveTo(margin, nexty);
		contentStream.lineTo(margin + tableWidth, nexty);
		//선색깔 바꾸기
		//			contentStream.setStrokingColor(255,50,5);
		contentStream.stroke();
		//			contentStream.fillAndStroke();

		nexty -= rowHeight;
	}

	//draw the columns
	float nextx = margin;
	for (int i = 0; i <= cols; i++) {

		//deprecated
		//			contentStream.drawLine(nextx, y, nextx, y - tableHeight);

		contentStream.moveTo(nextx, y);
		contentStream.lineTo(nextx, y - tableHeight);
		contentStream.stroke();

		nextx += colWidth;
	}

	//now add the text
	PDFont defaultFont = getDefaultFont();
	//		BoundingBox boundingBox = defaultFont.getBoundingBox();

	contentStream.setFont(defaultFont, defaultFontSize);

	float textx = margin + cellMargin;
	float texty = y - 15;

	//텍스트 색깔 바꾸기

	for (int i = 0; i < content.length; i++) {

		if (headerRow == i) {
			contentStream.setFont(defaultFont, headerFontSize);
			contentStream.setNonStrokingColor(headerFontColor);
		} else {
			contentStream.setFont(defaultFont, defaultFontSize);
			contentStream.setNonStrokingColor(defaultFontColor);
		}

		for (int j = 0; j < content[i].length; j++) {
			String text = content[i][j];

			contentStream.beginText();
			contentStream.newLineAtOffset(textx, texty);
			contentStream.showText(text);
			contentStream.endText();

			textx += colWidth;
		}
		texty -= rowHeight;
		textx = margin + cellMargin;

	}

}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:75,代码来源:TablePDFHelpeBuilder.java

示例7: placeBorders

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
private void placeBorders(PDPageContentStream stream, float startY, float endY, float x, float allowedWidth) throws IOException {
    if (border) {
        stream.setStrokingColor(0, 0, 0);
        stream.setLineWidth(0.3f);
        float y0 = startY - BORDER_Y_DELTA;
        float y1 = endY - (BORDER_Y_DELTA + 1);
        if (!noInnerBorders) {
            if (!noTopBorder || noTopBorder && !placeFirstBorder) {
                stream.moveTo(x, y0);
                stream.lineTo(x + allowedWidth, y0);
                stream.stroke();
            }
            if (!noBottomBorder || noBottomBorder && !placeLastBorder) {
                stream.moveTo(x, y1);
                stream.lineTo(x + allowedWidth, y1);
                stream.stroke();
            }
        } else {
            if (!noTopBorder && placeFirstBorder) {
                stream.moveTo(x, y0);
                stream.lineTo(x + allowedWidth, y0);
                stream.stroke();
            }
            if (!noBottomBorder && placeLastBorder) {
                stream.moveTo(x, y1);
                stream.lineTo(x + allowedWidth, y1);
                stream.stroke();
            }
        }
        float currX = x;
        stream.moveTo(currX, y0);
        stream.lineTo(currX, y1);
        stream.stroke();
        for (float width : cellWidths) {
            if (!noInnerBorders) {
                stream.moveTo(currX, y0);
                stream.lineTo(currX, y1);
                stream.stroke();
            }
            currX += width * allowedWidth;
        }
        stream.moveTo(currX, y0);
        stream.lineTo(currX, y1);
        stream.stroke();
    }
}
 
开发者ID:Catalysts,项目名称:cat-boot,代码行数:47,代码来源:ReportTable.java

示例8: drawLine

import org.apache.pdfbox.pdmodel.PDPageContentStream; //导入方法依赖的package包/类
/**
 * Helper method to draw a fine line
 * 
 * @param stream
 *            The stream used to draw the line
 * @param left
 *            The left end of the line
 * @param top
 *            The vertical position of the line
 * @param width
 *            The width of the line
 * @throws IOException
 *             If writing to the stream fails
 */
private void drawLine(final PDPageContentStream stream, final float left, final float top, final float width) throws IOException {
	stream.setLineWidth(0.25f);
	stream.moveTo(left, top);
	stream.lineTo(left + width, top);
	stream.stroke();
}
 
开发者ID:errt,项目名称:BoxTable,代码行数:21,代码来源:TextCell.java


注:本文中的org.apache.pdfbox.pdmodel.PDPageContentStream.moveTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。