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


Java PdfContentByte.setColorFill方法代码示例

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


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

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

示例2: placeBarcode

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 *
 * @param cb
 * @param foreground
 * @param moduleSide
 */
public void placeBarcode(PdfContentByte cb, Color foreground, float moduleSide) {

    int width = bm.getWidth();
    int height = bm.getHeight();
    byte[][] mt = bm.getArray();

    cb.setColorFill(foreground);

    for (int y = 0; y < height; ++y) {
        byte[] line = mt[y];
        for (int x = 0; x < width; ++x) {
            if (line[x] == 0) {
                cb.rectangle(x * moduleSide, (height - y - 1) * moduleSide, moduleSide, moduleSide);
            }
        }
    }

    cb.fill();
}
 
开发者ID:TerrenceMiao,项目名称:camel-spring,代码行数:26,代码来源:BarcodeQRCode.java

示例3: pictureBackdrop

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Prints a square and fills half of it with a gray rectangle.
 * @param x
 * @param y
 * @param cb
 * @throws Exception
 */
public static void pictureBackdrop(float x, float y, PdfContentByte cb) throws Exception {
    cb.setColorStroke(Color.black);
    cb.setColorFill(Color.red);
    cb.rectangle(x, y, 100, 200);
    cb.fill();
    cb.setLineWidth(2);
    cb.rectangle(x, y, 200, 200);
    cb.stroke();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:17,代码来源:GroupsTest.java

示例4: pictureCircles

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Prints 3 circles in different colors that intersect with eachother.
 * @param x
 * @param y
 * @param cb
 * @throws Exception
 */
public static void pictureCircles(float x, float y, PdfContentByte cb) throws Exception {
	PdfGState gs = new PdfGState();
	gs.setBlendMode(PdfGState.BM_SOFTLIGHT);
	gs.setFillOpacity(0.7f);
	cb.setGState(gs);
    cb.setColorFill(Color.gray);
    cb.circle(x + 70, y + 70, 50);
    cb.fill();
    cb.circle(x + 100, y + 130, 50);
    cb.fill();
    cb.circle(x + 130, y + 70, 50);
    cb.fill();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:21,代码来源:GroupsTest.java

示例5: pictureBackdrop

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Prints a square and fills half of it with a gray rectangle.
 * 
 * @param x
 * @param y
 * @param cb
 * @throws Exception
 */
private static void pictureBackdrop(float x, float y, PdfContentByte cb)
		throws Exception {
	cb.setColorStroke(Color.black);
	cb.setColorFill(Color.gray);
	cb.rectangle(x, y, 100, 200);
	cb.fill();
	cb.setLineWidth(2);
	cb.rectangle(x, y, 200, 200);
	cb.stroke();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:19,代码来源:TransparencyTest.java

示例6: pictureCircles

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Prints 3 circles in different colors that intersect with eachother.
 * 
 * @param x
 * @param y
 * @param cb
 * @throws Exception
 */
private static void pictureCircles(float x, float y, PdfContentByte cb)
		throws Exception {
	cb.setColorFill(Color.red);
	cb.circle(x + 70, y + 70, 50);
	cb.fill();
	cb.setColorFill(Color.yellow);
	cb.circle(x + 100, y + 130, 50);
	cb.fill();
	cb.setColorFill(Color.blue);
	cb.circle(x + 130, y + 70, 50);
	cb.fill();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:21,代码来源:TransparencyTest.java

示例7: main

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Changing the Graphics State with saveState() and restoreState().
 * 
 */
@Test
public void main() throws Exception {

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

	try {

		// step 2:
		// we create a writer that listens to the document
		// and directs a PDF-stream to a file
		PdfWriter writer = PdfWriter.getInstance(document,
				PdfTestBase.getOutputStream( "state.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();

		cb.circle(260.0f, 500.0f, 250.0f);
		cb.fill();
		cb.saveState();
		cb.setColorFill(Color.red);
		cb.circle(260.0f, 500.0f, 200.0f);
		cb.fill();
		cb.saveState();
		cb.setColorFill(Color.blue);
		cb.circle(260.0f, 500.0f, 150.0f);
		cb.fill();
		cb.restoreState();
		cb.circle(260.0f, 500.0f, 100.0f);
		cb.fill();
		cb.restoreState();
		cb.circle(260.0f, 500.0f, 50.0f);
		cb.fill();
		
		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,代码行数:52,代码来源:StateTest.java

示例8: main

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Changing the Graphics State with PdfGState.
 * 
 */
@Test
public void main() throws Exception {

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

	try {

		// step 2:
		// we create a writer that listens to the document
		// and directs a PDF-stream to a file
		PdfWriter writer = PdfWriter.getInstance(document,
				PdfTestBase.getOutputStream( "gstate.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();

           PdfGState gs = new PdfGState();
           gs.setFillOpacity(0.5f);
           cb.setGState(gs);
		cb.setColorFill(Color.red);
		cb.circle(260.0f, 500.0f, 250.0f);
		cb.fill();
		cb.circle(260.0f, 500.0f, 200.0f);
		cb.fill();
		cb.circle(260.0f, 500.0f, 150.0f);
		cb.fill();
		gs.setFillOpacity(0.2f);
		cb.setGState(gs);
		cb.setColorFill(Color.blue);
		cb.circle(260.0f, 500.0f, 100.0f);
		cb.fill();
		cb.circle(260.0f, 500.0f, 50.0f);
		cb.fill();
		
		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,代码行数:53,代码来源:GStateTest.java

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

示例10: main

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * Creates a document with some PdfAnnotations.
 * 
 */
@Test
public void main() throws Exception {

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

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Annotations.pdf"));
	// step 3:
	writer.setPdfVersion(PdfWriter.VERSION_1_5);
	document.open();
	// step 4:
	PdfContentByte cb = writer.getDirectContent();
	// page 1
	PdfFileSpecification fs = PdfFileSpecification.fileExtern(writer, PdfTestBase.RESOURCES_DIR + "cards.mpg");
	writer.addAnnotation(PdfAnnotation.createScreen(writer, new Rectangle(200f, 700f, 300f, 800f), "cards.mpg", fs,
			"video/mpeg", true));
	PdfAnnotation a = new PdfAnnotation(writer, 200f, 550f, 300f, 650f, PdfAction.javaScript(
			"app.alert('Hello');\r", writer));
	document.add(new Chunk("click to trigger javascript").setAnnotation(a).setLocalDestination("top"));
	writer.addAnnotation(a);
	writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 650f, 150f, 700f),
			"This is some text", "some text".getBytes(), null, "some.txt"));
	writer.addAnnotation(PdfAnnotation.createText(writer, new Rectangle(200f, 400f, 300f, 500f), "Help",
			"This Help annotation was made with 'createText'", false, "Help"));
	writer.addAnnotation(PdfAnnotation.createText(writer, new Rectangle(200f, 250f, 300f, 350f), "Help",
			"This Comment annotation was made with 'createText'", true, "Comment"));
	cb.rectangle(200, 700, 100, 100);
	cb.rectangle(200, 550, 100, 100);
	cb.rectangle(200, 400, 100, 100);
	cb.rectangle(200, 250, 100, 100);
	cb.stroke();
	document.newPage();
	// page 2
	writer.addAnnotation(PdfAnnotation.createLink(writer, new Rectangle(200f, 700f, 300f, 800f),
			PdfAnnotation.HIGHLIGHT_TOGGLE, PdfAction.javaScript("app.alert('Hello');\r", writer)));
	writer.addAnnotation(PdfAnnotation.createLink(writer, new Rectangle(200f, 550f, 300f, 650f),
			PdfAnnotation.HIGHLIGHT_OUTLINE, "top"));
	writer.addAnnotation(PdfAnnotation.createLink(writer, new Rectangle(200f, 400f, 300f, 500f),
			PdfAnnotation.HIGHLIGHT_PUSH, 1, new PdfDestination(PdfDestination.FIT)));
	writer.addAnnotation(PdfAnnotation.createSquareCircle(writer, new Rectangle(200f, 250f, 300f, 350f),
			"This Comment annotation was made with 'createSquareCircle'", false));
	document.newPage();
	// page 3
	PdfContentByte pcb = new PdfContentByte(writer);
	pcb.setColorFill(new Color(0xFF, 0x00, 0x00));
	writer.addAnnotation(PdfAnnotation.createFreeText(writer, new Rectangle(200f, 700f, 300f, 800f),
			"This is some free text, blah blah blah", pcb));
	writer.addAnnotation(PdfAnnotation.createLine(writer, new Rectangle(200f, 550f, 300f, 650f), "this is a line",
			200, 550, 300, 650));
	writer.addAnnotation(PdfAnnotation.createStamp(writer, new Rectangle(200f, 400f, 300f, 500f),
			"This is a stamp", "Stamp"));
	writer.addAnnotation(PdfAnnotation.createPopup(writer, new Rectangle(200f, 250f, 300f, 350f),
			"Hello, I'm a popup!", true));
	cb.rectangle(200, 700, 100, 100);
	cb.rectangle(200, 550, 100, 100);
	cb.rectangle(200, 250, 100, 100);
	cb.stroke();

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

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

示例12: addFooterAndWater

import com.lowagie.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 *	添加水印、页眉、页脚
 * @param fileName 源文件路径
 * @param savepath 目标文件路径
 * @param waterMarkName 文字水印
 * @param pageHeade 页眉
 * @param foot 页脚
 * @return
 */
public static int addFooterAndWater(String fileName, String savepath, String waterMarkName, String pageHeade, String foot) {
	// 文档总页数
	int num = 0;

	Document document = new Document();
	try {
		PdfReader reader = new PdfReader(fileName);
		//BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.EMBEDDED);
		BaseFont base = BaseFont.createFont(BaseFont.COURIER, "utf-8", BaseFont.EMBEDDED);

		num = reader.getNumberOfPages();
		PdfCopy copy = new PdfCopy(document, new FileOutputStream(savepath));
		document.open();
		for (int i = 0; i < num;) {
			PdfImportedPage page = copy.getImportedPage(reader, ++i);
			PageStamp stamp = copy.createPageStamp(page);
			Font f = new Font(base);

			// 添加页脚,左侧文字,右侧页码
			ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_RIGHT, new Phrase(String.format("第 %d 页/共 %d 页", i, num),
					f), 550f, 28, 0);
			ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_LEFT, new Phrase(foot, f), 50f, 28, 0);

			// 添加页眉 (文字页眉,居中)
			ColumnText.showTextAligned(stamp.getUnderContent(), Element.ALIGN_CENTER, new Phrase(pageHeade, f), 150f, 800, 0);

			// 页眉添加logo (图片页眉,居右)
			Image img = Image.getInstance("F:\\Tools\\pdf2swf工具\\resource/watermark.png");//"template/logo.png");// 选择图片
			img.setAlignment(1);
			img.scaleAbsolute(436 / 5, 96 / 5);// 控制图片大小
			img.setAbsolutePosition(450f, 800);// 控制图片位置
			stamp.getUnderContent().addImage(img);

			// 添加水印
			PdfContentByte under = stamp.getUnderContent();
			under.beginText();
			under.setColorFill(Color.LIGHT_GRAY);

			// 字符越长,字体越小,设置字体
			int fontSize = getFontSize(waterMarkName);
			under.setFontAndSize(base, fontSize);

			// 设置水印文字字体倾斜 开始
			float pageWidth = reader.getPageSize(i).getWidth();
			float pageHeight = reader.getPageSize(i).getHeight();

			// 水印文字成60度角倾斜,且页面居中展示
			//under.showTextAligned(Element.ALIGN_CENTER, waterMarkName, pageWidth / 2, pageHeight / 2, 60);

			img.setAlignment(1);
			img.scaleAbsolute(636 / 5, 126 / 5);// 控制图片大小
			img.setAbsolutePosition(pageWidth / 2, pageHeight / 2);// 控制图片位置
			img.setRotation(60);
			stamp.getUnderContent().addImage(img);

			// 字体设置结束
			under.endText();
			stamp.alterContents();
			copy.addPage(page);
		}
	} catch (Exception e) {
		e.printStackTrace();
		return -1;
	} finally {
		if (null != document) {
			document.close();
		}
	}
	System.out.println("pdf totalpages:" + num);
	return num;

}
 
开发者ID:pecker,项目名称:kony-converter,代码行数:82,代码来源:OfficeToPdf.java


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