本文整理匯總了Java中com.itextpdf.text.pdf.PdfContentByte.addTemplate方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfContentByte.addTemplate方法的具體用法?Java PdfContentByte.addTemplate怎麽用?Java PdfContentByte.addTemplate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfContentByte
的用法示例。
在下文中一共展示了PdfContentByte.addTemplate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: 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();
}
示例3: 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();
}
示例4: 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]))
);
}
示例5: createMultipagePDF
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* Create the multipage PDF report from the internal list of JPanels.
* @throws DocumentException
*/
public void createMultipagePDF() throws DocumentException {
// Document defaults to A4, so specify the current dimensions
Document doc= new Document(new Rectangle(pageWidth, pageHeight));
PdfWriter writer= PdfWriter.getInstance(doc, os);
doc.open();
PdfContentByte cb= writer.getDirectContent();
// Iterate over tabs
for (int i= 0; i != tabs.getTabCount(); ++i) {
JPanel jp= (JPanel) tabs.getComponent(i);
// Iterate over pages
for (int currentPage= 0; currentPage < getNumPages(jp); ++currentPage) {
doc.newPage(); // not needed for page 1, needed for >1
PdfTemplate template= cb.createTemplate(pageWidth, pageHeight);
Graphics2D g2d= new PdfGraphics2D(template, pageWidth, pageHeight * (currentPage + 1));
jp.printAll(g2d);
g2d.dispose();
cb.addTemplate(template, 0, 0);
}
}
doc.close();
}
示例6: writeToFile
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
public static void writeToFile(File f, Component m) throws Exception {
Graphics2D g2;
Document document = new Document(new Rectangle(
m.getBounds().x,
m.getBounds().y,
m.getBounds().width,
m.getBounds().height
));
PdfWriter writer;
writer = PdfWriter.getInstance(document, new FileOutputStream(f));
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(m.getSize().width, m.getSize().height);
g2 = tp.createGraphicsShapes(m.getSize().width, m.getSize().height);
m.paint(g2);
g2.dispose();
cb.addTemplate(tp, 0, 0);
document.close();
}
示例7: exportChartAsPDF
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* Exports the specified JFreeChart to a PDF file using
* <a href="http://itextpdf.com" target="_blank">iText</a>, bundled with
* Fiji. The destination file is specified by the user in a save dialog
* prompt. An error message is displayed if the file could not be saved.
* Does nothing if {@code chart} is {@code null}.
*
* @param chart
* the <a href="http://javadoc.imagej.net/JFreeChart/" target=
* "_blank">JFreeChart </a> to export.
* @param bounds
* the Rectangle delimiting the boundaries within which the chart
* should be drawn.
* @see #exportChartAsPDF(JFreeChart, Rectangle)
* @see #exportChartAsSVG(JFreeChart, Rectangle)
* @see #exportChartAsSVG(JFreeChart, Rectangle, File)
*/
public static void exportChartAsPDF(final JFreeChart chart, final Rectangle bounds, final File f)
throws FileNotFoundException, DocumentException {
final int margin = 0; // page margins
// Initialize writer
final Document document = new Document(new com.itextpdf.text.Rectangle(bounds.width, bounds.height), margin,
margin, margin, margin);
final PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(f));
document.open();
final PdfContentByte cb = writer.getDirectContent();
final PdfTemplate tp = cb.createTemplate(bounds.width, bounds.height);
// Draw the chart. Release resources upon completion
final Graphics2D g2 = tp.createGraphics(bounds.width, bounds.height, new DefaultFontMapper());
chart.draw(g2, bounds);
g2.dispose();
// Write to file
cb.addTemplate(tp, 0, 0);
document.close();
}
示例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 float textSize = _headerFooterFont.getWidthPoint(_legendText, 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(_legendText);
cb.endText();
cb.addTemplate(_tpl, document.right()
- adjust, textBase);
cb.restoreState();
}
示例9: exportChartAsPDF
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
public static void exportChartAsPDF(
JFreeChart chart,
Rectangle bounds,
File file) throws IOException, DocumentException {
System.out.println(file.getPath());
PdfWriter writer = null;
com.itextpdf.text.Document document = new com.itextpdf.text.Document();
document.addCreator("CanReg5");
document.addCreationDate();
writer = PdfWriter.getInstance(document, new FileOutputStream(
file));
document.open();
PdfContentByte contentByte = writer.getDirectContent();
PdfTemplate template = contentByte.createTemplate(bounds.width, bounds.height);
Graphics2D graphics2d = template.createGraphics(bounds.width, bounds.height,
new DefaultFontMapper());
Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, bounds.width,
bounds.height);
chart.draw(graphics2d, rectangle2d);
graphics2d.dispose();
contentByte.addTemplate(template, 0, 0);
document.close();
}
示例10: createEvent
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
public PdfPCellEvent createEvent(final Block block ){
return new PdfPCellEvent(){
public void cellLayout(PdfPCell cell, Rectangle rect,PdfContentByte[] canvas) {
float radiusInPs = SizeFactory.millimetersToPostscriptPoints( block.getRadius() );
PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
PdfTemplate template = cb.createTemplate( rect.getWidth() , rect.getHeight());
template.roundRectangle(0, 0, rect.getWidth() ,rect.getHeight() , radiusInPs);
template.clip();
template.newPath();
if( block.getBaseColor() != null ){
template.setColorFill(block.getBaseColor());
}
Border border = block.getBorder();
if( border != null ){
template.setLineWidth( SizeFactory.millimetersToPostscriptPoints( border.getThickness()) );
template.setColorStroke( border.getBaseColor());
}
template.roundRectangle(0, 0, rect.getWidth() ,rect.getHeight() ,radiusInPs);
if( block.getBaseColor() != null || border != null ){
if( block.getBaseColor() != null && border != null ){
template.fillStroke();
}else if( block.getBaseColor() != null ){
template.fill();
}else{
template.stroke();
}
}
cb.addTemplate( template, rect.getLeft(), rect.getBottom());
}
};
}
示例11: exportToPDF
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* Exports the 3d graph as a pdf
*
* @param file The pdf file to which the data should be written
* @param panel The chart panel that has to be exported
*/
public static void exportToPDF(File file, Chart3DPanel panel){
PdfWriter out = null;
Document document = new com.itextpdf.text.Document(PageSize.A4.rotate());
int width = 800, height = 500;
try{
out = PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
PdfContentByte contentByte = out.getDirectContent();
PdfTemplate template = contentByte.createTemplate(width, height);
@SuppressWarnings("deprecation")
Graphics2D graphics2d = template.createGraphics(width, height,new DefaultFontMapper());
Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,height);
panel.getChart().draw(graphics2d, rectangle2d);
graphics2d.dispose();
contentByte.addTemplate(template, 0, 0);
} catch(Exception e){
// in case any error occurs tell the user what the error is (sometimes useful if there is a problem of writing rights)
JOptionPane.showMessageDialog(GUIPrism.getGUI(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
return;
}
document.close();
}
示例12: saveAsPDF
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* Stores the logo in PDF format
* @param width
* @param height
* @param fileName
*/
public void saveAsPDF(int width, int height, String fileName)
{
if (chart == null)
{
makeSequenceLogo();
}
PdfWriter writer = null;
Rectangle pagesize = new Rectangle(width, height);
Document document = new Document(pagesize);
try
{
writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
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();
}
示例13: saveRAWAsPDF
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* Stores the logo in PDF format
* @param width
* @param height
* @param fileName
*/
public void saveRAWAsPDF(int width, int height, String fileName)
{
ChartPanel logo = getRawLogoPanel();
PdfWriter writer = null;
Rectangle pagesize = new Rectangle(width, height);
Document document = new Document(pagesize);
try
{
writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
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);
logo.getChart().draw(graphics2d, rectangle2d);
graphics2d.dispose();
contentByte.addTemplate(template, 0, 0);
}
catch (Exception e)
{
e.printStackTrace();
}
document.close();
}
示例14: writeChartToPDF
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* Save chart as a pdf file.
*
* @param chart
* chart that should be saved
* @param fileName
* file name under which the file 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();
}
示例15: save
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
public static final void save(File file, Component c, int width, int height) {
if (file == null) {
logger.log(Level.WARNING, "no file selected");
return;
}
if (c == null) {
logger.log(Level.WARNING, "no component provided");
return;
}
try {
Document document = new Document(new Rectangle(width, height));
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file.getAbsolutePath()));
document.addAuthor("UJMP v" + UJMP.UJMPVERSION);
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(width, height);
Graphics2D g2 = new PdfGraphics2D(cb, width, height, new DefaultFontMapper());
if (c instanceof CanRenderGraph) {
((CanRenderGraph) c).renderGraph(g2);
} else {
c.paint(g2);
}
g2.dispose();
cb.addTemplate(tp, 0, 0);
document.close();
writer.close();
} catch (Exception e) {
logger.log(Level.WARNING, "could not save PDF file", e);
}
}