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


Java PdfWriter.getPageNumber方法代码示例

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


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

示例1: onEndPage

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * After the content of the page is written, we put page X of Y at the
 * bottom of the page and we add either "Romeo and Juliet" of the title
 * of the current act as a header.
 * 
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter,
 *      com.lowagie.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	int pageN = writer.getPageNumber();
	String text = "Page " + pageN + " of ";
	float len = bf.getWidthPoint(text, 8);
	cb.beginText();
	cb.setFontAndSize(bf, 8);
	cb.setTextMatrix(280, 30);
	cb.showText(text);
	cb.endText();
	cb.addTemplate(template, 280 + len, 30);
	cb.beginText();
	cb.setFontAndSize(bf, 8);
	cb.setTextMatrix(280, 820);
	if (pageN % 2 == 1) {
		cb.showText("Romeo and Juliet");
	} else {
		cb.showText(act);
	}
	cb.endText();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:29,代码来源:EventsTest.java

示例2: onStartPage

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onStartPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 */
public void onStartPage(PdfWriter writer, Document document) {
    if (writer.getPageNumber() < 3) {
        PdfContentByte cb = writer.getDirectContentUnder();
        cb.saveState();
        cb.setColorFill(Color.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:albfernandez,项目名称:itext2,代码行数:16,代码来源:PageNumbersWatermarkTest.java

示例3: onEndPage

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
public void onEndPage(PdfWriter writer, Document document) {
	//Footer contains page numbers and date printed on all pages
	PdfContentByte cb = writer.getDirectContent();
	cb.saveState();

	String strFooter = promoTxt + " " + formatter.format(now);

	float textBase = document.bottom();
	cb.beginText();
	cb.setFontAndSize(font.getBaseFont(), FONTSIZE);
	Rectangle page = document.getPageSize();
	float width = page.getWidth();
	cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width / 2.0f), textBase - 20, 0);

	strFooter = "-" + writer.getPageNumber() + "-";
	cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width / 2.0f), textBase - 10, 0);

	cb.endText();
	cb.restoreState();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:21,代码来源:TicklerPrinter.java

示例4: onEndPage

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
public void onEndPage( PdfWriter writer, Document document ) {
    //Footer contains page numbers and date printed on all pages
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();

    String strFooter = promoTxt + " " + formatter.format(now);

    float textBase = document.bottom();
    cb.beginText();
    cb.setFontAndSize(font.getBaseFont(),FONTSIZE);
    Rectangle page = document.getPageSize();
    float width = page.getWidth();

    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase - 20, 0);

    strFooter = "-" + writer.getPageNumber() + "-";
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase-10, 0);

    cb.endText();
    cb.restoreState();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:22,代码来源:OscarChartPrinter.java

示例5: onEndPage

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

	String text = "Page " + writer.getPageNumber() + " of ";

	// height where text starts 
	float textBase = document.bottom() - getBaseOffset();
	float textSize = getFont().getWidthPoint(text, getFontSize());
	float width = document.getPageSize().getWidth();
	float center = width / 2.0f;

	cb.beginText();
	cb.setFontAndSize(getFont(), getFontSize());

	cb.setTextMatrix(document.left(), textBase);
	cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text, center, textBase, 0);
	cb.endText();
	cb.addTemplate(total, center + (textSize / 2.0f), textBase);

	cb.restoreState();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:23,代码来源:PageNumberStamper.java

示例6: onEndPage

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
public void onEndPage( PdfWriter writer, Document document ) {
    //Footer contains page numbers and date printed on all pages
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();

    String strFooter = promoTxt + " " + formatter.format(now);

    float textBase = document.bottom();
    cb.beginText();
    cb.setFontAndSize(font.getBaseFont(),FONTSIZE);
    Rectangle page = document.getPageSize();
    float width = page.getWidth();            
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase - 20, 0);

    strFooter = "-" + writer.getPageNumber() + "-";
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase-10, 0);

    cb.endText();
    cb.restoreState();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:21,代码来源:PdfRecordPrinter.java

示例7: onEndPage

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();
    // write the headertable
    table.setTotalWidth(document.right() - document.left());
    table.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 50, cb);
    // compose the footer
    String text = "Page " + writer.getPageNumber() + " of ";
    float textSize = helv.getWidthPoint(text, 12);
    float textBase = document.bottom() - 20;
    cb.beginText();
    cb.setFontAndSize(helv, 12);
    // for odd pagenumbers, show the footer at the left
    if ((writer.getPageNumber() & 1) == 1) {
        cb.setTextMatrix(document.left(), textBase);
        cb.showText(text);
        cb.endText();
        cb.addTemplate(tpl, document.left() + textSize, textBase);
    }
    // for even numbers, show the footer at the right
    else {
        float adjust = helv.getWidthPoint("0", 12);
        cb.setTextMatrix(document.right() - textSize - adjust, textBase);
        cb.showText(text);
        cb.endText();
        cb.addTemplate(tpl, document.right() - adjust, textBase);
    }

    // draw a Rectangle around the page
    cb.setColorStroke(Color.orange);
    cb.setLineWidth(2);
    cb.rectangle(20, 20, document.getPageSize().getWidth() - 40, document.getPageSize().getHeight() - 40);
    cb.stroke();

    // starting on page 3, a watermark with an Image that is made transparent
    if (writer.getPageNumber() >= 3) {

        cb.setGState(gstate);
        cb.setColorFill(Color.red);
        cb.beginText();
        cb.setFontAndSize(helv, 48);
        cb.showTextAligned(Element.ALIGN_CENTER, "Watermark Opacity " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45);
        cb.endText();
        try {
            cb.addImage(headerImage, headerImage.getWidth(), 0, 0, headerImage.getHeight(), 440, 80);
        }
        catch(Exception e) {
            throw new ExceptionConverter(e);
        }
    }
    cb.restoreState();
    cb.sanityCheck();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:57,代码来源:PageNumbersWatermarkTest.java

示例8: onFinPagina2

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
private void onFinPagina2(PdfWriter writer, Document document) {
	Rectangle page = document.getPageSize();
          PdfContentByte cb = writer.getDirectContent();
          
          Font font = new Font(Font.HELVETICA, 7, Font.ITALIC, Color.GRAY);
          
          
          if (cabecera != null){
           PdfPTable head = new PdfPTable(1);	            
           head.getDefaultCell().setBorder(Rectangle.NO_BORDER);
           head.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);	            
           Paragraph bloque = new Paragraph(new Chunk(cabecera,font));
           head.addCell(bloque);
           head.addCell(new Phrase(new Chunk("",font)));
           head.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin());
           head.writeSelectedRows(0, -1, document.leftMargin(), page.height() - document.topMargin() + head.getTotalHeight(),writer.getDirectContent());
          }            
          
          // Texto de pie y c�digo de barras
          if (pie == null) pie = "";
      	
          
          /** VRS: cambio para a�adir paginacion */
          cb.saveState();
          String text = pie + "  -  P�g. " + writer.getPageNumber() + " de ";
  		float textBase = document.bottom() - 20;
  		float textSize = bFont.getWidthPoint(text, 7);
  		
  		
  		cb.saveState();
  		cb.beginText();
  		cb.setFontAndSize(bFont, 7);
  		
  		
	float adjust = bFont.getWidthPoint("0", 7);
	cb.setTextMatrix(document.right() - textSize - adjust, textBase);
	cb.setColorFill(Color.GRAY);
	cb.showText(text);
	cb.endText();
	cb.addTemplate(tplTotal, document.right() - adjust, textBase);
  		
  		cb.restoreState();
  		

}
 
开发者ID:GovernIB,项目名称:sistra,代码行数:46,代码来源:PDFDocument.java


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