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


Java PdfContentByte.setTextMatrix方法代碼示例

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


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

示例1: build

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
 * Update NDA file with visitor name and visitor signature.
 * 
 * @param destFile 
 * @param signatureImage signature file
 * @param visitorName
 * @return File
 */
public static File build(Path destFile, File signatureImage, String visitorName) {
	try {
		PdfReader pdfReader = new PdfReader(ndaUrl);
		PdfStamper pdfStamper = new PdfStamper(pdfReader,
				new FileOutputStream(destFile.toString()));
		Image image = createNDAImage(signatureImage, 0, 0);
		PdfContentByte over = pdfStamper.getOverContent(5);
		over.addImage(image);
		PdfContentByte pdfContentByte = pdfStamper.getOverContent(5);
		pdfContentByte.beginText();
		pdfContentByte.setFontAndSize(BaseFont.createFont
				(BaseFont.HELVETICA, 
						BaseFont.CP1257, 
						BaseFont.EMBEDDED
						)
				, 10); 
		pdfContentByte.setTextMatrix(112, 428); 
		pdfContentByte.showText(visitorName);
		pdfContentByte.setTextMatrix(89, 406);
		pdfContentByte.showText(new SimpleDateFormat("E, dd MMM yyyy").format(new Date()));
		pdfContentByte.endText();
		pdfStamper.close();
		return destFile.toFile();
	} catch (IOException | DocumentException | NumberFormatException e) {
		logger.error("Exception while generating NDA file. ",e);
		return null;
	}
}
 
開發者ID:Zymr,項目名稱:visitormanagement,代碼行數:37,代碼來源:NdaBuilder.java

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

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

示例4: createClippingTextPdf

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
static byte[] createClippingTextPdf() throws DocumentException, IOException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    document.open();

    PdfContentByte directContent = writer.getDirectContent();
    directContent.beginText();
    directContent.setTextRenderingMode(PdfPatternPainter.TEXT_RENDER_MODE_CLIP);
    directContent.setTextMatrix(AffineTransform.getTranslateInstance(100, 400));
    directContent.setFontAndSize(BaseFont.createFont(), 100);
    directContent.showText("Test");
    directContent.endText();
    
    BufferedImage bim = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = bim.createGraphics();
    g2d.setColor(Color.BLUE);
    g2d.fillRect(0, 0, 500, 500);
    g2d.dispose();

    Image image = Image.getInstance(bim, null);
    directContent.addImage(image, 500, 0, 0, 599, 50, 50);
    document.close();

    return baos.toByteArray();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:29,代碼來源:SimpleRedactionTest.java

示例5: onEndPage

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