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


Java PDPageContentStream.setNonStrokingColor方法代码示例

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


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

示例1: fill

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
@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);
}

   }
 
开发者ID:ralfstuckert,项目名称:pdfbox-layout,代码行数:18,代码来源:AbstractShape.java

示例2: newPage

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
void newPage() throws IOException
{
    close();

    PDPage page = new PDPage(PDPage.PAGE_SIZE_LETTER);
    doc.addPage(page);
    content = new PDPageContentStream(doc, page);
    content.drawImage(logoImg, 50, 720);
    content.setLineWidth(.5f);
    content.setNonStrokingColor(Color.GRAY);
    content.drawLine(50, 710, 562, 710);

    previousBandBase = 770;
    render(new BandColumn(BandColumn.Layout.headerText, "ENDOSO", null));
    for (String head: header)
        render(new BandColumn(BandColumn.Layout.headerText, head, null));

    content.setNonStrokingColor(Color.BLACK);
    previousBandBase = 680;
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:21,代码来源:PdfRenderingEndorsementAlternative.java

示例3: appendContent

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
@Override
protected void appendContent(int start, int pages, int page, PDPageContentStream contentStream,
        PDRectangle rect) throws IOException {
    float fontSize = getFontSize();
    contentStream.beginText();
    contentStream.setFont(font, fontSize);
    contentStream.setNonStrokingColor(getColor());
    String str = getText(start, pages, page);
    float contentWidth;
    float contentHeight;
    {
        contentWidth = (font.getStringWidth(str) / 1000) * fontSize;
        contentHeight = (font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000)
                * fontSize;
    }
    double angle = (getRotate() * Math.PI) / 180.0;
    float[] point = getRotatePoint(angle, rect.getWidth(), rect.getHeight(), contentWidth,
            contentHeight);
    contentStream.setTextRotation(angle, point[0], point[1]);
    contentStream.drawString(str);
    contentStream.endText();
}
 
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:23,代码来源:TextPageAppender.java

示例4: appendContent

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
@Override
protected void appendContent(int end, int start, int pages, int page,
        PDPageContentStream contentStream, PDRectangle rect) throws IOException {
    PDFont font = getFont();
    float fontSize = getFontSize();
    contentStream.beginText();
    contentStream.setFont(font, fontSize);
    contentStream.setNonStrokingColor(getColor());
    String str = getText(end, start, pages, page);
    float contentWidth;
    float contentHeight;
    {
        contentWidth = (font.getStringWidth(str) / 1000) * fontSize;
        contentHeight = (font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000)
                * fontSize;
    }
    double angle = (getRotate() * Math.PI) / 180.0;
    float[] point = getRotatePoint(angle, rect.getWidth(), rect.getHeight(), contentWidth,
            contentHeight);
    contentStream.setTextRotation(angle, point[0], point[1]);
    contentStream.drawString(str);
    contentStream.endText();
}
 
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:24,代码来源:TextPagesAppender.java

示例5: drawTable

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

	float nexty = y;
	for (int i = 0; i <= rows; i++) {
		contentStream.drawLine(margin, nexty, margin + tableWidth, nexty);
		nexty -= rowHeight;
	}

	// draw the columns
	float nextx = margin;
	for (int i = 0; i <= cols; i++) {
		contentStream.drawLine(nextx, y, nextx, y - tableHeight);
		nextx += colWidth;
	}

	// now add the text
	contentStream.setFont(PDType1Font.HELVETICA_BOLD, 12);

	float textx = margin + cellMargin;
	float texty = y - 15;
	for (int i = 0; i < content.length; i++) {
		for (int j = 0; j < content[i].length; j++) {
			String text = content[i][j];
			contentStream.beginText();
				if(i == 0) {
					contentStream.setNonStrokingColor(Color.BLUE); 
				} else {
					contentStream.setNonStrokingColor(Color.BLACK);
				}
				contentStream.moveTextPositionByAmount(textx, texty);
				contentStream.drawString(text);
			contentStream.endText();
			textx += colWidth;
		}
		texty -= rowHeight;
		textx = margin + cellMargin;
	}
}
 
开发者ID:rmohta,项目名称:pdfboxExamples,代码行数:48,代码来源:PdfTable.java

示例6: newPage

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
void newPage() throws IOException
{
    close();

    PDPage page = new PDPage();
    doc.addPage(page);
    content = new PDPageContentStream(doc, page);
    content.setNonStrokingColor(Color.BLACK);

    textRenderingLineY = 768;
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:12,代码来源:PdfRenderingSimple.java

示例7: testDrawOnBackgroundLikeDave823

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/33440450/pdfbox-how-to-draw-text-on-top-of-a-filled-rectangle">
 * PDFBox: How to draw text on top of a filled rectangle?
 * </a>
 * <p>
 * The OP's code works. Thus, the cause for his issue lies beyond the code he provided.
 * </p>
 */
@Test
public void testDrawOnBackgroundLikeDave823() throws IOException, COSVisitorException
{
    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    PDPageContentStream content = new PDPageContentStream(document, page);
    PDFont font = PDType1Font.HELVETICA_BOLD;

    int cursorX = 70;
    int cursorY = 500;

    //draw rectangle
    content.setNonStrokingColor(200, 200, 200); //gray background
    content.fillRect(cursorX, cursorY, 100, 50);

    //draw text
    content.setNonStrokingColor(0, 0, 0); //black text
    content.beginText();
    content.setFont(font, 12);
    content.moveTextPositionByAmount(cursorX, cursorY);
    content.drawString("Test Data");
    content.endText();

    content.close();
    document.save(new File(RESULT_FOLDER, "textOnBackground.pdf"));
    document.close();
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:37,代码来源:DrawOnBackground.java

示例8: testTransparentTextLikeTilman

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/39998390/how-to-create-transparent-text-in-pdfbox-or-add-opacity-to-the-text-with-the-hel">
 * How to create Transparent text in pdfBOX or add opacity to the text with the help of pdfBOX?
 * </a>
 * <p>
 * Indeed, this code does not produce transparency... but look at
 * {@link #testTransparentTextLikeTilmanImproved()}.
 * </p>
 */
@Test
public void testTransparentTextLikeTilman() throws IOException, COSVisitorException
{
    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    PDPageContentStream cs = new PDPageContentStream(document, page);

    PDExtendedGraphicsState gs1 = new PDExtendedGraphicsState();
    gs1.setNonStrokingAlphaConstant(1f);
    PDExtendedGraphicsState gs2 = new PDExtendedGraphicsState();
    gs2.setNonStrokingAlphaConstant(0.2f);
    Map<String, PDExtendedGraphicsState> graphicsStatesMap = page.getResources().getGraphicsStates();
    if (graphicsStatesMap == null)
    {
        graphicsStatesMap = new HashMap<String, PDExtendedGraphicsState>();
    }
    graphicsStatesMap.put("gs1", gs1);
    graphicsStatesMap.put("gs2", gs2);
    page.getResources().setGraphicsStates(graphicsStatesMap);
    cs.setFont(PDType1Font.HELVETICA_BOLD, 60);
    cs.setNonStrokingColor(0, 0, 0);
    cs.beginText();
    cs.appendRawCommands("/gs1 gs\n");
    cs.moveTextPositionByAmount(50, 600);
    cs.drawString("Apache PDFBox 1");
    cs.appendRawCommands("/gs2 gs\n");
    cs.moveTextPositionByAmount(20, 20);
    cs.drawString("Apache PDFBox 2");
    cs.endText();
    cs.close();

    cs.close();
    document.save(new File(RESULT_FOLDER, "transparentTextLikeTilman.pdf"));
    document.close();
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:46,代码来源:TransparentText.java

示例9: watermarkOriginal

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
/**
 * <p>
 * This is the OP's initial approach: "the problem is where ever my watermark
 * message comes it is hiding my page content."
 * </p>
 * <p>
 * I enclosed the mark drawing code in <code>saveGraphicsState</code> and
 * <code>restoreGraphicsState</code> to protect the original content from
 * being influenced by state changes by the the mark drawing code.
 * </p>
 */
void watermarkOriginal(PDDocument document, PDFont pdfFont, double degree, double x, double y, String text) throws IOException
{
    List<?> pages = document.getDocumentCatalog().getAllPages();
    float fontSize = 70.0f;
    for (int i = 0; i < pages.size(); i++) {
        PDPage page = (PDPage) pages.get(i);
        PDRectangle pageSize = page.findMediaBox();
        float stringWidth = pdfFont.getStringWidth(text) * fontSize
                / 1000f;
        // calculate to center of the page
        int rotation = page.findRotation();
        boolean rotate = degree > 0;
        float pageWidth = rotate ? pageSize.getHeight() : pageSize
                .getWidth();
        float pageHeight = rotate ? pageSize.getWidth() : pageSize
                .getHeight();
        double centeredXPosition = rotate ? pageHeight / 2f
                : (pageWidth - stringWidth) / 2f;
        double centeredYPosition = rotate ? (pageWidth - stringWidth) / 2f
                : pageHeight / 2f;
        // append the content to the existing stream
        PDPageContentStream contentStream = new PDPageContentStream(
                document, page, true, true, true);
        contentStream.saveGraphicsState();
        contentStream.beginText();
        // set font and font size
        contentStream.setFont(pdfFont, fontSize);
        // set text color to red
        contentStream.setNonStrokingColor(240, 240, 240);
        if (rotate) {
            // rotate the text according to the page rotation
            contentStream.setTextRotation(degree, x, y);
        } else {
            contentStream.setTextTranslation(centeredXPosition,
                    centeredYPosition);
        }
        contentStream.drawString(text);
        contentStream.endText();
        contentStream.restoreGraphicsState();
        contentStream.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:54,代码来源:UnderlayText.java

示例10: drawAligned

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
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();
   }
 
开发者ID:ralfstuckert,项目名称:pdfbox-layout,代码行数:64,代码来源:TextLine.java

示例11: testTransparentTextLikeTilmanImproved

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/39998390/how-to-create-transparent-text-in-pdfbox-or-add-opacity-to-the-text-with-the-hel">
 * How to create Transparent text in pdfBOX or add opacity to the text with the help of pdfBOX?
 * </a>
 * <p>
 * This code (which parallels Tilman's own improved code) does produce transparency
 * in contrast to {@link #testTransparentTextLikeTilman()}.
 * </p>
 */
@Test
public void testTransparentTextLikeTilmanImproved() throws IOException, COSVisitorException
{
    PDDocument document = new PDDocument();
    PDPage page = new PDPage();
    document.addPage(page);
    PDPageContentStream cs = new PDPageContentStream(document, page);

    PDExtendedGraphicsState gs1 = new PDExtendedGraphicsState();
    gs1.setNonStrokingAlphaConstant(1f);
    PDExtendedGraphicsState gs2 = new PDExtendedGraphicsState();
    gs2.setNonStrokingAlphaConstant(0.2f);
    Map<String, PDExtendedGraphicsState> graphicsStatesMap = page.getResources().getGraphicsStates();
    if (graphicsStatesMap == null)
    {
        graphicsStatesMap = new HashMap<String, PDExtendedGraphicsState>();
    }
    graphicsStatesMap.put("gs1", gs1);
    graphicsStatesMap.put("gs2", gs2);
    page.getResources().setGraphicsStates(graphicsStatesMap);
    cs.setFont(PDType1Font.HELVETICA_BOLD, 60);
    cs.setNonStrokingColor(0, 0, 0);
    cs.appendRawCommands("/gs1 gs\n");
    cs.setNonStrokingColor(Color.green);
    cs.beginText();
    cs.moveTextPositionByAmount(50, 600);
    cs.drawString("Apache PDFBox 1");
    cs.endText();
    cs.appendRawCommands("/gs2 gs\n");
    cs.setNonStrokingColor(Color.red);
    cs.beginText();
    cs.moveTextPositionByAmount(70, 620);
    cs.drawString("Apache PDFBox 2");
    cs.endText();
    cs.close();

    cs.close();
    document.save(new File(RESULT_FOLDER, "transparentTextLikeTilmanImproved.pdf"));
    document.close();
}
 
开发者ID:mkl-public,项目名称:testarea-pdfbox1,代码行数:50,代码来源:TransparentText.java

示例12: addWatermark

import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
@Override
public void addWatermark(final PDDocument doc, final PDPage page, final Color color,
		final String text, final WatermarkPosition watermarkPosition) throws IOException,
		WatermarkOutOfLengthException {

	if (doc != null && page != null && color != null && StringUtils.isNotBlank(text)
			&& watermarkPosition != null) {

		// Attributes are extrated from the watermarkPosition argument.
		Double rotationAngle = 0D;
		Double rotationTX = 0D;
		Double rotationTY = 0D;
		Integer maxLength = 0;

		if (page.getMediaBox().getHeight() > page.getMediaBox().getWidth()) {
			// Page is portrait
			rotationAngle = watermarkPosition.getRotationAnglePortrait();
			rotationTX = watermarkPosition.getRotationTXPortrait();
			rotationTY = watermarkPosition.getRotationTYPortrait();
			maxLength = watermarkPosition.getMaxLengthPortrait();
		} else {
			// Page is landscape
			rotationAngle = watermarkPosition.getRotationAngleLandscape();
			rotationTX = watermarkPosition.getRotationTXLandscape();
			rotationTY = watermarkPosition.getRotationTYLandscape();
			maxLength = watermarkPosition.getMaxLengthLandscape();
		}

		// In case text is too large, an exception is thrown.
		if (text.length() > maxLength) {
			throw new WatermarkOutOfLengthException(
					Constants.WATERMARK_OUT_OF_LENGTH_EXCEPTION_MESSAGE);
		}

		final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true);
		contentStream.appendRawCommands("/TransparentState gs\n");
		contentStream.setNonStrokingColor(color);
		contentStream.beginText();
		contentStream.setFont(PDType1Font.HELVETICA, 70);
		contentStream.setTextRotation(rotationAngle, rotationTX, rotationTY);
		// Text is centered
		final Integer size = (maxLength * 2) - text.length();
		final String centeredText = StringUtils.center(text, size);
		contentStream.drawString(centeredText);
		contentStream.endText();
		contentStream.close();
	}
}
 
开发者ID:alexpernas,项目名称:PDFGal,代码行数:49,代码来源:WatermarkUtilsImpl.java


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