Tag: itext

在java中将图像写入pdf文件

我正在编写一个代码,将Microsoft power-point(ppt)幻灯片转换为图像,并将生成的图像写入pdf文件。 以下代码生成并将图像写入pdf文件,但我面临的问题是,当我将图像写入pdf文件时,它的大小超过了pdf页面大小,我只能查看75%的图像rest是不可见的。 这里需要注意的另一件事是,pdf文件中的书写图像看起来像缩放或扩展。 看一下下面的代码片段: for (int i = 0; i < slide.length; i++) { BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); graphics.setPaint(Color.white); graphics.fill(new Rectangle(0, 0, pgsize.width, pgsize.height)); slide[i].draw(graphics); fileName="C:/DATASTORE/slide-"+(i+1)+".png"; FileOutputStream out = new FileOutputStream(fileName); javax.imageio.ImageIO.write(img, "png", out); out.flush(); out.close(); com.lowagie.text.Image image =com.lowagie.text.Image.getInstance(fileName); image.setWidthPercentage(40.0f); doc.add((image)); } doc.close(); } catch(DocumentException de) { […]

iText:将PDF分成几个PDF(每页1个)

我想要的是:给定一个10页的pdf文件,我想在网络上的表格中显示该pdf的每一页。 实现这一目标的最佳方法是什么? 我想一种方法是将这个10页-pdf文件分成10页1页pdf,并以编程方式将每个pdf显示在一行表格上。 我可以用iText做到这一点吗? 有没有更好的方法来实现这一目标?

iText直接打印

我正在使用iText生成pdf并将其写入文件系统,如下所示: private void createPDF() throws Exception{ com.itextpdf.text.Document doc = new com.itextpdf.text.Document(); PdfWriter docWriter = null; path = “C:\\PATH\\TO\\Desktop\\EXAMPLE_FOLDER\\” + pdfFilename; docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path)); doc.addTitle(“Invoice”); doc.setPageSize(PageSize.A4); doc.open(); PdfContentByte cb = docWriter.getDirectContent(); fillPDFDetails(cb); if (doc != null) { doc.close(); } if (docWriter != null) { docWriter.close(); } } 但是,我想将pdf发送到打印机并打印pdf文件,而不是将其写入文件系统。 我怎样才能做到这一点?

使用iText,在内存上生成一个在磁盘上生成的PDF

我正在从Java应用程序生成PDF。 (效果很好)问题是PDF在磁盘上生成为: Document documento = new Document(PageSize.A4, 25, 25, 25, 25); PdfWriter writer = PdfWriter.getInstance(documento, new FileOutputStream(“/Users/sheldon/Desktop/Registry.pdf”)); documento.open(); // Put some images on the PDF for( byte[] imagen : imagenes ) { Image hoja = Image.getInstance(imagen); hoja.scaleToFit(documento.getPageSize().getHeight(), documento.getPageSize().getWidth()); documento.add(hoja); } documento.addTitle(“Generated Registry!”); documento.close(); 现在,当用户搜索PDF并打印它们时,我不需要将它们存储在磁盘上。 我需要(如果可能的话)在内存中生成它们并使用命令打开(使用acrobat reader)该文档。 那可能吗? 任何的想法。 如果没有,有什么建议(根据您的经验)。 提前谢谢你。 编辑: 适用于标准Java桌面应用程序。

如何将HTML内容转换为PDF而不会丢失使用Java的格式?

我有一些HTML内容(包括格式标签,如strong ,图像等)。在我的Java代码中,我想将此HTML内容转换为PDF文档,而不会丢失HTML格式。 无论如何在Java中使用它(使用iText或任何其他库)?

边界框中的itext多行文本

有没有人知道,如何在iText中在边界框中添加多行文字(指定坐标)。 我试过了 cb.showTextAligned( PdfContentByte.ALIGN_LEFT, text, bounds.getLeft(), TOTAL_HEIGHT-bounds.getTop(), 0 ); 但它不支持换行。 我也试过了 PdfContentByte cb = writer.getDirectContent(); cb.moveText(300,400); document.add(new Paragraph(“TEST paragraph\nNewline”)); 这支持换行但不对moveText作出反应,因此我不知道如何将它放在给定位置或更好:边界框。 我怀疑块或PdfTemplate或者表可能有帮助,但我(还)不知道如何把它放在一起。 TIA寻求帮助。

pdfptable的无形边框

我正在使用iText库在Java中生成pdf文件。 我在pdfptable中编写数据,如何使表格的边框不可见?

iText:PdfTable单元垂直对齐

我正在尝试垂直对齐我的headet单元格文本在单元格高度的中间。 这是我的代码: PdfPCell c1 = new PdfPCell(cerate_phrase(“” ,regular_bold )); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setVerticalAlignment(Element.ALIGN_MIDDLE); c1.setBackgroundColor(BaseColor.LIGHT_GRAY); table_.addCell(c1); 但这不起作用..setHorizo​​ntalAlignment居中但不是setVerticalAlignment。 我做错了吗? 我怎么能在中间做到? 任何帮助都将被批准。

如何使用iText对pdf进行数字签名?

如何使用iText签署pdf? 我正在浏览这个LINK但却不了解my_private_key.pfx。 我真的需要数字签名证书吗? 请澄清我。 提前致谢。

为什么不在java servlet中创建pdf文档?

我使用iText / Pdfbox创建PDF文档。 当我使用像这样的独立Java类创建PDF时,一切正常: public static void main(String[] args){ … … … } 文档已正确创建。 但我需要从Servlet创建一个PDF文档。 我将代码粘贴到get或post方法中,在服务器上运行该servlet,但不创建PDF文档! 此代码作为独立应用程序运行: 此代码不起作用: