本文整理汇总了Java中com.itextpdf.text.pdf.PdfContentByte类的典型用法代码示例。如果您正苦于以下问题:Java PdfContentByte类的具体用法?Java PdfContentByte怎么用?Java PdfContentByte使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PdfContentByte类属于com.itextpdf.text.pdf包,在下文中一共展示了PdfContentByte类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildPdfDocument
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
public void buildPdfDocument(OutputStream toWrite, final String name, final int treeCount, String[] codeFragments, String imagePath) throws Exception {
// create pdf
final Document doc = new Document();
final PdfWriter pdfWriter = PdfWriter.getInstance(doc, toWrite);
pdfWriter.setEncryption(null, null, PdfWriter.ALLOW_DEGRADED_PRINTING | PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);
_imagePath = imagePath;
doc.open();
PdfContentByte cb = pdfWriter.getDirectContent();
PdfHelper.createHeaderBlock(cb,1,1);
PdfHelper.createCircleAndText(cb, "Gutschein", 298f, 705f, 75, textFontForCircle, 0x7F, 0xAD, 0x09);
createBlueBlock(cb, treeCount);
createGreyBlock(cb, codeFragments);
pdfHelper.addLogo(cb, _imagePath, 262f, 35f);
doc.close();
}
示例2: 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;
}
}
示例3: print
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
public void print(String plot_pdf) {
try {
float width = jframe.getSize().width,
height = jframe.getSize().height;
Document document = new Document(new Rectangle(width, height));
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(plot_pdf));
document.open();
PdfContentByte canvas = writer.getDirectContent();
PdfTemplate template = canvas.createTemplate(width, height);
Graphics2D g2d = new PdfGraphics2D(template, width, height);
jframe.paint(g2d);
g2d.dispose();
canvas.addTemplate(template, 0, 0);
document.close();
} catch (FileNotFoundException | DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例4: writeChartToPDF
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
* Save the chart as pdf.
*
* @param chart
* chart that should be saved
* @param fileName
* file name under which chart should be saved
*/
public static void writeChartToPDF(final JFreeChart chart,
final String fileName) {
PdfWriter writer = null;
com.itextpdf.text.Document document = new com.itextpdf.text.Document(
PageSize.A4);
final int width = (int) PageSize.A4.getWidth();
final int height = (int) PageSize.A4.getHeight();
try {
writer = PdfWriter.getInstance(document, new FileOutputStream(
fileName + ".pdf"));
document.open();
PdfContentByte contentByte = writer.getDirectContent();
PdfTemplate template = contentByte.createTemplate(width, height);
Graphics2D graphics2d = template.createGraphics(width, height,
new DefaultFontMapper());
Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,
height);
chart.draw(graphics2d, rectangle2d);
graphics2d.dispose();
contentByte.addTemplate(template, 0, 0);
} catch (Exception e) {
e.printStackTrace();
}
document.close();
}
示例5: testShowTextAlignedVsSimpleColumnTopAlignment
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/32162759/columntext-showtextaligned-vs-columntext-setsimplecolumn-top-alignment">
* ColumnText.ShowTextAligned vs ColumnText.SetSimpleColumn Top Alignment
* </a>
* <p>
* Indeed, the coordinates do not line up. The y coordinate of
* {@link ColumnText#showTextAligned(PdfContentByte, int, Phrase, float, float, float)}
* denotes the baseline while {@link ColumnText#setSimpleColumn(Rectangle)} surrounds
* the text to come.
* </p>
*/
@Test
public void testShowTextAlignedVsSimpleColumnTopAlignment() throws DocumentException, IOException
{
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "ColumnTextTopAligned.pdf")));
document.open();
Font fontQouteItems = new Font(BaseFont.createFont(), 12);
PdfContentByte canvas = writer.getDirectContent();
// Item Number
ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("36222-0", fontQouteItems), 60, 450, 0);
// Estimated Qty
ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("47", fontQouteItems), 143, 450, 0);
// Item Description
ColumnText ct = new ColumnText(canvas); // Uses a simple column box to provide proper text wrapping
ct.setSimpleColumn(new Rectangle(193, 070, 390, 450));
ct.setText(new Phrase("In-Situ : Poly Cable - 100'\nPoly vented rugged black gable 100ft\nThis is an additional description. It can wrap an extra line if it needs to so this text is long.", fontQouteItems));
ct.go();
document.close();
}
示例6: createLawTable
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
private PdfPTable createLawTable(PdfContentByte cb) throws DocumentException {
PdfPTable table = new PdfPTable(1);
float[] rows = { 445f };
table.setTotalWidth(rows);
table.getDefaultCell()
.setBorder(Rectangle.NO_BORDER);
table.getDefaultCell()
.setLeading(8f, 0);
table.addCell(new Phrase(new Chunk("Es handelt sich nicht um den Verzicht auf Erstattung von Aufwendungen.", textFontLawText)));
table.addCell(new Phrase(new Chunk("Die Gesellschaft ist wegen Förderung (begünstigter Zweck: Umweltschutz (§52 (2) S. 1 Nr.(n) 8 AO)) durch", textFontLawText)));
table.addCell(new Phrase(new Chunk("Bescheinigung des Finanzamt Halle (Saale)-Nord, StNr. 110/108/91169, vom 19.11.2008 ab 01.01.2009", textFontLawText)));
table.addCell(new Phrase(new Chunk("als gemeinnützig anerkannt. Letzter Freistellungsbescheid datiert auf den 20.06.2013.", textFontLawText)));
table.addCell(new Phrase(new Chunk("Es wird bestätigt, dass die Zuwendung nur zur Förderung des Umweltschutzes verwendet wird.", textFontLawText)));
PdfPCell emptyCell = new PdfPCell();
emptyCell.setBorder(Rectangle.BOTTOM);
emptyCell.setFixedHeight(15f);
table.addCell(emptyCell);
return table;
}
示例7: generate128
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
private static Image generate128(PdfContentByte cb, String sku){
Barcode128 code128 = new Barcode128();
code128.setCodeType(Barcode128.CODE_A);
code128.setGuardBars(true);
code128.setCode(sku);
code128.setSize(7);
code128.setBaseline(6f);
code128.setBarHeight(27f);
code128.setX(.70f);
return code128.createImageWithBarcode(cb, null, null);
}
示例8: 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();
}
示例9: getImageByFile
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
public ImageInstance getImageByFile( PdfContentByte cb , File file ) throws IOException, BadElementException{
Image image = null;
ImageInstance instance = null;
if( file.getName().toLowerCase().endsWith( ".pdf")){
PdfReader reader = new PdfReader( file.getAbsolutePath() );
PdfImportedPage p = cb.getPdfWriter().getImportedPage(reader, 1);
image = Image.getInstance(p);
instance = new ImageInstance(image, reader);
}else{
image = Image.getInstance( file.getAbsolutePath() );
instance = new ImageInstance(image, null);
}
instances.add(instance);
return instance;
}
示例10: createRoundRectangle
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
public void createRoundRectangle(PdfContentByte cb, Block block ){
PdfDocument request = getPdfDocument(block);
float[] positions = getBoundsInPs(block);
float[] mmPositions = getBoundsInMMIncludeCutmark(block);
PdfTemplate tp = cb.createTemplate(positions[2],positions[3]);
tp.roundRectangle(
0,
0,
positions[2],
positions[3],
SizeFactory.millimetersToPostscriptPoints( block.getRadius() )
);
// because pdf i calculated from bottom up
cb.addTemplate(
tp,
positions[0],
SizeFactory.millimetersToPostscriptPoints( request.getSize()[1] - ( mmPositions[1] + mmPositions[3]))
);
}
示例11: onRender
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
@Override
public void onRender(PdfContentByte cb) throws PdfRenderException {
Integer[] pageSizes = getPage().getPdfDocument().getSize();
float[] pos = getPosition();
float[] moveTo = getMoveTo();
cb.setLineWidth( getThickness() );
cb.setColorStroke( getBaseColor() );
float y1 = pageSizes[1] + SizeFactory.CUT_MARK - pos[1]; // seams strange but pdf starts bottom and up.
float y2 = pageSizes[1] + SizeFactory.CUT_MARK - moveTo[1];
// x , y. y is backward in pdf so start pos is the entire page height
cb.moveTo( SizeFactory.millimetersToPostscriptPoints( pos[0] + SizeFactory.CUT_MARK ) , SizeFactory.millimetersToPostscriptPoints( y1 ) );
cb.lineTo( SizeFactory.millimetersToPostscriptPoints( moveTo[0] + SizeFactory.CUT_MARK ) , SizeFactory.millimetersToPostscriptPoints( y2 ) );
cb.stroke();
}
示例12: closePassedStream
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
/**
* The <code>closePassedStream</code> method closes the stream passed.
*
* @param reader {@link PdfReader}
* @param document {@link Document}
* @param contentByte {@link PdfContentByte}
* @param writer {@link PdfWriter}
* @param fileInputStream {@link FileInputStream}
* @param fileOutputStream {@link FileOutputStream}
* @throws IOException {@link} if unable to close input or output stream
*/
private static void closePassedStream(final PdfReader reader, final Document document,
final PdfContentByte contentByte, final PdfWriter writer,
final FileInputStream fileInputStream, final FileOutputStream fileOutputStream) throws IOException {
if (null != reader) {
reader.close();
}
if (null != document) {
document.close();
}
if (null != contentByte) {
contentByte.closePath();
}
if (null != writer) {
writer.close();
}
if (null != fileInputStream) {
fileInputStream.close();
}
if (null != fileOutputStream) {
fileOutputStream.flush();
fileOutputStream.close();
}
}
示例13: split
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
void split(PdfReader reader, int page) throws IOException
{
PdfImportedPage importedPage = writer.getImportedPage(reader, page);
Rectangle pageSizeToImport = reader.getPageSize(page);
Iterable<Rectangle> rectangles = determineSplitRectangles(reader, page);
for (Rectangle rectangle : rectangles) {
newPage(rectangle);
PdfContentByte directContent = writer.getDirectContent();
directContent.saveState();
directContent.rectangle(rectangle.getLeft(), rectangle.getBottom(), rectangle.getWidth(), rectangle.getHeight());
directContent.clip();
directContent.newPath();
writer.getDirectContent().addTemplate(importedPage, -pageSizeToImport.getLeft(), -pageSizeToImport.getBottom());
directContent.restoreState();
}
}
示例14: cellLayout
import com.itextpdf.text.pdf.PdfContentByte; //导入依赖的package包/类
@Override
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
PdfContentByte canvas = canvases[PdfPTable.BACKGROUNDCANVAS];
float xTransition = position.getLeft() + (position.getRight() - position.getLeft()) * (percent/100.0f);
float yTransition = (position.getTop() + position.getBottom()) / 2f;
float radius = (position.getRight() - position.getLeft()) * 0.025f;
PdfShading axial = PdfShading.simpleAxial(canvas.getPdfWriter(),
xTransition - radius, yTransition, xTransition + radius, yTransition, leftColor, rightColor);
PdfShadingPattern shading = new PdfShadingPattern(axial);
canvas.saveState();
canvas.setShadingFill(shading);
canvas.rectangle(position.getLeft(), position.getBottom(), position.getWidth(), position.getHeight());
// canvas.clip();
canvas.fill();
canvas.restoreState();
}
示例15: 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();
}