我正在测试iText以生成由平铺格式的8个图像组成的PDF。我使用JFreeChart创建一个图形,然后由iText将其转换为图像。 PDF生成的很好,但是当我打开输出文件时,左侧,右侧和底部仍有大约一英寸的空白。我想打印时利用合法大小页面上的所有空间。使用iText消除PDF中的所有空白空间
我知道在PDF中没有“边距”的概念,它不是可编辑的格式。图像必须在没有空白的情况下创建。文档构造函数中的额外参数实际上做了什么?
我认为通过向Document对象(LEGAL和1f params)提供必要的参数可以消除空白,并且我的表将占用打印页面上的所有8.5x14,但没有运气。
有什么建议吗?在此先感谢
原始代码:
// Setup document
Document doc = new Document(PageSize.LEGAL, 1f, 1f, 1f, 1f);
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("c:\\temp\\image_in_chunk.pdf"));
doc.open();
//create the chart, save to file system, and create an iText Image object
ChartUtilities.saveChartAsPNG(new File("C:\\temp\\img.png"), createChart(createDataset()), 240, 240);
Image img1 = Image.getInstance("C:\\temp\\img.png");
PdfPCell cell1 = null;
Paragraph paragraph = new Paragraph();
paragraph.add(new Chunk(img1, 0, 0, true));
PdfPTable table = new PdfPTable(2);
for (int i = 0; i < 8; i++)
{
cell1 = new PdfPCell(paragraph);
table.addCell(cell1);
}
doc.add(table);
doc.close();
更正和工作守则(当然,创建自己的JFreeChart作为IMG1我不能发布不是成员的样本图像输出。):
// Setup document
Document doc = new Document(PageSize.LEGAL, 0f, 0f, 0f, 0f);
PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("c:\\temp\\image_in_chunk.pdf"));
doc.open();
//create the chart, save to file system, and create an iText Image object
ChartUtilities.saveChartAsPNG(new File("C:\\temp\\img.png"), createChart(createDataset()), 305, 250);
Image img1 = Image.getInstance("C:\\temp\\img.png");
// Create pdf document
for (int i = 0; i < 8; i++)
{
doc.add(new Chunk(img1, 0, 0, true));
}
doc.close();
你能告诉我怎样才能去除顶部空白当我在grails中使用jFreeChart生成条形图? – VVB 2015-02-24 07:10:22