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


Java PdfContentByte类代码示例

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


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

示例1: exportVectorGraphics

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
private void exportVectorGraphics(String formatName, File outputFile) throws ImageExportException {
	Component component = printableComponent.getExportComponent();
	int width = component.getWidth();
	int height = component.getHeight();
	try (FileOutputStream fs = new FileOutputStream(outputFile)) {
		switch (formatName) {
			case PDF:
				// create pdf document with slightly increased width and height
				// (otherwise the image gets cut off)
				Document document = new Document(new Rectangle(width + 5, height + 5));
				PdfWriter writer = PdfWriter.getInstance(document, fs);
				document.open();
				PdfContentByte cb = writer.getDirectContent();
				PdfTemplate tp = cb.createTemplate(width, height);
				Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
				component.print(g2);
				g2.dispose();
				cb.addTemplate(tp, 0, 0);
				document.close();
				break;
			case SVG:
				exportFreeHep(component, fs, new SVGGraphics2D(fs, new Dimension(width, height)));
				break;
			case EPS:
				exportFreeHep(component, fs, new PSGraphics2D(fs, new Dimension(width, height)));
				break;
			default:
				// cannot happen
				break;
		}
	} catch (Exception e) {
		throw new ImageExportException(I18N.getMessage(I18N.getUserErrorMessagesBundle(),
				"error.image_export.export_failed"), e);
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:36,代码来源:ImageExporter.java

示例2: drawLine

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
 * Draws a horizontal line.
 * @param canvas	the canvas to draw on
 * @param leftX		the left x coordinate
 * @param rightX	the right x coordindate
 * @param y			the y coordinate
 */
public void drawLine(PdfContentByte canvas, float leftX, float rightX, float y) {
	float w;
    if (getPercentage() < 0)
        w = -getPercentage();
    else
        w = (rightX - leftX) * getPercentage() / 100.0f;
    float s;
    switch (getAlignment()) {
        case Element.ALIGN_LEFT:
            s = 0;
            break;
        case Element.ALIGN_RIGHT:
            s = rightX - leftX - w;
            break;
        default:
            s = (rightX - leftX - w) / 2;
            break;
    }
    canvas.setLineWidth(getLineWidth());
    if (getLineColor() != null)
        canvas.setColorStroke(getLineColor());
    canvas.moveTo(s + leftX, y + offset);
    canvas.lineTo(s + w + leftX, y + offset);
    canvas.stroke();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:33,代码来源:LineSeparator.java

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

示例4: onEndPage

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
   * Print footer string on each page
   * @param writer
   * @param document
   */
  public void onEndPage(PdfWriter writer, Document document) {
   
  	if(getDateTime() == null) {
  		setDateTime(new Date());
  	}
  	
PdfContentByte cb = writer.getDirectContent();
cb.beginText();
cb.setFontAndSize(getBaseFont(), getFontSize());
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getDateFormat().format(getDateTime()), 
	    document.left(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, String.valueOf(document.getPageNumber()), 
	    document.right(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, MESSAGES.pdfCopyright(Constants.getVersion()),
		(document.left() + document.right()) / 2, 20, 0);
cb.endText();
	
      return;
  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:25,代码来源:PdfEventHandler.java

示例5: startPage

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
 * Any work to start off printing a page of the document
 * m_currentPage will contain the page being printed, and
 * m_currentTemplatePage will contain the template page number to base this
 * new page on.
 * @throws FormPrintException Thrown if there is any form processing problems
 */
protected void startPage() throws FormPrintException {
    log.debug("startPage: Page=" + getCurrentPage());

    Rectangle r = m_templateReader.getPageSize(getCurrentTemplatePage());
    log.debug( "Page Size      : t="+r.getTop()+",l="+r.getLeft()+",b="+r.getBottom()+",r="+r.getRight()+", rot="+r.getRotation() );
    r = m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage());
    log.debug( "Page Size w/Rot: t="+r.getTop()+",l="+r.getLeft()+",b="+r.getBottom()+",r="+r.getRight()+", rot="+r.getRotation() );

    // Get rotation quadrent 0..3
    int q = (m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()).getRotation() % 360)/90;
    float tX = (q==2?r.getTop():0)+(q==3?r.getRight():0);
    float tY = (q==1?r.getTop():0)+(q==2?r.getRight():0);
    float sX=1f, sY=1f;
    double angle = -r.getRotation()*(Math.PI/180f);
    double transformA = sX * Math.cos(angle);
    double transformB = sY * Math.sin(angle);
    double transformC = -sX * Math.sin(angle);
    double transformD = sY * Math.cos(angle);
    double transformE = tX;
    double transformF = tY;


    m_generatedDoc.setPageSize(m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()) );
    //m_generatedDoc.setPageSize(m_templateReader.getPageSize(getCurrentTemplatePage()) );
    /**
     * try {
     * m_generatedDoc.newPage();
     * } catch (DocumentException e) {
     * log.error("Error Creating New Page - " + e.getMessage() ,e);
     * throw new EngineProcessingException("Error Creating New Page - " + e.getMessage());
     * }
     **/
    m_generatedDoc.newPage();

    PdfImportedPage page = m_writer.getImportedPage(m_templateReader, getCurrentTemplatePage() );
    PdfContentByte cb = m_writer.getDirectContent();
    //cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
    cb.addTemplate(page, (float)transformA, (float)transformB, (float)transformC,
                         (float)transformD, (float)transformE, (float)transformF);
    log.debug("Matrix = [A=" + transformA +", B=" + transformB +", C=" + transformC +
                      ", D=" + transformD +", E=" + transformE +", F=" + transformF +" ]");
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:50,代码来源:FormPrintEngineIText.java

示例6: getInstance

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
 * Gets an instance of a Image from a java.awt.Image.
 * The image is added as a JPEG with a user defined quality.
 *
 * @param cb
 *            the <CODE>PdfContentByte</CODE> object to which the image will be added
 * @param awtImage
 *            the <CODE>java.awt.Image</CODE> to convert
 * @param quality
 *            a float value between 0 and 1
 * @return an object of type <CODE>PdfTemplate</CODE>
 * @throws BadElementException
 *             on error
 * @throws IOException
 */
public static Image getInstance(PdfContentByte cb, java.awt.Image awtImage, float quality) throws BadElementException, IOException {
    java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(awtImage,
            0, 0, -1, -1, true);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        throw new IOException(
                "java.awt.Image Interrupted waiting for pixels!");
    }
    if ((pg.getStatus() & java.awt.image.ImageObserver.ABORT) != 0) {
        throw new IOException("java.awt.Image fetch aborted or errored");
    }
    int w = pg.getWidth();
    int h = pg.getHeight();
    PdfTemplate tp = cb.createTemplate(w, h);
    Graphics2D g2d = tp.createGraphics(w, h, true, quality);
    g2d.drawImage(awtImage, 0, 0, null);
    g2d.dispose();
    return getInstance(tp);
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:36,代码来源:Image.java

示例7: main

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
 * Draws arabic text using java.awt.Graphics2D.
    */
@Test
public void main() throws Exception {
   	// step 1
       Document document = new Document(PageSize.A4, 50, 50, 50, 50);
       try {
       	// step 2
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "arabictext.pdf"));
           // step 3
           document.open();
           // step 4
           String text1 = "This text has \u0634\u0627\u062f\u062c\u0645\u0647\u0648\u0631 123,456 \u0645\u0646 (Arabic)";
           java.awt.Font font = new java.awt.Font("arial", 0, 18);
           PdfContentByte cb = writer.getDirectContent();
           java.awt.Graphics2D g2 = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight());
           g2.setFont(font);
           g2.drawString(text1, 100, 100);
           g2.dispose();
           cb.sanityCheck();
           // step 5
           document.close();
       }
       catch (Exception de) {
           de.printStackTrace();
       }
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:29,代码来源:ArabicTextTest.java

示例8: footer

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
public void footer() {
       PdfContentByte cb = writer.getDirectContent();
       cb.saveState();

       Date now = new Date();
       String promoTxt = OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT");
       if( promoTxt == null ) {
           promoTxt = new String();
       }

       String strFooter = promoTxt + " " + formatter.format(now);

       float textBase = document.bottom();
       cb.beginText();
       cb.setFontAndSize(font.getBaseFont(),FONTSIZE);
       Rectangle page = document.getPageSize();
       float width = page.getWidth();

       cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase - 20, 0);

       strFooter = "-" + writer.getPageNumber() + "-";
       cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width/2.0f), textBase-10, 0);

       cb.endText();
       cb.restoreState();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:27,代码来源:PdfRecordPrinter.java

示例9: main

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
@Test
public void main() throws Exception {

	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	PdfWriter writer = PdfWriter.getInstance(document,	PdfTestBase.getOutputStream( "shading.pdf"));
	document.open();

	PdfFunction function1 = PdfFunction.type2(writer, new float[] { 0, 1 },
			null, new float[] { .929f, .357f, 1, .298f }, new float[] {
					.631f, .278f, 1, .027f }, 1.048f);
	PdfFunction function2 = PdfFunction.type2(writer, new float[] { 0, 1 },
			null, new float[] { .929f, .357f, 1, .298f }, new float[] {
					.941f, .4f, 1, .102f }, 1.374f);
	PdfFunction function3 = PdfFunction.type3(writer, new float[] { 0, 1 },
			null, new PdfFunction[] { function1, function2 },
			new float[] { .708f }, new float[] { 1, 0, 0, 1 });
	PdfShading shading = PdfShading.type3(writer,
			new CMYKColor(0, 0, 0, 0),
			new float[] { 0, 0, .096f, 0, 0, 1 }, null, function3,
			new boolean[] { true, true });
	PdfContentByte cb = writer.getDirectContent();
	cb.moveTo(316.789f, 140.311f);
	cb.curveTo(303.222f, 146.388f, 282.966f, 136.518f, 279.122f, 121.983f);
	cb.lineTo(277.322f, 120.182f);
	cb.curveTo(285.125f, 122.688f, 291.441f, 121.716f, 298.156f, 119.386f);
	cb.lineTo(336.448f, 119.386f);
	cb.curveTo(331.072f, 128.643f, 323.346f, 137.376f, 316.789f, 140.311f);
	cb.clip();
	cb.newPath();
	cb.saveState();
	cb.concatCTM(27.7843f, 0, 0, -27.7843f, 310.2461f, 121.1521f);
	cb.paintShading(shading);
	cb.restoreState();

	cb.sanityCheck();

	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:39,代码来源:ShadingTest.java

示例10: main

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
 * Generates an Acroform with a Combobox
 */
@Test
public void main() throws Exception {

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

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

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

	// step 4:
	PdfContentByte cb = writer.getDirectContent();
	cb.moveTo(0, 0);
	String options[] = { "Red", "Green", "Blue" };
	PdfFormField field = PdfFormField.createCombo(writer, true, options, 0);
	field.setWidget(new Rectangle(100, 700, 180, 720), PdfAnnotation.HIGHLIGHT_INVERT);
	field.setFieldName("ACombo");
	field.setValueAsString("Red");
	writer.addAnnotation(field);

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

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

示例12: tableLayout

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
 * @see com.lowagie.text.pdf.PdfPTableEvent#tableLayout(com.lowagie.text.pdf.PdfPTable,
 *      float[][], float[], int, int, com.lowagie.text.pdf.PdfContentByte[])
 */
public void tableLayout(PdfPTable table, float[][] width, float[] height, int headerRows, int rowStart,
		PdfContentByte[] canvases) {
	float widths[] = width[0];
	float x1 = widths[0];
	float x2 = widths[widths.length - 1];
	float y1 = height[0];
	float y2 = height[height.length - 1];
	PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
	canvas.setRGBColorStroke(0x00, 0x00, 0xFF);
	canvas.rectangle(x1, y1, x2 - x1, y2 - y1);
	canvas.stroke();
	canvas.resetRGBColorStroke();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:18,代码来源:FloatingBoxesTest.java

示例13: main

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
 * Break a large table up into several smaller tables for memory management
 * purposes.
 * 
 */
@Test
public void main() throws Exception {
	// step1
	Document document = new Document(PageSize.A4, 10, 10, 10, 10);
	// step2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("SplitTable.pdf"));
	// step3
	document.open();
	// step4

	PdfContentByte cb = writer.getDirectContent();
	PdfPTable table = new PdfPTable(10);
	for (int k = 1; k <= 100; ++k) {
		table.addCell("The number " + k);
	}
	table.setTotalWidth(800);
	table.writeSelectedRows(0, 5, 0, -1, 50, 650, cb);
	document.newPage();
	table.writeSelectedRows(5, -1, 0, -1, 50, 650, cb);
	document.close();

	// step5
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:30,代码来源:SplitTableTest.java

示例14: setCheckboxAppearance

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
private void setCheckboxAppearance( PdfFormField checkboxfield, PdfContentByte canvas, float width )
{
    PdfAppearance[] onOff = new PdfAppearance[2];
    onOff[0] = canvas.createAppearance( width + 2, width + 2 );
    onOff[0].rectangle( 1, 1, width, width );
    onOff[0].stroke();
    onOff[1] = canvas.createAppearance( width + 2, width + 2 );
    onOff[1].setRGBColorFill( 255, 128, 128 );
    onOff[1].rectangle( 1, 1, width, width );
    onOff[1].fillStroke();
    onOff[1].moveTo( 1, 1 );
    onOff[1].lineTo( width + 1, width + 1 );
    onOff[1].moveTo( 1, width + 1 );
    onOff[1].lineTo( width + 1, 1 );
    onOff[1].stroke();

    checkboxfield.setAppearance( PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0] );
    checkboxfield.setAppearance( PdfAnnotation.APPEARANCE_NORMAL, "On", onOff[1] );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:20,代码来源:DefaultPdfDataEntryFormService.java

示例15: footer

import com.lowagie.text.pdf.PdfContentByte; //导入依赖的package包/类
public void footer() {
	PdfContentByte cb = writer.getDirectContent();
	cb.saveState();

	Date now = new Date();
	String promoTxt = OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT");
	if (promoTxt == null) {
		promoTxt = new String();
	}

	String strFooter = promoTxt + " " + formatter.format(now);

	float textBase = document.bottom();
	cb.beginText();
	cb.setFontAndSize(font.getBaseFont(), FONTSIZE);
	Rectangle page = document.getPageSize();
	float width = page.getWidth();

	cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width / 2.0f), textBase - 20, 0);

	strFooter = "-" + writer.getPageNumber() + "-";
	cb.showTextAligned(PdfContentByte.ALIGN_CENTER, strFooter, (width / 2.0f), textBase - 10, 0);

	cb.endText();
	cb.restoreState();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:27,代码来源:TicklerPrinter.java


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