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


Java PdfContentByte.restoreState方法代码示例

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


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

示例1: onEndPage

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
@Override
public void onEndPage(final PdfWriter writer,
                      final Document document) {
  final PdfContentByte cb = writer.getDirectContent();
  cb.saveState();

  // compose the footer
  final String text = "Page "
      + writer.getPageNumber() + " of ";
  final float textSize = _headerFooterFont.getWidthPoint(text, 12);
  final float textBase = document.bottom() - 20;
  cb.beginText();
  cb.setFontAndSize(_headerFooterFont, 12);

  final float adjust = _headerFooterFont.getWidthPoint("0", 12);
  cb.setTextMatrix(document.right()
      - textSize - adjust, textBase);
  cb.showText(text);
  cb.endText();
  cb.addTemplate(_tpl, document.right()
      - adjust, textBase);

  cb.restoreState();
}
 
开发者ID:jpschewe,项目名称:fll-sw,代码行数:25,代码来源:SimpleFooterHandler.java

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

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

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

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public static void createCircleAndText(PdfContentByte cb, String text, float xCoord, float yCoord, float radius, Font textFont, int circleColorRed, int circleColorGreen, int circleColorBlue)
        throws DocumentException, IOException {
    cb.saveState();
    cb.setRGBColorFill(circleColorRed, circleColorGreen, circleColorBlue);
    cb.circle(xCoord, yCoord, radius);
    cb.fill();
    cb.stroke();
    cb.restoreState();

    PdfPTable table = new PdfPTable(1);
    float[] rows = { 595f };
    table.setTotalWidth(rows);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.getDefaultCell().setFixedHeight(radius * 2);
    table.addCell(new Phrase(new Chunk(text, textFont)));
    table.writeSelectedRows(0, 1, 0, yCoord + radius, cb);
}
 
开发者ID:Dica-Developer,项目名称:weplantaforest,代码行数:20,代码来源:PdfHelper.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: 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

示例8: drawFooter

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void drawFooter(PdfContentByte canvas, PageInfos pageInfos) {
    if (pageInfos.getRawPageNumber() == 1 && !footerOnFirstPage)
        return;

    if (drawLine) {
        BaseColor lineColor = styles.getColorOrDefault(HEADER_LINE_COLOR);
        canvas.saveState();
        canvas.setColorStroke(lineColor);
        canvas.setLineWidth(1.2f);
        canvas.moveTo(rect.getLeft(), rect.getBottom() - 6);
        canvas.lineTo(rect.getRight(), rect.getBottom() - 6);
        canvas.stroke();
        canvas.restoreState();
    }

    float bottom = rect.getBottom() - 20;
    Phrase footer = footerText(pageInfos);
    if (footer != null) {
        showTextAligned(canvas, Element.ALIGN_LEFT, footer, rect.getLeft(), bottom, 0);
    }

    Font footerFont = styles.getFontOrDefault(FOOTER_FONT);

    Phrase page = new Phrase(pageInfos.getFormattedPageNumber(), footerFont);
    showTextAligned(canvas, Element.ALIGN_RIGHT, page, rect.getRight(), bottom, 0);
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:27,代码来源:HeaderFooter.java

示例9: drawFooter

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void drawFooter(PdfContentByte canvas, PageInfos pageInfos) {
    if (lineColor != null) {
        canvas.saveState();
        canvas.setColorStroke(lineColor);
        canvas.setLineWidth(1.2f);
        canvas.moveTo(rect.getLeft(), rect.getBottom() - 6);
        canvas.lineTo(rect.getRight(), rect.getBottom() - 6);
        canvas.stroke();
        canvas.restoreState();
    }

    float bottom = rect.getBottom() - 20;
    Phrase footer = footerText();
    if (footer != null) {
        showTextAligned(canvas, Element.ALIGN_LEFT, footer, rect.getLeft(), bottom, 0);
    }

    Phrase page = new Phrase(pageInfos.getFormattedPageNumber(), footerFont);
    showTextAligned(canvas, Element.ALIGN_RIGHT, page, rect.getRight(), bottom, 0);
}
 
开发者ID:Arnauld,项目名称:cucumber-contrib,代码行数:21,代码来源:HeaderFooter.java

示例10: onEndPage

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
@Override
public void onEndPage(final PdfWriter writer,
                      final Document document) {
  final PdfContentByte cb = writer.getDirectContent();
  cb.saveState();

  // compose the footer

  final float textSize = _headerFooterFont.getWidthPoint(_legendText, 12);
  final float textBase = document.bottom()
      - 20;
  cb.beginText();
  cb.setFontAndSize(_headerFooterFont, 12);

  final float adjust = _headerFooterFont.getWidthPoint("0", 12);
  cb.setTextMatrix(document.right()
      - textSize
      - adjust, textBase);
  cb.showText(_legendText);
  cb.endText();
  cb.addTemplate(_tpl, document.right()
      - adjust, textBase);

  cb.restoreState();
}
 
开发者ID:jpschewe,项目名称:fll-sw,代码行数:26,代码来源:FinalComputedScores.java

示例11: saveFile

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Saves matrix to file.
 *
 * @param name
 *            name under which the file should be saved
 * @param table
 *            table you want to save
 *
 */
public static void saveFile(final String name, final Container table) {
	com.itextpdf.text.Document document = new com.itextpdf.text.Document(
			PageSize.A4);
	try {
		int width = table.getWidth();
		int height = table.getHeight();

		PdfWriter writer = PdfWriter.getInstance(document,
				new FileOutputStream(name + ".pdf"));
		document.open();

		PdfContentByte cb = writer.getDirectContent();

		cb.saveState();
		Graphics2D g2 = cb.createGraphicsShapes(width, height);

		Shape oldClip = g2.getClip();
		g2.clipRect(0, 0, width, height);

		table.print(g2);
		g2.setClip(oldClip);

		g2.dispose();
		cb.restoreState();
	} catch (Exception e) {
		System.err.println(e.getMessage());
	}
	document.close();
}
 
开发者ID:adamIqbal,项目名称:Health,代码行数:39,代码来源:StateTransitionMatrix.java

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

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

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

示例15: addBackground

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
private static void addBackground(PdfWriter writer)
        throws BadElementException, MalformedURLException, IOException, DocumentException {
    PdfContentByte canvas = writer.getDirectContentUnder();
    canvas.saveState();
    canvas.addImage(bkgnd);
    canvas.restoreState();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:8,代码来源:BinaryTransparency.java


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