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


Java PdfContentByte.setColorFill方法代码示例

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


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

示例1: stampTextOriginal

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * The OP's original code transformed into Java
 */
void stampTextOriginal(InputStream source, OutputStream target) throws DocumentException, IOException
{
    Date today = new Date();
    PdfReader reader = new PdfReader(source);
    PdfStamper stamper = new PdfStamper(reader, target);
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
    int tSize = 24;
    String mark = "DRAFT " + today;
    int angle = 45;
    float height = reader.getPageSizeWithRotation(1).getHeight()/2;
    float width = reader.getPageSizeWithRotation(1).getWidth()/2;
    PdfContentByte cb = stamper.getOverContent(1);
    cb.setColorFill(new BaseColor(255,200,200));
    cb.setFontAndSize(bf, tSize);
    cb.beginText();
    cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle);
    cb.endText();
    stamper.close();
    reader.close();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:24,代码来源:StampColoredText.java

示例2: stampTextChanged

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * The OP's code transformed into Java changed with the work-around.
 */
void stampTextChanged(InputStream source, OutputStream target) throws DocumentException, IOException
{
    Date today = new Date();
    PdfReader reader = new PdfReader(source);
    PdfStamper stamper = new PdfStamper(reader, target);
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
    int tSize = 24;
    String mark = "DRAFT " + today;
    int angle = 45;
    float height = reader.getPageSizeWithRotation(1).getHeight()/2;
    float width = reader.getPageSizeWithRotation(1).getWidth()/2;
    PdfContentByte cb = stamper.getOverContent(1);
    cb.setFontAndSize(bf, tSize);
    cb.beginText();
    cb.setColorFill(new BaseColor(255,200,200));
    cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle);
    cb.endText();
    stamper.close();
    reader.close();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:24,代码来源:StampColoredText.java

示例3: testHideContenUnderRectangle

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/43870545/filling-a-pdf-with-itextsharp-and-then-hiding-the-base-layer">
 * Filling a PDF with iTextsharp and then hiding the base layer
 * </a>
 * <p>
 * This test shows how to cover all content using a white rectangle.
 * </p>
 */
@Test
public void testHideContenUnderRectangle() throws IOException, DocumentException
{
    try (   InputStream resource = getClass().getResourceAsStream("document.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "document-hiddenContent.pdf")))
    {
        PdfReader pdfReader = new PdfReader(resource);
        PdfStamper pdfStamper = new PdfStamper(pdfReader, result);
        for (int page = 1; page <= pdfReader.getNumberOfPages(); page++)
        {
            Rectangle pageSize = pdfReader.getPageSize(page);
            PdfContentByte canvas = pdfStamper.getOverContent(page);
            canvas.setColorFill(BaseColor.WHITE);
            canvas.rectangle(pageSize.getLeft(), pageSize.getBottom(), pageSize.getWidth(), pageSize.getHeight());
            canvas.fill();
        }
        pdfStamper.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:28,代码来源:HideContent.java

示例4: onStartPage

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onStartPage(com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onStartPage(PdfWriter writer, Document document) {
    if (writer.getPageNumber() < 3) {
        PdfContentByte cb = writer.getDirectContentUnder();
        cb.saveState();
        cb.setColorFill(BaseColor.PINK);
        cb.beginText();
        cb.setFontAndSize(helv, 48);
        cb.showTextAligned(Element.ALIGN_CENTER, "My Watermark Under " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45);
        cb.endText();
        cb.restoreState();
    }
}
 
开发者ID:ltrr-arizona-edu,项目名称:tellervo,代码行数:16,代码来源:PageNumbersWatermark.java

示例5: cellLayout

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
@Override
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
    BaseColor color = colorProviders.apply(percent);
    if (color != null) {
        PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
        cb.saveState();
        cb.setColorFill(color);
        cb.rectangle(
                rect.getLeft() + margin.marginLeft,
                rect.getBottom() + margin.marginBottom,
                rect.getWidth() * percent - (margin.marginLeft + margin.marginRight),
                rect.getHeight() - (margin.marginTop + margin.marginBottom));
        cb.fill();
        cb.restoreState();
    }
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:17,代码来源:PercentBackgroundEvent.java

示例6: tableLayout

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void tableLayout(PdfPTable table, float[][] width, float[] height,
                        int headerRows, int rowStart, PdfContentByte[] canvas) {
    // because table is only one cell length, one can focus on using the first width
    float xmin = width[0][0];
    float xmax = width[0][1];
    float ymin = height[height.length - 1];
    float ymax = height[0];
    float d = 3;

    PdfContentByte background = canvas[PdfPTable.BASECANVAS];
    background.saveState();
    background.setColorFill(backgroundColor);
    background.roundRectangle(
            xmin - d,
            ymin - d,
            (xmax + d) - (xmin - d),
            (ymax + d) - (ymin - d),
            d + d);
    background.fill();
    background.restoreState();
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:22,代码来源:PygmentsAdapter.java

示例7: onEndPage

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
@Override
public void onEndPage(PdfWriter writer, Document document)
{
    if (active)
    {
        PdfContentByte cb = writer.getDirectContentUnder();
        cb.saveState();
        cb.setColorFill(color);
        cb.rectangle(document.left(), document.bottom() - offset,
            document.right() - document.left(), startPosition - document.bottom());
        cb.fill();
        cb.restoreState();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:15,代码来源:ParagraphBackground.java

示例8: onParagraphEnd

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
@Override
public void onParagraphEnd(PdfWriter writer, Document document, float paragraphPosition)
{
    if (active)
    {
        PdfContentByte cb = writer.getDirectContentUnder();
        cb.saveState();
        cb.setColorFill(color);
        cb.rectangle(document.left(), paragraphPosition - offset,
            document.right() - document.left(), startPosition - paragraphPosition);
        cb.fill();
        cb.restoreState();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:15,代码来源:ParagraphBackground.java

示例9: testCreateTableLikeUser7968180

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/43807931/creating-table-in-pdf-on-last-page-bottom-wrong-official-solution">
 * Creating table in pdf on last page bottom (wrong official solution)
 * </a>
 * <p>
 * Indeed, there is an error in the official sample which effectively
 * applies the margins twice.
 * </p>
 */
@Test
public void testCreateTableLikeUser7968180() throws FileNotFoundException, DocumentException
{
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(new File(RESULT_FOLDER, "calendarUser7968180.pdf")));
    document.open();

    PdfPTable datatable = null;//createHeaderTable();
    //document.add(datatable);
    datatable = createFooterTable();

    drawTableAtTheEndOfPage(document, writer, datatable);

    // Marking the border
    PdfContentByte canvas = writer.getDirectContentUnder();
    canvas.setColorStroke(BaseColor.RED);
    canvas.setColorFill(BaseColor.PINK);
    canvas.rectangle(document.left(), document.bottom(), document.right() - document.left(), document.top() - document.bottom());
    Rectangle pageSize = document.getPageSize(); 
    canvas.rectangle(pageSize.getLeft(), pageSize.getBottom(), pageSize.getWidth(), pageSize.getHeight());
    canvas.eoFillStroke();

    document.close();
    System.out.println("done");
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:36,代码来源:CreateTableDirectContent.java

示例10: enhance

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
void enhance(PdfContentByte page, Collection<Rectangle2D> rectangles, Point2D point, BaseColor color)
{
    Rectangle2D best = null;
    double bestDist = Double.MAX_VALUE;

    for (Rectangle2D rectangle : rectangles)
    {
        double distance = distance(rectangle, point);
        if (distance < bestDist)
        {
            best = rectangle;
            bestDist = distance;
        }
    }

    if (best != null)
    {
        page.setColorFill(color);
        page.rectangle((float) best.getMinX(), (float) best.getMinY(), (float) best.getWidth(), (float) best.getHeight());
        page.fill();
        System.out.printf("    Best rectangle for %7.3f, %7.3f is %7.3f, %7.3f, %7.3f, %7.3f\n", point.getX(), point.getY(), best.getMinX(),
                best.getMinY(), best.getWidth(), best.getHeight());
    }
    else
    {
        System.err.printf("!!! No best rectangle for %7.3f, %7.3f\n", point.getX(), point.getY());
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:29,代码来源:FindFreeSpace.java

示例11: createSimplePatternPdf

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
static byte[] createSimplePatternPdf() throws DocumentException, IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    document.open();

    PdfContentByte directContent = writer.getDirectContent();
    Rectangle pageSuze = document.getPageSize();
    
    PdfPatternPainter painter = directContent.createPattern(200, 150);
    painter.setColorStroke(BaseColor.GREEN);
    painter.beginText();
    painter.setTextRenderingMode(PdfPatternPainter.TEXT_RENDER_MODE_STROKE);
    painter.setTextMatrix(AffineTransform.getTranslateInstance(0, 50));
    painter.setFontAndSize(BaseFont.createFont(), 100);
    painter.showText("Test");
    painter.endText();

    directContent.setColorFill(new PatternColor(painter));
    directContent.rectangle(pageSuze.getLeft(), pageSuze.getBottom(), pageSuze.getWidth(), pageSuze.getHeight());
    directContent.fill();

    document.close();

    return baos.toByteArray();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:29,代码来源:SimpleRedactionTest.java

示例12: createHeaderBlock

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public static void createHeaderBlock(PdfContentByte cb, int pageNumber, int pageSize) throws DocumentException, IOException {
    cb.saveState();
    cb.setColorFill(BaseColor.BLACK);
    cb.rectangle(0.0f, 822.0f, 595.0f, 20.0f);
    cb.fill();
    cb.stroke();
    cb.restoreState();

    Font textFont = new Font(FontFamily.HELVETICA, 7, Font.NORMAL, BaseColor.WHITE);

    PdfPTable table = new PdfPTable(4);
    float[] rows = { 100f, 100f, 100f, 295f };
    table.setTotalWidth(rows);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.getDefaultCell().setFixedHeight(20);
    table.addCell(new Phrase(new Chunk("WALD 1.1 gGmbH", textFont)));
    table.addCell(new Phrase(new Chunk("[ Spendenkonto 222 888 ]", textFont)));
    table.addCell(new Phrase(new Chunk("www.iplantatree.org", textFont)));
    
    PdfPCell pageCell = new PdfPCell(new Phrase(new Chunk("Seite " + pageNumber + " von " + pageSize, textFont)));
    pageCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
    pageCell.setBorder(PdfPCell.NO_BORDER);
    table.addCell(pageCell);
    table.writeSelectedRows(0, 1, 0, 842, cb);
}
 
开发者ID:Dica-Developer,项目名称:weplantaforest,代码行数:28,代码来源:PdfHelper.java

示例13: cellLayout

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
    BaseColor color = colorThresholdSelectors.colorFor(percent);
    if (color != null) {
        PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
        cb.saveState();
        cb.setColorFill(color);
        cb.rectangle(rect.getLeft(), rect.getBottom(), rect.getWidth() * percent, rect.getHeight());
        cb.fill();
        cb.restoreState();
    }
}
 
开发者ID:Arnauld,项目名称:cucumber-contrib,代码行数:12,代码来源:PercentBackgroundEvent.java

示例14: colorRectangle

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void colorRectangle(PdfContentByte canvas,
                                  BaseColor color, float x, float y, float width, float height) {
    canvas.saveState();
    canvas.setColorFill(color);
    canvas.setColorStroke(color);
    canvas.rectangle(x, y, width, height);
    canvas.fillStroke();
    canvas.restoreState();
}
 
开发者ID:snavruzov,项目名称:cvbuilder_lib,代码行数:10,代码来源:ModelFactory.java

示例15: onRender

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void onRender( PdfContentByte cb ) throws PdfRenderException{
	
	float[] positions = new BlockFactory().getBoundsInPs(this);
	
	try{
		@SuppressWarnings("rawtypes")
		Hashtable hintMap = new Hashtable();
		hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
		PdfDocument req = getPage().getPdfDocument();
		QRCodeWriter qrCodeWriter = new QRCodeWriter();
		BitMatrix byteMatrix = qrCodeWriter.encode(getText(), BarcodeFormat.QR_CODE, (int) (positions[2]),(int) (positions[3]), hintMap);
		int matrixWidth = byteMatrix.getWidth();
		int matrixHeight = byteMatrix.getHeight();
		float pageHeight = req.getSize()[1];
		float top = getPosition()[1];

		if (getPage().getPdfDocument().getCutmarks() != null) {
			pageHeight += SizeFactory.CUT_MARK * 2;
			top += SizeFactory.CUT_MARK;
		}

		cb.setColorFill(getBaseColor());
		float pageHeightInPs = SizeFactory.millimetersToPostscriptPoints(pageHeight);
		float topInPs = SizeFactory.millimetersToPostscriptPoints(top);
		for (int i = byteMatrix.getTopLeftOnBit()[0]; i < matrixWidth; i++) {
			for (int j = byteMatrix.getTopLeftOnBit()[0]; j < matrixHeight; j++) {
				if (byteMatrix.get(i, j)) {
					
					cb.rectangle(positions[0] + (i - byteMatrix.getTopLeftOnBit()[0]),pageHeightInPs - ((topInPs + 1) + (j - byteMatrix .getTopLeftOnBit()[0])), 1, 1);
				}
			}
		}

		cb.fill();
		cb.setColorFill(new ColorFactory().getBlack()); 
 
	}catch( Exception e ){
		
	}
}
 
开发者ID:Billes,项目名称:pdf-renderer,代码行数:42,代码来源:QRCode.java


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