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


Java Rectangle.setBackgroundColor方法代碼示例

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


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

示例1: writeBorderAndBackground

import com.lowagie.text.Rectangle; //導入方法依賴的package包/類
/**
 * Writes the border and background of one cell in the row.
 * 
 * @param xPos The x-coordinate where the table starts on the canvas
 * @param yPos The y-coordinate where the table starts on the canvas
 * @param currentMaxHeight The height of the cell to be drawn.
 * @param cell
 * @param canvases
 * @since	2.1.6	extra parameter currentMaxHeight
 */
public void writeBorderAndBackground(float xPos, float yPos, float currentMaxHeight, PdfPCell cell, PdfContentByte[] canvases) {
	Color background = cell.getBackgroundColor();
	if (background != null || cell.hasBorders()) {
		// Add xPos resp. yPos to the cell's coordinates for absolute coordinates
		float right = cell.getRight() + xPos;
		float top = cell.getTop() + yPos;
		float left = cell.getLeft() + xPos;
		float bottom = top - currentMaxHeight;
		
		if (background != null) {
			PdfContentByte backgr = canvases[PdfPTable.BACKGROUNDCANVAS];
			backgr.setColorFill(background);
			backgr.rectangle(left, bottom, right - left, top - bottom);
			backgr.fill();
		}
		if (cell.hasBorders()) {
			Rectangle newRect = new Rectangle(left, bottom, right, top);
			// Clone non-position parameters except for the background color
			newRect.cloneNonPositionParameters(cell);
			newRect.setBackgroundColor(null);
			// Write the borders on the line canvas
			PdfContentByte lineCanvas = canvases[PdfPTable.LINECANVAS];
			lineCanvas.rectangle(newRect);
		}
	}
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:37,代碼來源:PdfPRow.java

示例2: main

import com.lowagie.text.Rectangle; //導入方法依賴的package包/類
/**
 * Creates a PDF document with a certain pagesize
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Rectangle pageSize = new Rectangle(216, 720);
	pageSize.setBackgroundColor(new java.awt.Color(0xFF, 0xFF, 0xDE));
	Document document = new Document(pageSize);

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file

	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CustomPageSize.pdf"));

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

	// step 4: we add some paragraphs to the document
	document.add(new Paragraph("The size of this page is 216x720 points."));
	document.add(new Paragraph("216pt / 72 points per inch = 3 inch"));
	document.add(new Paragraph("720pt / 72 points per inch = 10 inch"));
	document.add(new Paragraph("The size of this page is 3x10 inch."));
	document.add(new Paragraph("3 inch x 2.54 = 7.62 cm"));
	document.add(new Paragraph("10 inch x 2.54 = 25.4 cm"));
	document.add(new Paragraph("The size of this page is 7.62x25.4 cm."));
	document.add(new Paragraph("The backgroundcolor of the Rectangle used for this PageSize, is #FFFFDE."));
	document.add(new Paragraph("That's why the background of this document is yellowish..."));

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:35,代碼來源:CustomPageSizeTest.java

示例3: main

import com.lowagie.text.Rectangle; //導入方法依賴的package包/類
/**
    * PdfTemplates can be wrapped in an Image.
    */
@Test
   public  void main() throws Exception {
       
           
       // step 1: creation of a document-object
       Rectangle rect = new Rectangle(PageSize.A4);
       rect.setBackgroundColor(new Color(238, 221, 88));
       Document document = new Document(rect, 50, 50, 50, 50);
	// step 2: we create a writer that listens to the document
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("templateImages.pdf"));
	// step 3: we open the document
	document.open();
	// step 4:
	PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
	BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
			BaseFont.NOT_EMBEDDED);
	String text = "Vertical";
	float size = 16;
	float width = bf.getWidthPoint(text, size);
	template.beginText();
	template.setRGBColorFillF(1, 1, 1);
	template.setFontAndSize(bf, size);
	template.setTextMatrix(0, 2);
	template.showText(text);
	template.endText();
	template.setWidth(width);
	template.setHeight(size + 2);
	template.sanityCheck();
	Image img = Image.getInstance(template);
	img.setRotationDegrees(90);
	Chunk ck = new Chunk(img, 0, 0);
	PdfPTable table = new PdfPTable(3);
	table.setWidthPercentage(100);
	table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
	table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
	PdfPCell cell = new PdfPCell(img);
	cell.setPadding(4);
	cell.setBackgroundColor(new Color(0, 0, 255));
	cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");
	table.addCell(cell);
	table.addCell("I see a template everywhere");
	table.addCell(cell);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");

	Paragraph p1 = new Paragraph("This is a template ");
	p1.add(ck);
	p1.add(" just here.");
	p1.setLeading(img.getScaledHeight() * 1.1f);
	document.add(p1);
	document.add(table);
	Paragraph p2 = new Paragraph("More templates ");
	p2.setLeading(img.getScaledHeight() * 1.1f);
	p2.setAlignment(Element.ALIGN_JUSTIFIED);
	img.scalePercent(70);
	for (int k = 0; k < 20; ++k)
		p2.add(ck);
	document.add(p2);
	// step 5: we close the document
	document.close();

   }
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:70,代碼來源:TemplateImagesTest.java

示例4: main

import com.lowagie.text.Rectangle; //導入方法依賴的package包/類
/**
 * Generates a StudentCard
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Rectangle rect = new Rectangle(243, 153);
	rect.setBackgroundColor(new Color(0xFF, 0xFF, 0xCC));
	Document document = new Document(rect, 10, 10, 10, 10);

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("studentcard.pdf"));

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

	// step 4:
	Font font = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, Color.BLUE);
	Paragraph p = new Paragraph("Ghent University", font);
	p.setAlignment(Element.ALIGN_CENTER);
	document.add(p);
	PdfContentByte cb = writer.getDirectContent();
	Font f = FontFactory.getFont(FontFactory.HELVETICA, 8);
	PdfPTable outertable = new PdfPTable(3);
	outertable.setTotalWidth(200);
	outertable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
	float[] outer = { 60, 25, 15 };
	outertable.setWidths(outer);
	PdfPTable innertable = new PdfPTable(2);
	float[] inner = { 35, 65 };
	innertable.setWidths(inner);
	innertable.addCell(new Paragraph("name:", f));
	innertable.addCell(new Paragraph("Bruno Lowagie", f));
	innertable.addCell(new Paragraph("date of birth:", f));
	innertable.addCell(new Paragraph("June 10th, 1970", f));
	innertable.addCell(new Paragraph("Study Program:", f));
	innertable.addCell(new Paragraph("master in civil engineering", f));
	innertable.addCell(new Paragraph("option:", f));
	innertable.addCell(new Paragraph("architecture", f));
	outertable.addCell(innertable);
	outertable.getDefaultCell().setBackgroundColor(new Color(0xFF, 0xDE, 0xAD));
	outertable.addCell(Image.getInstance(PdfTestBase.RESOURCES_DIR + "bruno.jpg"));
	BarcodeEAN codeEAN = new BarcodeEAN();
	codeEAN.setCodeType(Barcode.EAN13);
	codeEAN.setCode("8010012529736");
	Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
	imageEAN.setRotationDegrees(90);
	outertable.getDefaultCell().setBackgroundColor(Color.WHITE);
	outertable.addCell(imageEAN);
	outertable.writeSelectedRows(0, -1, 20, 100, writer.getDirectContent());

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:56,代碼來源:StudentCardTest.java

示例5: generatePdf

import com.lowagie.text.Rectangle; //導入方法依賴的package包/類
/**
 * Method that generates the actual PDF file.
 */
public void generatePdf() throws Exception {

	// step 1: creation of a document-object
	Rectangle pageSize = new Rectangle(780, 525);
	if (backgroundcolor != null) {
		pageSize.setBackgroundColor(backgroundcolor);
	}
	Document document = new Document(pageSize);

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file
	if (filename == null) {
		filename = PdfTestBase.OUTPUT_DIR + "dvdcover.pdf";
	}
	PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));

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

	// step 4:
	PdfContentByte cb = writer.getDirectContent();
	if (title != null) {
		cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false), 24);
		cb.beginText();
		if (front == null) {
			cb.showTextAligned(Element.ALIGN_CENTER, title, 595f, 262f, 0f);
		}
		if (side == null) {
			cb.showTextAligned(Element.ALIGN_CENTER, title, 385f, 262f, 270f);
		}
		cb.endText();
	}
	cb.moveTo(370, 0);
	cb.lineTo(370, 525);
	cb.moveTo(410, 525);
	cb.lineTo(410, 0);
	cb.stroke();
	if (front != null) {
		front.scaleToFit(370, 525);
		front.setAbsolutePosition(410f + (370f - front.getScaledWidth()) / 2f,
				(525f - front.getScaledHeight()) / 2f);
		document.add(front);
	}
	if (back != null) {
		back.scaleToFit(370, 525);
		back.setAbsolutePosition((370f - back.getScaledWidth()) / 2f, (525f - back.getScaledHeight()) / 2f);
		document.add(back);
	}
	if (side != null) {
		side.scaleToFit(40, 525);
		side.setAbsolutePosition(370 + (40f - side.getScaledWidth()) / 2f, (525f - side.getScaledHeight()) / 2f);
		document.add(side);
	}

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:62,代碼來源:DvdCoverTest.java


注:本文中的com.lowagie.text.Rectangle.setBackgroundColor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。