我正在使用Spring MVC。我必须编写一个服务,从请求主体获取input,将数据添加到pdf并将PDF文件返回给浏览器。 pdf文档是使用itextpdf生成的。 我怎样才能使用Spring MVC做到这一点。 我尝试过使用这个 @RequestMapping(value="/getpdf", method=RequestMethod.POST) public Document getPDF(HttpServletRequest request , HttpServletResponse response, @RequestBody String json) throws Exception { response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment:filename=report.pdf"); OutputStream out = response.getOutputStream(); Document doc = PdfUtil.showHelp(emp); return doc; } 生成pdf的showhelp函数。 我只是暂时把一些随机数据放在pdf中。 public static Document showHelp(Employee emp) throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("C:/tmp/report.pdf")); document.open(); document.add(new […]
我试图在PDF文档的每个页面上使用iTextSharp格式的Page#of#在iText页面和书上的教程之后创build一个页脚。 虽然我不断得到cb.SetFontAndSize(helv,12)的exception; – 对象引用未设置为对象。 任何人都可以看到问题? 代码如下。 谢谢,罗布 public class MyPdfPageEventHelpPageNo : iTextSharp.text.pdf.PdfPageEventHelper { protected PdfTemplate total; protected BaseFont helv; private bool settingFont = false; public override void OnOpenDocument(PdfWriter writer, Document document) { total = writer.DirectContent.CreateTemplate(100, 100); total.BoundingBox = new Rectangle(-20, -20, 100, 100); helv = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); } public override void OnEndPage(PdfWriter writer, Document […]
我目前有一个PdfReader和一个PdfStamper,我正在用acrofields填写。 我现在必须复制另一个pdf到我已经填写的表格的末尾,当我这样做的时候,我将复制的新表格丢失了。 这是代码。 public static void addSectionThirteenPdf(PdfStamper stamper, Rectangle pageSize, int pageIndex){ PdfReader reader = new PdfReader(FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/resources/documents/Section13.pdf")); AcroFields fields = reader.getAcroFields(); fields.renameField("SecurityGuidancePage3", "SecurityGuidancePage" + pageIndex); stamper.insertPage(pageIndex, pageSize); stamper.replacePage(reader, 1, pageIndex); } 我创build原始文档的方式就是这样。 OutputStream output = FacesContext.getCurrentInstance().getExternalContext().getResponseOutputStream(); PdfReader pdfTemplate = new PdfReader(FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/resources/documents/dd254.pdf")); PdfStamper stamper = new PdfStamper(pdfTemplate, output); stamper.setFormFlattening(true); AcroFields fields = stamper.getAcroFields(); 有没有办法使用第一段代码合并两个acrofields在一起?
我正在使用itextsharp dll将HTML转换为PDF。 HTML有一些Unicode字符,如α,β…当我尝试将HTML转换为PDF时,Unicode字符不显示在PDF中。 我的function: Document doc = new Document(PageSize.LETTER); using (FileStream fs = new FileStream(Path.Combine("Test.pdf"), FileMode.Create, FileAccess.Write, FileShare.Read)) { PdfWriter.GetInstance(doc, fs); doc.Open(); doc.NewPage(); string arialuniTff = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF"); BaseFont bf = BaseFont.CreateFont(arialuniTff, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font fontNormal = new Font(bf, 12, Font.NORMAL); List<IElement> list = HTMLWorker.ParseToList(new StringReader(stringBuilder.ToString()), new StyleSheet()); Paragraph p = new Paragraph {Font = […]
我想添加一些string,图像和表格到我的PDF文件(必须有几个页面),但是当我尝试使用ColumnText (我使用这个,因为我想把string放在绝对位置),我遇到一个问题。 当列高不足以添加string的内容时,内容不完整。 我怎样才能避免这些内容丢失? 这是相关的代码: try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("output.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); String imageUrl = "/Users/nofear/workspace/deneme23/pics/a4-ust.png"; String imageUrlAlt = "pics/a4-alt.png"; Image imageust = null; Image imageAlt = null; try { imageust = Image.getInstance(imageUrl); imageAlt = Image.getInstance(imageUrlAlt); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } […]
什么是最新版本的不是AGPL的itext? 我在哪里可以下载? 谁在维护它? 这很重要,程序员可以为他们的项目select正确的iText版本。 [编辑] 这个问题已经6年没有被标记为脱离主题。 我所问的问题中没有一个是观点问题。 我不是要求任何人提出build议。 这个问题对于开发人员来说很重要,可以通过投票人数来certificate,也有助于他们select他们想使用的iText库的版本。 请重新打开它。
iReport版本:3.7.1 我用两种方法来解决这个问题。 我的第一个方法 我正在iReport创build一个pdf页面,我有一个字段(从数据库)设置为字体古吉拉特语 – Salarl (印度的区域语言字体)。 该字体在iReport的字体列表中可用。 当我点击预览时,我得到所需的输出,字段在所需的字体样式。 一切都在这里很好。 但生成的pdf文件仍然包含英文字符相同的原始字体。 无论我从应用程序还是从JAVA文件调用报告,结果都是一样的。 经过一番研究,我发现了这个, 第二种方法 JRProperties.setProperty("net.sf.jasperreports.default.pdf.font.name", "C:\\Gujrati-Saral-1.ttf"); 这将pdf的字体设置为提供的ttf字体,但是现在整个pdf都是Guarati-saral字体,这不是我正在寻找的。 有没有一种方法可以将这种字体专门应用于特定的字段? 要么 当用第二种方法时,是否有办法不把字体Guarati-saral应用于除了所需字段之外的所有其他字段?
我想插入空白页的数字PDF使用itext library末尾。我的困惑是添加页面将使现有的签名无效? 谢谢。