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


Java PdfContentByte.setTextMatrix方法代码示例

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


在下文中一共展示了PdfContentByte.setTextMatrix方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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包/类
/**
 * 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

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

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

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

示例6: main

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Adding text at absolute positions.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document();

	// step 2: creation of the writer
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("text.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we grab the ContentByte and do some stuff with it
	PdfContentByte cb = writer.getDirectContent();

	// first we draw some lines to be able to visualize the text alignment
	// functions
	cb.setLineWidth(0f);
	cb.moveTo(250, 500);
	cb.lineTo(250, 800);
	cb.moveTo(50, 700);
	cb.lineTo(400, 700);
	cb.moveTo(50, 650);
	cb.lineTo(400, 650);
	cb.moveTo(50, 600);
	cb.lineTo(400, 600);
	cb.stroke();

	// we tell the ContentByte we're ready to draw text
	cb.beginText();

	BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,
			BaseFont.NOT_EMBEDDED);
	cb.setFontAndSize(bf, 12);
	String text = "Sample text for alignment";
	// we show some text starting on some absolute position with a given
	// alignment
	cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text + " Center", 250,
			700, 0);
	cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, text + " Right", 250,
			650, 0);
	cb.showTextAligned(PdfContentByte.ALIGN_LEFT, text + " Left", 250, 600,
			0);

	// we draw some text on a certain position
	cb.setTextMatrix(100, 400);
	cb.showText("Text at position 100,400.");

	// we draw some rotated text on a certain position
	cb.setTextMatrix(0, 1, -1, 0, 100, 300);
	cb.showText("Text at position 100,300, rotated 90 degrees.");

	// we draw some mirrored, rotated text on a certain position
	cb.setTextMatrix(0, 1, 1, 0, 200, 200);
	cb.showText("Text at position 200,200, mirrored and rotated 90 degrees.");

	// we tell the contentByte, we've finished drawing text
	cb.endText();

	cb.sanityCheck();

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:69,代码来源:TextTest.java

示例7: onEndPage

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