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


Java PdfContentByte.setFontAndSize方法代码示例

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


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

示例1: setPageNumbers

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
private void setPageNumbers() throws DocumentException, IOException {		
	
	int pages = getReader().getNumberOfPages();
	int i = 0;	
	PdfContentByte overContent;
	Rectangle pageSize = null;
	BaseFont font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);

	while (i < pages) {
		i++;
		overContent = getStamper().getOverContent(i);
		pageSize = overContent.getPdfDocument().getPageSize();
		overContent.beginText();
		overContent.setFontAndSize(font, 9);
		overContent.setTextMatrix(pageSize.getWidth() - 50, pageSize.getHeight() - 70);
		overContent.showText("Page " + i + " of " + pages);
		overContent.endText();
	}
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:20,代码来源:PDFController.java

示例2: onEndPage

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
   * Print footer string on each page
   * @param writer
   * @param document
   */
  public void onEndPage(PdfWriter writer, Document document) {
   
  	if(getDateTime() == null) {
  		setDateTime(new Date());
  	}
  	
PdfContentByte cb = writer.getDirectContent();
cb.beginText();
cb.setFontAndSize(getBaseFont(), getFontSize());
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getDateFormat().format(getDateTime()), 
	    document.left(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, String.valueOf(document.getPageNumber()), 
	    document.right(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, MESSAGES.pdfCopyright(Constants.getVersion()),
		(document.left() + document.right()) / 2, 20, 0);
cb.endText();
	
      return;
  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:25,代码来源:PdfEventHandler.java

示例3: onStartPage

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的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

示例4: footer

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

	Date now = new Date();
	String promoTxt = OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT");
	if (promoTxt == null) {
		promoTxt = new String();
	}

	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,代码行数:27,代码来源:TicklerPrinter.java

示例5: onEndPage

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的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

示例6: onEndPage

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的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

示例7: onEndPage

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Adds promo text, date and current page number to each page
 * 
 * @param writer
 * @param document
 */
public void onEndPage(PdfWriter writer, Document document) {
	PdfContentByte cb = writer.getDirectContent();
	cb.saveState();

	float textBase = document.bottom() - getBaseOffset();
	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.restoreState();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:23,代码来源:PromoTextStamper.java

示例8: onEndPage

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的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

示例9: footer

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

       Date now = new Date();
       String promoTxt = OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT");
       if( promoTxt == null ) {
           promoTxt = new String();
       }

       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,代码行数:27,代码来源:PdfRecordPrinter.java

示例10: onEndPage

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

        Rectangle page = document.getPageSize();
        PdfContentByte cb = writer.getDirectContent();
        BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        int pageNum = document.getPageNumber();
        float width = page.getWidth();
        float height = page.getHeight();

        //add patient name header for every page but the first.
        if (pageNum > 1){
            cb.beginText();
            cb.setFontAndSize(bf, 8);
            cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, handler.getPatientName(), 575, height - 30, 0);
            cb.endText();

        }

        //add footer for every page
        cb.beginText();
        cb.setFontAndSize(bf, 8);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "-"+pageNum+"-", width/2, 30, 0);
        cb.endText();


        // add promotext as footer if it is enabled
        if ( OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") != null){
            cb.beginText();
            cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA,BaseFont.CP1252,BaseFont.NOT_EMBEDDED), 6);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT"), width/2, 19, 0);
            cb.endText();
        }

    // throw any exceptions
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:40,代码来源:LabPDFCreator.java

示例11: main

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Shading example.
 */
@Test
public void main() throws Exception {
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("shading_pattern.pdf"));
	document.open();

	PdfShading shading = PdfShading.simpleAxial(writer, 100, 100, 400, 100,
			Color.red, Color.cyan);
	PdfShadingPattern shadingPattern = new PdfShadingPattern(shading);
	PdfContentByte cb = writer.getDirectContent();
	BaseFont bf = BaseFont.createFont(BaseFont.TIMES_BOLD,
			BaseFont.WINANSI, false);
	cb.setShadingFill(shadingPattern);
	cb.beginText();
	cb.setTextMatrix(100, 100);
	cb.setFontAndSize(bf, 40);
	cb.showText("Look at this text!");
	cb.endText();
	PdfShading shadingR = PdfShading.simpleRadial(writer, 200, 500, 50,
			300, 500, 100, new Color(255, 247, 148), new Color(247, 138,
					107), false, false);
	cb.paintShading(shadingR);
	cb.sanityCheck();
	document.close();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:31,代码来源:ShadingPatternTest.java

示例12: main

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
    * Reads the pages of an existing PDF file, adds pagenumbers and a watermark.

    */
@Test
   public  void main() throws Exception {
           // we create a reader for a certain document
           PdfReader reader = new PdfReader(PdfTestBase.RESOURCES_DIR +"ChapterSection.pdf");
           int n = reader.getNumberOfPages();
           // we create a stamper that will copy the document to a new file
           PdfStamper stamp = new PdfStamper(reader,PdfTestBase.getOutputStream("watermark_pagenumbers.pdf"));
           // adding some metadata
           HashMap<String, String> moreInfo = new HashMap<String, String>();
           moreInfo.put("Author", "Bruno Lowagie");
           stamp.setMoreInfo(moreInfo);
           // adding content to each page
           int i = 0;
           PdfContentByte under;
           PdfContentByte over;
           Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR +"watermark.jpg");
           BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
           img.setAbsolutePosition(200, 400);
           while (i < n) {
           	i++;
           	// watermark under the existing page
           	under = stamp.getUnderContent(i);
           	under.addImage(img);
           	// text over the existing page
           	over = stamp.getOverContent(i);
           	over.beginText();
           	over.setFontAndSize(bf, 18);
           	over.setTextMatrix(30, 30);
           	over.showText("page " + i);
           	over.setFontAndSize(bf, 32);
           	over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE", 230, 430, 45);
           	over.endText();
           }
           // adding an extra page
           stamp.insertPage(1, PageSize.A4);
           over = stamp.getOverContent(1);
       	over.beginText();
       	over.setFontAndSize(bf, 18);
           over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE OF AN EXISTING PDF DOCUMENT", 30, 600, 0);
           over.endText();
           // adding a page from another document
           PdfReader reader2 = new PdfReader(PdfTestBase.RESOURCES_DIR +"SimpleAnnotations1.pdf");
           under = stamp.getUnderContent(1);
           under.addTemplate(stamp.getImportedPage(reader2, 3), 1, 0, 0, 1, 0, 0);
           // closing PdfStamper will generate the new PDF file
           stamp.close();
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:52,代码来源:AddWatermarkPageNumbersTest.java

示例13: main

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Reads the pages of an existing PDF file and puts 2 pages from the
 * existing doc into one of the new doc.
 */
@Test
public void main() throws Exception {
	// we create a reader for a certain document
	PdfReader reader = new PdfReader(PdfTestBase.RESOURCES_DIR + "ChapterSection.pdf");
	// we retrieve the total number of pages
	int n = reader.getNumberOfPages();
	// we retrieve the size of the first page
	Rectangle psize = reader.getPageSize(1);
	float width = psize.getHeight();
	float height = psize.getWidth();

	// step 1: creation of a document-object
	Document document = new Document(new Rectangle(width, height));
	// step 2: we create a writer that listens to the document
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("2on1.pdf"));
	// step 3: we open the document
	document.open();
	// step 4: we add content
	PdfContentByte cb = writer.getDirectContent();
	int i = 0;
	int p = 0;
	while (i < n) {
		document.newPage();
		p++;
		i++;
		PdfImportedPage page1 = writer.getImportedPage(reader, i);
		cb.addTemplate(page1, .5f, 0, 0, .5f, 60, 120);
		if (i < n) {
			i++;
			PdfImportedPage page2 = writer.getImportedPage(reader, i);
			cb.addTemplate(page2, .5f, 0, 0, .5f, width / 2 + 60, 120);
		}
		BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
		cb.beginText();
		cb.setFontAndSize(bf, 14);
		cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "page " + p + " of " + ((n / 2) + (n % 2 > 0 ? 1 : 0)),
				width / 2, 40, 0);
		cb.endText();
	}
	// step 5: we close the document
	document.close();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:48,代码来源:TwoOnOneTest.java

示例14: main

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
    * Creates a PDF document with shapes, lines and text at specific X and Y coordinates.
    */
@Test
public void main() throws Exception {
       
       // step 1: creation of a document-object
       Document document = new Document();
       
       try {      
           // step 2: creation of the writer
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "XandY.pdf"));
           
           // step 3: we open the document
           document.open();
           
           // step 4:
           PdfContentByte cb = writer.getDirectContent();
           
           // we create a PdfTemplate
           PdfTemplate template = cb.createTemplate(25, 25);
           
           // we add some crosses to visualize the coordinates
           template.moveTo(13, 0);
           template.lineTo(13, 25);
           template.moveTo(0, 13);
           template.lineTo(50, 13);
           template.stroke();
           template.sanityCheck();
           
           // we add the template on different positions
           cb.addTemplate(template, 216 - 13, 720 - 13);
           cb.addTemplate(template, 360 - 13, 360 - 13);
           cb.addTemplate(template, 360 - 13, 504 - 13);
           cb.addTemplate(template, 72 - 13, 144 - 13);
           cb.addTemplate(template, 144 - 13, 288 - 13);

           cb.moveTo(216, 720);
           cb.lineTo(360, 360);
           cb.lineTo(360, 504);
           cb.lineTo(72, 144);
           cb.lineTo(144, 288);
           cb.stroke();
           
           BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
           cb.beginText();
           cb.setFontAndSize(bf, 12);
           cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(3\", 10\")", 216 + 25, 720 + 5, 0);
           cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\", 5\")", 360 + 25, 360 + 5, 0);
           cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\", 7\")", 360 + 25, 504 + 5, 0);
           cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(1\", 2\")", 72 + 25, 144 + 5, 0);
           cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(2\", 4\")", 144 + 25, 288 + 5, 0);
           cb.endText(); 
           
           cb.sanityCheck();
       }
       catch(DocumentException de) {
           System.err.println(de.getMessage());
       }
       catch(IOException ioe) {
           System.err.println(ioe.getMessage());
       }
       
       // step 5: we close the document
       document.close();
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:67,代码来源:XandYcoordinatesTest.java

示例15: writeDirectContent

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void writeDirectContent(PdfContentByte cb, BaseFont bf, float fontSize, int alignment, String text, float x, float y, float rotation) {
	cb.beginText();
	cb.setFontAndSize(bf, fontSize);
	cb.showTextAligned(alignment, text, x, y, rotation);
	cb.endText();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:7,代码来源:FrmCustomedPDFServlet.java


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