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


Java PdfContentByte.setFontAndSize方法代码示例

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


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

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * The OP's original code transformed into Java
 */
void stampTextOriginal(InputStream source, OutputStream target) throws DocumentException, IOException
{
    Date today = new Date();
    PdfReader reader = new PdfReader(source);
    PdfStamper stamper = new PdfStamper(reader, target);
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
    int tSize = 24;
    String mark = "DRAFT " + today;
    int angle = 45;
    float height = reader.getPageSizeWithRotation(1).getHeight()/2;
    float width = reader.getPageSizeWithRotation(1).getWidth()/2;
    PdfContentByte cb = stamper.getOverContent(1);
    cb.setColorFill(new BaseColor(255,200,200));
    cb.setFontAndSize(bf, tSize);
    cb.beginText();
    cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle);
    cb.endText();
    stamper.close();
    reader.close();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:24,代码来源:StampColoredText.java

示例4: stampTextChanged

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * The OP's code transformed into Java changed with the work-around.
 */
void stampTextChanged(InputStream source, OutputStream target) throws DocumentException, IOException
{
    Date today = new Date();
    PdfReader reader = new PdfReader(source);
    PdfStamper stamper = new PdfStamper(reader, target);
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
    int tSize = 24;
    String mark = "DRAFT " + today;
    int angle = 45;
    float height = reader.getPageSizeWithRotation(1).getHeight()/2;
    float width = reader.getPageSizeWithRotation(1).getWidth()/2;
    PdfContentByte cb = stamper.getOverContent(1);
    cb.setFontAndSize(bf, tSize);
    cb.beginText();
    cb.setColorFill(new BaseColor(255,200,200));
    cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle);
    cb.endText();
    stamper.close();
    reader.close();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:24,代码来源:StampColoredText.java

示例5: onStartPage

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

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

示例7: addImageToPdf

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * The <code>addImageToPdf</code> method is used to add image to pdf and make it searchable by adding image text in invisible mode
 * w.r.t parameter 'isPdfSearchable' passed.
 * 
 * @param pdfWriter {@link PdfWriter} writer of pdf in which image has to be added
 * @param htmlUrl {@link HocrPage} corresponding html file for fetching text and coordinates
 * @param imageUrl {@link String} url of image to be added in pdf
 * @param isPdfSearchable true for searchable pdf else otherwise
 * @param widthOfLine
 */
private void addImageToPdf(PdfWriter pdfWriter, HocrPage hocrPage, String imageUrl, boolean isPdfSearchable, final int widthOfLine) {
	if (null != pdfWriter && null != imageUrl && imageUrl.length() > 0) {
		try {
			LOGGER.info("Adding image" + imageUrl + " to pdf using iText");
			Image pageImage = Image.getInstance(imageUrl);
			float dotsPerPointX = pageImage.getDpiX() / PDF_RESOLUTION;
			float dotsPerPointY = pageImage.getDpiY() / PDF_RESOLUTION;
			PdfContentByte pdfContentByte = pdfWriter.getDirectContent();

			pageImage.scaleToFit(pageImage.getWidth() / dotsPerPointX, pageImage.getHeight() / dotsPerPointY);

			pageImage.setAbsolutePosition(0, 0);

			// Add image to pdf
			pdfWriter.getDirectContentUnder().addImage(pageImage);
			pdfWriter.getDirectContentUnder().add(pdfContentByte);

			// If pdf is to be made searchable
			if (isPdfSearchable) {
				LOGGER.info("Adding invisible text for image: " + imageUrl);
				float pageImagePixelHeight = pageImage.getHeight();
				Font defaultFont = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD, CMYKColor.BLACK);

				// Fetch text and coordinates for image to be added
				Map<String, int[]> textCoordinatesMap = getTextWithCoordinatesMap(hocrPage, widthOfLine);
				Set<String> ketSet = textCoordinatesMap.keySet();

				// Add text at specific location
				for (String key : ketSet) {
					int[] coordinates = textCoordinatesMap.get(key);
					float bboxWidthPt = (coordinates[2] - coordinates[0]) / dotsPerPointX;
					float bboxHeightPt = (coordinates[3] - coordinates[1]) / dotsPerPointY;
					pdfContentByte.beginText();

					// To make text added as invisible
					pdfContentByte.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE);
					pdfContentByte.setLineWidth(Math.round(bboxWidthPt));

					// Ceil is used so that minimum font of any text is 1
					// For exception of unbalanced beginText() and endText()
					if (bboxHeightPt > 0.0) {
						pdfContentByte.setFontAndSize(defaultFont.getBaseFont(), (float) Math.ceil(bboxHeightPt));
					} else {
						pdfContentByte.setFontAndSize(defaultFont.getBaseFont(), 1);
					}
					float xCoordinate = (float) (coordinates[0] / dotsPerPointX);
					float yCoordinate = (float) ((pageImagePixelHeight - coordinates[3]) / dotsPerPointY);
					pdfContentByte.moveText(xCoordinate, yCoordinate);
					pdfContentByte.showText(key);
					pdfContentByte.endText();
				}
			}
			pdfContentByte.closePath();
		} catch (BadElementException badElementException) {
			LOGGER
					.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: "
							+ badElementException.toString());
		} catch (DocumentException documentException) {
			LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + documentException.toString());
		} catch (MalformedURLException malformedURLException) {
			LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: "
					+ malformedURLException.toString());
		} catch (IOException ioException) {
			LOGGER.error("Error occurred while adding image" + imageUrl + " to pdf using Itext: " + ioException.toString());
		}
	}
}
 
开发者ID:kuzavas,项目名称:ephesoft,代码行数:78,代码来源:MultiPageExecutor.java

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

示例9: createFile

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
private void createFile(String finalPDF, ByteArrayOutputStream outputStream) throws FileNotFoundException, IOException 
{
	if (outputStream == null || finalPDF == null)
		return;
	FileOutputStream fos = new FileOutputStream (new File(finalPDF)); 
	Document document = new Document();
	try
	{			
		fos.write(outputStream.toByteArray());
		fos.close();
		
		PdfWriter writer = PdfWriter.getInstance(document, fos);

		document.open();
		BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
		PdfContentByte cb = writer.getDirectContent();
		cb.beginText();
		cb.setFontAndSize(bf, 9);
		cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "This is a Draft Document, its contents might still change", 520, 5, 0);
		cb.endText();

		document.close();		       
	}
	catch (Exception e) 
	{
		engine.createSystemLogEntry(SystemLogType.REPORTS, SystemLogLevel.ERROR, "Error Converting DRAFT Document into PDF");
	}
	finally 
	{		
		fos.close();
		if (document.isOpen()) {
			document.close();		
		}
	}
}
 
开发者ID:IMS-MAXIMS,项目名称:openMAXIMS,代码行数:36,代码来源:Logic.java

示例10: createFile

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public static void createFile(String finalPDF, ByteArrayOutputStream outputStream, UIEngine engine) throws FileNotFoundException, IOException 
{
	if (outputStream == null || finalPDF == null)
		return;
	
	FileOutputStream fos = new FileOutputStream (new File(finalPDF)); 
	Document document = new Document();
	try
	{			
		fos.write(outputStream.toByteArray());
		fos.close();
		
		PdfWriter writer = PdfWriter.getInstance(document, fos);

		document.open();
		BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
		PdfContentByte cb = writer.getDirectContent();
		cb.beginText();
		cb.setFontAndSize(bf, 9);
		cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "This is a Draft Document, its contents might still change", 520, 5, 0);
		cb.endText();

		document.close();		       
	}
	catch (Exception e) 
	{
		engine.createSystemLogEntry(SystemLogType.REPORTS, SystemLogLevel.ERROR, "Error Converting DRAFT Document into PDF");
	}
	finally 
	{		
		fos.close();
		if (document.isOpen()) {
			document.close();		
		}
	}
}
 
开发者ID:IMS-MAXIMS,项目名称:openMAXIMS,代码行数:37,代码来源:DocumentHelper.java

示例11: addText

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
private void addText(String text, int x, int y, BaseFont font,int fontSize,PdfWriter writer) throws DocumentException, IOException {
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();
    cb.beginText();
    cb.setFontAndSize(font, fontSize);
    float n = 0;
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text, x, y, n);
    cb.endText();
    cb.restoreState();
}
 
开发者ID:rbraam,项目名称:vanenapp,代码行数:11,代码来源:PrintCertificateActionBean.java

示例12: addTextAndImage

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
private void addTextAndImage(PcGtsType pc, int cutoffLeft, int cutoffTop, Image img, boolean imageOnly) throws DocumentException, IOException {
		lineAndColorList.clear();
		
		PdfContentByte cb = writer.getDirectContentUnder();

		cb.setColorFill(BaseColor.BLACK);
		cb.setColorStroke(BaseColor.BLACK);
		//BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, "UTF-8", BaseFont.NOT_EMBEDDED);
		if (!imageOnly){
			cb.beginLayer(ocrLayer);
			cb.setFontAndSize(bfArial, 32);
					
			List<TrpRegionType> regions = pc.getPage().getTextRegionOrImageRegionOrLineDrawingRegion();
			
			/*
			 * use reading order comparator for sorting since at this time reading order is more trustable
			 * other sorting is not transitive and seldomly produces "Comparison violates its general contract" exception
			 */
			Collections.sort(regions, new TrpElementReadingOrderComparator<RegionType>(true));
	
			for(RegionType r : regions){
				//TODO add paths for tables etc.
				if(r instanceof TextRegionType){
					TextRegionType tr = (TextRegionType)r;
					//PageXmlUtils.buildPolygon(tr.getCoords().getPoints()).getBounds().getMinX();
					addTextFromTextRegion(tr, cb, cutoffLeft, cutoffTop, bfArial);
				}
			}
			
			//scale after calculating lineMeanHeightForAllRegions
			//lineMeanHeight = lineMeanHeight/scaleFactorX;
			
			cb.endLayer();
		}
				
		cb.beginLayer(imgLayer);		
		cb.addImage(img);
		cb.endLayer();
		
		if (highlightTags){
			
			highlightAllTagsOnImg(lineAndColorList, cb, cutoffLeft, cutoffTop);
		}
		
		/*
		 * draw tag lines
		 */
		

		
//		addTocLinks(doc, page,cutoffTop);
	}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:53,代码来源:TrpPdfDocument.java

示例13: applyWatermarkOnAllPages

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public static void applyWatermarkOnAllPages(
	PdfReader reader, PdfStamper stamper, String text, BaseColor color, float opacity
) throws DocumentException, IOException {
	
	int numberOfPages = reader.getNumberOfPages();
	
	PdfGState gs = new PdfGState();
	gs.setFillOpacity(opacity);

	for (int i = 1; i <= numberOfPages; i++) {
		Rectangle pageSize = reader.getPageSize(i);
		int pageRotation = reader.getPageRotation(i);
		
		boolean isLandscape = false;
		if(pageRotation > 0){
			isLandscape = true;
		}
		
		int pageDiagonalSize = getDiagonalSize(pageSize);
		int watermarkAngle = getDiagonalAngle(pageSize, pageDiagonalSize, isLandscape);
		
		LinkedHashSet<Integer> fontSizeSet = new LinkedHashSet<Integer>();
		float fontSize = determineFontSize(pageDiagonalSize, a4WatermarkFontSize, fontSizeSet);
		fontSize = fontSize - 1;
		
		int cornerPlacement = getCornerPlacementDiagonal(fontSize);
		
		PdfContentByte underContent = stamper.getUnderContent(i);
		underContent.setGState(gs);
		underContent.setFontAndSize(getWaterkmarkFont(), fontSize);
		underContent.setColorFill(color);
		underContent.beginText();
		underContent.showTextAligned(
			Element.ALIGN_BASELINE, text, 
			cornerPlacement/2,
			cornerPlacement/2,
			watermarkAngle
		);
		underContent.endText();
	}
}
 
开发者ID:MatheusArleson,项目名称:PdfUtil,代码行数:42,代码来源:PdfWatermarker.java

示例14: testCreateLinkWithAppearance

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/34734669/define-background-color-and-transparency-of-link-annotation-in-pdf">
 * Define background color and transparency of link annotation in PDF
 * </a>
 * <p>
 * This test creates a link annotation with custom appearance. Adobe Reader chooses
 * to ignore it but other viewers use it. Interestingly Adobe Acrobat export-as-image
 * does use the custom appearance...
 * </p>
 */
@Test
public void testCreateLinkWithAppearance() throws IOException, DocumentException
{
    Document doc = new Document();
    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(new File(RESULT_FOLDER, "custom-link.appearance.pdf")));
    writer.setCompressionLevel(0);
    doc.open();

    BaseFont baseFont = BaseFont.createFont();
    int fontSize = 15;
    doc.add(new Paragraph("Hello", new Font(baseFont, fontSize)));
    
    PdfContentByte content = writer.getDirectContent();
    
    String text = "Test";
    content.setFontAndSize(baseFont, fontSize);
    content.beginText();
    content.moveText(100, 500);
    content.showText(text);
    content.endText();
    
    Rectangle linkLocation = new Rectangle(95, 495 + baseFont.getDescentPoint(text, fontSize),
            105 + baseFont.getWidthPoint(text, fontSize), 505 + baseFont.getAscentPoint(text, fontSize));

    PdfAnnotation linkGreen = PdfAnnotation.createLink(writer, linkLocation, PdfName.HIGHLIGHT, "green" );
    PdfTemplate appearance = PdfTemplate.createTemplate(writer, linkLocation.getWidth(), linkLocation.getHeight());
    PdfGState state = new PdfGState();
    //state.FillOpacity = .3f;
    // IMPROVEMENT: Use blend mode Darken instead of transparency; you may also want to try Multiply.
    state.setBlendMode(new PdfName("Darken"));
    appearance.setGState(state);

    appearance.setColorFill(BaseColor.GREEN);
    appearance.rectangle(0, 0, linkLocation.getWidth(), linkLocation.getHeight());
    appearance.fill();
    linkGreen.setAppearance(PdfName.N, appearance);
    writer.addAnnotation(linkGreen);

    doc.open();
    doc.close();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:52,代码来源:CreateLink.java

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