itext

利用IText导出Word

 ̄綄美尐妖づ 提交于 2020-03-02 06:49:46
生成Word文档的类库有很多,常用的有jacob,poi,itext等等,jacob操作office的能力是不错的,但是对于我个人来说,我不喜欢它的两方面:一、jacob只能应用于windows平台。二、除了要把相应的ar包加载到类路径下,还需要把jacob.dll复制到windows/system32目录中。poi操作excel方面的能力非常强大,对于word方面的操作能力还是不够的。 现在来说说IText吧。IText是用于生成PDF文档的一个java类库。通过iText不仅可以生成PDF或rtf的文档,而且可以将XML、Html文件转化为PDF文件。当然也可以生成word文档。而且操作方法简单。使用IText需要3个jar包:iText-2.1.7.jar(核心包),iTextAsian.jar(解决中文输出问题),itext-rtf-2.1.7.jar(操作rtf格式)。(最后会提供jar包与实例下载)。 用iText生成Word文档需要5个步骤:   ①建立com.lowagie.text.Document对象的实例。 Document document = new Document(); ②建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。 RtfWriter2.getInstance(this.document

Verify digital signature using certificate chain in java

倖福魔咒の 提交于 2020-02-29 07:00:45
问题 i try to sign pdf using digital signature, i send hash value of pdf to REST API it does sign pdf using user's private key and returns CMS formatted data. I got certificate chain from CMS. Now i need to verify original pdf using the certificate chain and add signature to pdf. I use BC and Itextpdf public static String verifyPdf(byte[] toVerify, byte[] signedByte, String origFile, String signedFile) throws Exception { // CMSSignedData cms = new CMSSignedData(signedByte); // Store store = cms

文件系统(01):基于SpringBoot框架,管理Excel和PDF文件类型

☆樱花仙子☆ 提交于 2020-02-25 23:04:45
本文源码: GitHub·点这里 || GitEE·点这里 一、文档类型简介 1、Excel文档 Excel一款电子表格软件。直观的界面、出色的计算功能和图表工具,在系统开发中,经常用来把数据转存到Excel文件,或者Excel数据导入系统中,这就涉及数据转换问题。 2、PDF文档 PDF是可移植文档格式,是一种电子文件格式,具有许多其他电子文档格式无法相比的优点。PDF文件格式可以将文字、字型、格式、颜色及独立于设备和分辨率的图形图像等封装在一个文件中。该格式文件还可以包含超文本链接、声音和动态影像等电子信息,支持特长文件,集成度和安全可靠性都较高。 二、Excel文件管理 1、POI依赖 Apache POI是Apache软件基金会的开源类库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能。 <!-- Excel 依赖 --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.9</version> </dependency> <!-- 2007及更高版本 --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml<

Reading and writing the TOC for a PDF

元气小坏坏 提交于 2020-02-05 08:54:12
问题 My requirement is to prefix a PDF generated by some other process with a single 'cover page'. I've written a relatively simple Ant task to concatenate a list of PDF documents, and this works well, but the TOC is not preserved in the process. By TOC I mean .. Ideally, both TOCs would be preserved, and adjusted for their new offsets, but I can see no means of reading or writing the TOC (the left hand one) in the iText API. Can anyone? M. 回答1: I'm the author of the book about iText and in the

How to print custom page size as portrait in itextsharp

点点圈 提交于 2020-02-05 03:53:49
问题 Below is my code to create custom page size in ItextSharp. Page is now printing in landscape mode. I want print in Portrait. document = new Document(new iTextSharp.text.Rectangle(410f, 288f)); 回答1: Replace: document = new Document(new iTextSharp.text.Rectangle(410f, 288f)); With: document = new Document(new iTextSharp.text.Rectangle(410f, 288f).Rotate()); And the custom page will be rotated by 90 degrees, if that's what you want. 回答2: Document document = new Document(default(iTextSharp.text

Showing image on a acro text field position

拥有回忆 提交于 2020-02-01 09:10:09
问题 I had a PDF document which has acro text fields which is already shared to the client. Now the client wants to insert signature image in one of the text fields. My manager asked me to try a way to do the same.My idea is to replace an image on top of the text field position and resize the text field as image size. For replacing acro text field of pdf into image, i am trying as below 1.Finding the text field by its field id String position = null; List<FieldPosition> fieldPositons = form

An invisible border of pdfptable

佐手、 提交于 2020-01-31 04:06:47
问题 I am using iText library for generating pdf files in Java. I am writing data in pdfptable , how can I make the borders of table invisible? 回答1: The Border Elements of the PdfPTable are defined by the PdfPCell which are added to the table. Each Cell will have its own style/formatting. Here is the API: http://api.itextpdf.com/ Example PdfPTable table = new PdfPTable(2); PdfPCell cellOne = new PdfPCell(new Phrase("Hello")); PdfPCell cellTwo = new PdfPCell(new Phrase("World")); cellOne.setBorder

Is there a way to draw a rectangle into a PdfPCell in iText (the Java version)?

亡梦爱人 提交于 2020-01-29 23:29:39
问题 I found some tutorials about how to draw forms in iText, but I need to insert it into a cell, and I don´t know how. Thank you for your consideration of this matter. 回答1: An iText Image extends Rectangle. You could make a new implementation of image. You can create an Image from a template, and you can create a template using a content byte. You could therefore create a template, draw a rectangle on it, create the image and then set the image on the desired cell. I have done something similar

merging pdf and preserve SetTagged

余生长醉 提交于 2020-01-25 23:04:13
问题 I'm using iTextSharp 5.x. I'm trying to merge two pdfs and preserve the isTagged flag. When I remove copy.SetTagged(); the result pdf contains both pdfs which is great. When adding the copy.SetTagged() is get an exception Exception -->System.ObjectDisposedException: Cannot access a closed file. at System.IO.__Error.FileNotOpen() at System.IO.FileStream.get_Position() Here is the code List<string> filesToMerge = new List<string> { "C:/dev/dcs/wp-cla-dcs/Hex/Docs/metadata/coverPage.pdf", "C:

Error while generating pdf from Html file in Java using iText [closed]

主宰稳场 提交于 2020-01-25 15:51:30
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . I am converting XML -> HTML -> pdf. The HTML -> pdf step is done with iText v5.5.3, but I get the following error: Exception in thread "main" java.lang.NoSuchMethodError: com.itextpdf.text.pdf.PdfPTable.addCell(Lcom/itextpdf/text/pdf/PdfPCell;)V at com.itextpdf.tool.xml.html.table.Table.end(Table