Tag: pdf

用于PDF渲染的Java库

有没有人知道Java的PDF渲染的好库? 理想情况下,它不仅应支持显示图像,还应支持从中检索文本,查找哪个文本位于某个位置等。

使用PDFBox将unicode字符串写入PDF

我想使用Apache PDFBox 1.8.8创建一个包含unicode字符的PDF,但我对支持的内容和不支持的内容感到困惑。 这里发布的答案表明这是一个已修复在主干上的错误。 这里发布的另一个答案表明我必须自己做翻译。 此处发布的另一个(较旧的)答案涉及嵌入字体。 请有人澄清一下。 此外,如果它是一个现在修复的错误,有人可以告诉我PDFBox的下一个版本可能是什么时候。 谢谢。

我可以使用iText在我的Swing应用程序中呈现PDF吗?

iText可以在Swing应用程序中呈现PDF文档吗? 或者我是否必须使用另一个库/框架?

用Java实现RTF到PDF

我们正在构建一个与其他系统部分交互的应用程序。 我们从其他系统中提取一些数据,这些数据作为RTF文档返回。 但我们必须阻止用户编辑此文件,因此我们考虑将其与iText一起转换为PDF。 代码段: // moving the rtf data into input stream to be used in RTF parser ByteArrayInputStream rtfInputStream = new ByteArrayInputStream(rtfStream.toByteArray()); // set headers resp.setHeader(“Cache-Control”, “no-store”); resp.addHeader(“Content-Type”, “application/pdf”); resp.addHeader(“Content-Disposition”, “inline; filename=Karta.pdf”); resp.setStatus(HttpServletResponse.SC_OK); // pdf output stream ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); Document pdfDoc = new Document(); PdfWriter pdfWriter = PdfWriter.getInstance(pdfDoc, pdfStream); pdfDoc.open(); RtfParser […]

PDFBox 1.8.10:填写并签署PDF会生成无效签名

我在PDF文档中填写(以编程方式)表单(AcroPdf),然后在文档中签名。 我从doc.pdf开始,使用PDFBox的setFields.java示例创建doc_filled.pdf。 然后我签署doc_filled.pdf,使用一些代码创建doc?filled_signed.pdf,基于签名示例并在Acrobat Reader中打开pdf。 输入的Field数据可见,签名面板告诉我 “此签名中包含的格式或信息存在错误(签名字节数组无效)” 到目前为止,我知道: 单独应用的签名代码(即直接创建一些doc_signed.pdf)会创建一个有效的签名 “隐形签名”,可见签名和可见签名存在的问题被添加到现有签名字段中。 问题甚至发生,如果我没有填写表格,但只打开并保存,即: PDDocument doc = PDDocument.load(new File(“doc.pdf”)); doc.save(new File(“doc_filled.pdf”)); doc.close(); 足以打破后来应用的签名代码。 另一方面,如果我使用相同的doc.pdf,在Adobe中手动输入字段的值,则签名代码会生成有效的签名。 我究竟做错了什么? 更新: @mkl要求我提供文件,我正在谈论(我目前没有足够的声誉,将所有文件发布为链接,抱歉给您带来不便): odc.pdf: https ://www.dropbox.com/s/ev8x9q48w5l0hof/doc.pdf ? dl = 0 doc_filled.pdf: https ://www.dropbox.com/s/fxn4gyneizs1zzb/doc_filled.pdf ? dl = 0 doc_filled_signed.pdf: https ://www.dropbox.com/s/xm846sj8f9kiga9/doc_filled_signed.pdf ? dl = 0 doc_filled_and_signed.pdf: https ://www.dropbox.com/s/5jftje6ke87jedr/doc_filled_and_signed.pdf ? dl = 0 最后一个是通过使用一次签署和填写文档来创建的 doc.saveIncremental(); 正如我已经在评论中写的那样 setNeedToBeUpdate(true); […]

iText PDFDocument页面大小不准确

我正在尝试使用iText为Java中的现有pdf文档添加标题。 我可以在文档的固定位置添加标题,但所有文档都是不同的页面大小,因此它并不总是位于页面的顶部。 我已经尝试获取页面大小,以便我可以计算标题的位置,但似乎页面大小实际上不是我想要的。 在某些文档中,调用reader.getPageSize(i).getTop(20)会将文本放在页面顶部的正确位置,但是,在某些不同的文档中,它会将其放在页面的一半。 大多数页面都被扫描为Xerox复印机,如果这有所不同的话。 这是我正在使用的代码: PdfReader reader = new PdfReader(readFilePath); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(writeFilePath)); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); for (int i = 1; i <= reader.getNumberOfPages(); i++) { PdfContentByte cb = stamper.getOverContent(i); cb.beginText(); cb.setFontAndSize(bf, 14); float x = reader.getPageSize(i).getWidth() / 2; float y = reader.getPageSize(i).getTop(20); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "Copy", x, y, […]

用Java合并2个PDF

我有iText的问题,并将2PDF合并为1个PDF。 我想合并这些PDF: PDF1 – 一个站点: 这是PDF1。 PDF2 – 一个站点: 这是PDF2。 我需要的是: https : //dl.dropboxusercontent.com/u/4001370/whatIneed.pdf 代码1 – 两个站点: One Site One:这是PDF1。 一站点二:这是PDF2。 PDFMergerUtility ut = new PDFMergerUtility(); ut.addSource(“C:\\Temp\\PDF1.pdf”); ut.addSource(“C:\\Temp\\PDF2.pdf”); ut.setDestinationFileName(“C:\\Temp\\Code1.pdf”); ut.mergeDocuments(); 代码2 – 数字被覆盖: 这是PDF(1/2)。 public class main { public static void main(String[] args) throws IOException, DocumentException { PdfReader reader; PdfImportedPage page; LinkedList fileList = new […]

如何在map reduce程序中解析PDF文件?

我想在我的hadoop 2.2.0程序中解析PDF文件,我发现了这个 ,按照它的说法,直到现在,我有这三个类: PDFWordCount :包含map和reduce函数的主类。 (就像本机hadoop wordcount示例,但我使用的是PDFInputFormat类而不是TextInputFormat 。 PDFRecordReader extends RecordReader :这是主要的工作。 特别是我把initialize函数放在这里以获得更多插图。 public void initialize(InputSplit genericSplit, TaskAttemptContext context) throws IOException, InterruptedException { System.out.println(“initialize”); System.out.println(genericSplit.toString()); FileSplit split = (FileSplit) genericSplit; System.out.println(“filesplit convertion has been done”); final Path file = split.getPath(); Configuration conf = context.getConfiguration(); conf.getInt(“mapred.linerecordreader.maxlength”, Integer.MAX_VALUE); FileSystem fs = file.getFileSystem(conf); System.out.println(“fs has been opened”); start […]

使用java密码保护pdf

我想将现有的PDF作为密码保护,我正在使用我正在遵循此URL的itext http://howtodoinjava.com/2014/07/29/create-pdf-files-in-java-itext-tutorial/ 我开发了一个程序,它将以PDF作为附件发送邮件。 下面是我将PDF文件设为密码保护的代码。 现在PDF文件附在邮件中,但是当我试图打开它时,我收到一个错误,它已被损坏。 我在下面的代码中做错了什么? // attachment part MimeBodyPart attachPart = new MimeBodyPart(); String filename = “c:\\SettingupRulesin outlook2003.pdf”; //OutputStream file = new FileOutputStream(new File(“PasswordProtected.pdf”)); final OutputStream os = new FileOutputStream(filename); com.itextpdf.text.Document doc = new com.itextpdf.text.Document(); PdfWriter writer = PdfWriter.getInstance(doc, os); writer.setEncryption(USER_PASSWORD.getBytes(), OWNER_PASSWORD.getBytes(), PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128); os.close(); DataSource source = new FileDataSource(filename); attachPart.setDataHandler(new DataHandler(source)); attachPart.setFileName(filename);

java中的Docx到Pdf转换器

以下代码不适用于Apache poi 3.16。 有人可以提供正确的解决方案,在我的项目中只有一些依赖使用 public void ConvertToPDF(String docPath, String pdfPath) { try { InputStream doc = new FileInputStream(new File(docPath)); XWPFDocument document = new XWPFDocument(doc); PdfOptions options = PdfOptions.create(); OutputStream out = new FileOutputStream(new File(pdfPath)); PdfConverter.getInstance().convert(document, out, options); System.out.println(“Done”); } catch (FileNotFoundException ex) { System.out.println(ex.getMessage()); } catch (IOException ex) { System.out.println(ex.getMessage()); } } 例外: Exception in […]