本文整理匯總了Java中com.itextpdf.text.pdf.PdfWriter.getVerticalPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfWriter.getVerticalPosition方法的具體用法?Java PdfWriter.getVerticalPosition怎麽用?Java PdfWriter.getVerticalPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfWriter
的用法示例。
在下文中一共展示了PdfWriter.getVerticalPosition方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeChartsToPDF
import com.itextpdf.text.pdf.PdfWriter; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public static void writeChartsToPDF(List<JFreeChart> charts, int width, int height, OutputStream outputStream, String hostname, Date date) {
PdfWriter writer = null;
Document document = new Document();
try {
writer = PdfWriter.getInstance(document, outputStream);
writer.setPageEmpty(false);
document.open();
document.setPageSize(PageSize.A4);
document.add(new Paragraph("Aggregates Report generated by " + hostname + " on " + date.toString()));
document.newPage();
writer.newPage();
PdfContentByte contentByte = writer.getDirectContent();
PdfTemplate template;
Graphics2D graphics2d;
int position = 0;
Rectangle2D rectangle2d;
for (JFreeChart chart : charts){
LOG.debug("Writing chart to PDF");
if (writer.getVerticalPosition(true)-height+(height*position) < 0){
position = 0;
document.newPage();
writer.newPage();
}
template = contentByte.createTemplate(width, height);
graphics2d = template.createGraphics(width, height, new DefaultFontMapper());
rectangle2d = new Rectangle2D.Double(0, 0, width, height);
chart.draw(graphics2d, rectangle2d);
graphics2d.dispose();
contentByte.addTemplate(template, 38, writer.getVerticalPosition(true)-height+(height*position));
position--;
}
} catch (Exception e) {
e.printStackTrace();
}
document.close();
}