當前位置: 首頁>>代碼示例>>Java>>正文


Java PdfContentByte.rectangle方法代碼示例

本文整理匯總了Java中com.itextpdf.text.pdf.PdfContentByte.rectangle方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfContentByte.rectangle方法的具體用法?Java PdfContentByte.rectangle怎麽用?Java PdfContentByte.rectangle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.itextpdf.text.pdf.PdfContentByte的用法示例。


在下文中一共展示了PdfContentByte.rectangle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: split

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
void split(PdfReader reader, int page) throws IOException
{
    PdfImportedPage importedPage = writer.getImportedPage(reader, page);

    Rectangle pageSizeToImport = reader.getPageSize(page);
    Iterable<Rectangle> rectangles = determineSplitRectangles(reader, page);

    for (Rectangle rectangle : rectangles) {
        newPage(rectangle);
        PdfContentByte directContent = writer.getDirectContent();
        directContent.saveState();
        directContent.rectangle(rectangle.getLeft(), rectangle.getBottom(), rectangle.getWidth(), rectangle.getHeight());
        directContent.clip();
        directContent.newPath();

        writer.getDirectContent().addTemplate(importedPage, -pageSizeToImport.getLeft(), -pageSizeToImport.getBottom());

        directContent.restoreState();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:21,代碼來源:Abstract2DPdfPageSplittingTool.java

示例2: cellLayout

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
@Override
    public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
        PdfContentByte canvas = canvases[PdfPTable.BACKGROUNDCANVAS];

        float xTransition = position.getLeft() + (position.getRight() - position.getLeft()) * (percent/100.0f);
        float yTransition = (position.getTop() + position.getBottom()) / 2f;
        float radius = (position.getRight() - position.getLeft()) * 0.025f;
        PdfShading axial = PdfShading.simpleAxial(canvas.getPdfWriter(),
                xTransition - radius, yTransition, xTransition + radius, yTransition, leftColor, rightColor);
        PdfShadingPattern shading = new PdfShadingPattern(axial);

        canvas.saveState();
        canvas.setShadingFill(shading);
        canvas.rectangle(position.getLeft(), position.getBottom(), position.getWidth(), position.getHeight());
//        canvas.clip();
        canvas.fill();
        canvas.restoreState();
    }
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:19,代碼來源:PercentileCellBackground.java

示例3: createRectangle

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
private static void createRectangle(PdfWriter writer, float x, float y, float width, float height, BaseColor color)
{
    float posX = Utilities.millimetersToPoints(x);
    float posY = Utilities.millimetersToPoints(y);

    float widthX = Utilities.millimetersToPoints(width + x);
    float heightY = Utilities.millimetersToPoints(height + y);

    Rectangle rectangle = new Rectangle(posX, posY, widthX, heightY);

    PdfContentByte canvas = writer.getDirectContent();
    rectangle.setBorder(Rectangle.BOX);
    rectangle.setBorderWidth(1);
    rectangle.setBorderColor(color);
    canvas.rectangle(rectangle);
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:17,代碼來源:UseMillimeters.java

示例4: 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

示例5: mark

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
void mark(InputStream input, OutputStream output, Pattern pattern) throws DocumentException, IOException
{
    PdfReader reader = new PdfReader(input);
    PdfStamper stamper = new PdfStamper(reader, output);
    try {
        PdfReaderContentParser parser = new PdfReaderContentParser(reader);
        for (int pageNr = 1; pageNr <= reader.getNumberOfPages(); pageNr++)
        {
            SearchTextLocationExtractionStrategy strategy = new SearchTextLocationExtractionStrategy(pattern);
            parser.processContent(pageNr, strategy, Collections.emptyMap()).getResultantText();
            Collection<TextRectangle> locations = strategy.getLocations(null);
            if (locations.isEmpty())
                continue;

            PdfContentByte canvas = stamper.getOverContent(pageNr);
            canvas.setRGBColorStroke(255, 255, 0);
            for (TextRectangle location : locations)
            {
                canvas.rectangle(location.getMinX(), location.getMinY(), location.getWidth(), location.getHeight());
            }
            canvas.stroke();
        }
        stamper.close();
    } finally {
        reader.close();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:28,代碼來源:TextLocationExtraction.java

示例6: 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

示例7: split

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
void split(PdfReader reader, int page) throws IOException
{
    PdfImportedPage importedPage = writer.getImportedPage(reader, page);
    PdfContentByte directContent = writer.getDirectContent();
    yPosition = pageSize.getTop();

    Rectangle pageSizeToImport = reader.getPageSize(page);
    float[] borderPositions = determineSplitPositions(reader, page);
    if (borderPositions == null || borderPositions.length < 2)
        return;

    for (int borderIndex = 0; borderIndex + 1 < borderPositions.length; borderIndex++) {
        float height = borderPositions[borderIndex] - borderPositions[borderIndex + 1];
        if (height <= 0)
            continue;

        directContent.saveState();
        directContent.rectangle(0, yPosition - height, pageSizeToImport.getWidth(), height);
        directContent.clip();
        directContent.newPath();

        writer.getDirectContent().addTemplate(importedPage, 0, yPosition - (borderPositions[borderIndex] - pageSizeToImport.getBottom()));

        directContent.restoreState();
        newPage();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:28,代碼來源:AbstractPdfPageSplittingTool.java

示例8: 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

示例9: 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

示例10: printPage3

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
private void printPage3(Document document, PdfContentByte canvas) throws DocumentException {
    int cols = 3;
    int rows = 15;

    PdfPTable table = new PdfPTable(cols);
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            table.addCell(new Phrase("Cell " + row + ", " + col));
        }
    }
    table.setSpacingBefore(5);

    Rectangle docBounds = document.getPageSize();
    Rectangle upper = new Rectangle(docBounds.getLeft(20), docBounds.getTop(20) - 200, docBounds.getRight(20), docBounds.getTop(20));
    upper.setBackgroundColor(new BaseColor(23, 142, 255, 20));
    Rectangle lower = new Rectangle(docBounds.getLeft(20), docBounds.getBottom(20), docBounds.getRight(20), docBounds.getBottom(20) + 600);
    lower.setBackgroundColor(new BaseColor(255, 142, 23, 20));
    Rectangle[] rectangles = new Rectangle[] { upper, lower };

    for (Rectangle bounds : rectangles)
    {
        bounds.setBorder(Rectangle.BOX);
        bounds.setBorderColor(BaseColor.BLACK);
        bounds.setBorderWidth(1);

        canvas.rectangle(bounds);
    }

    rectangles = drawKeepTogether(new Paragraph("This table should keep together!"), canvas, rectangles);
    rectangles = drawKeepTogether(table, canvas, rectangles);
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:32,代碼來源:TableKeepTogether.java

示例11: 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

示例12: enhance

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
void enhance(PdfContentByte page, Collection<Rectangle2D> rectangles)
{
    for (Rectangle2D rectangle : rectangles)
    {
        page.setColorStroke(pickColor());
        page.rectangle((float) rectangle.getMinX(), (float) rectangle.getMinY(), (float) rectangle.getWidth(), (float) rectangle.getHeight());
        page.stroke();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:10,代碼來源:FindFreeSpace.java

示例13: 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

示例14: 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

示例15: 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


注:本文中的com.itextpdf.text.pdf.PdfContentByte.rectangle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。