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


Java PdfWriter.getPageNumber方法代碼示例

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


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

示例1: onEndPage

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
@Override
public void onEndPage(PdfWriter writer, Document document) {
	List<Page> pages=report.getPages();
	int pageNumber=writer.getPageNumber();
	if(pageNumber>pages.size()){
		return;
	}
	Page page=pages.get(pageNumber-1);
	HeaderFooter header=page.getHeader();
	HeaderFooter footer=page.getFooter();
	if(header!=null){
		buildTable(writer,header,true,report);			
	}
	if(footer!=null){
		buildTable(writer,footer,false,report);						
	}
}
 
開發者ID:youseries,項目名稱:ureport,代碼行數:18,代碼來源:PageHeaderFooterEvent.java

示例2: onEndPage

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
/**
 * Adds a header to every page
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	PdfPTable table = new PdfPTable(3);
	try {
		table.setWidths(new int[]{40,5,10});
		table.setTotalWidth(100);
		table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
		Font font=new Font(chineseFont,8);
		font.setColor(new BaseColor(55,55,55));
		Paragraph paragraph=new Paragraph("第   "+writer.getPageNumber()+" 頁   共",font);
		paragraph.setAlignment(Element.ALIGN_RIGHT);
		table.addCell(paragraph);
		Image img=Image.getInstance(total);
		img.scaleAbsolute(28, 28);
		PdfPCell cell = new PdfPCell(img);
		cell.setBorder(Rectangle.NO_BORDER);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		PdfPCell c = new PdfPCell(new Paragraph("頁",font));
		c.setHorizontalAlignment(Element.ALIGN_LEFT);
		c.setBorder(Rectangle.NO_BORDER);
		table.addCell(c);
		float center=(document.getPageSize().getWidth())/2-120/2;
		table.writeSelectedRows(0, -1,center,30, writer.getDirectContent());
	}
	catch(DocumentException de) {
		throw new ExceptionConverter(de);
	}
}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:35,代碼來源:PdfReportPageNumber.java

示例3: onCloseDocument

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
/**
 * 
 * TODO 關閉文檔時,替換模板,完成整個頁眉頁腳組件
 * 
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onCloseDocument(com.itextpdf.text.pdf.PdfWriter,
 *      com.itextpdf.text.Document)
 */
public void onCloseDocument(PdfWriter writer, Document document) {
	// 7.最後一步了,就是關閉文檔的時候,將模板替換成實際的 Y 值,至此,page x of y 製作完畢,完美兼容各種文檔size。
	total.beginText();
	total.setFontAndSize(bf, presentFontSize);// 生成的模版的字體、顏色
	String foot2 = " " + (writer.getPageNumber() - 1) + " 頁";
	total.showText(foot2);// 模版顯示的內容
	total.endText();
	total.closePath();
}
 
開發者ID:simbest,項目名稱:simbest-cores,代碼行數:17,代碼來源:HeaderFooter.java

示例4: onStartPage

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的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: onEndPage

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
public void onEndPage(PdfWriter writer, Document document) {
    pageNumber = writer.getPageNumber();
    generateFooter().writeSelectedRows(0, -1, document.left(), document.bottom() /*- getTableHeight(footerTable)*/ + 25,
            writer.getDirectContent());
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:6,代碼來源:DynamicFooter.java

示例6: onEndPage

import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
/**
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(com.itextpdf.text.pdf.PdfWriter, com.itextpdf.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);
    }
    cb.saveState();
    // draw a Rectangle around the page
    cb.setColorStroke(BaseColor.ORANGE);
    cb.setLineWidth(2);
    cb.rectangle(20, 20, document.getPageSize().getWidth() - 40, document.getPageSize().getHeight() - 40);
    cb.stroke();
    cb.restoreState();
    // starting on page 3, a watermark with an Image that is made transparent
    if (writer.getPageNumber() >= 3) {
        cb.setGState(gstate);
        cb.setColorFill(BaseColor.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:ltrr-arizona-edu,項目名稱:tellervo,代碼行數:56,代碼來源:PageNumbersWatermark.java


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