本文整理匯總了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);
}
}
示例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();
}
示例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();
}
}
示例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;
}
示例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 +" ]");
}
示例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);
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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] );
}
示例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();
}