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


Java PdfContentByte.saveState方法代碼示例

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


在下文中一共展示了PdfContentByte.saveState方法的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: bulidCellBorder

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
private PdfContentByte bulidCellBorder(PdfContentByte[] canvases,Border border){
	PdfContentByte cb=canvases[PdfPTable.LINECANVAS];
	cb.saveState();
	BigDecimal w=new BigDecimal(border.getWidth());
	cb.setLineWidth(w.divide(new BigDecimal(2),10,RoundingMode.HALF_UP).floatValue());
	if(border.getStyle().equals(BorderStyle.dashed)){
		cb.setLineDash(new float[]{2f,3f,1f},2);
	}
	String borderColor[]=border.getColor().split(",");
	cb.setColorStroke(new BaseColor(Integer.valueOf(borderColor[0]),Integer.valueOf(borderColor[1]),Integer.valueOf(borderColor[2])));
	return cb;
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:13,代碼來源:CellBorderEvent.java

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

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

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

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


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