插入文本然后合并pdf [英] Insert text and then merge pdf

查看:249
本文介绍了插入文本然后合并pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IText7版本7.0.2.2,我是新手,我正在尝试将几个pdf同时合并到我首先上传的一个,这样工作正常,问题是什么时候我动态尝试在其中一个pdf中插入一些文本然后合并它,我正在使用PdfWriter将一些内容写入pdf然后尝试合并它,但我得到了这个异常: '无法从正在写入的文档中复制间接对象。

I'm using IText7 version 7.0.2.2, I'm new with it, I'm trying to merge several pdfs at the same time into one that I'm uploading first, that is working fine, the problem is when I try dynamically to insert some text in one of the pdfs and then merge it, I'm using PdfWriter to write some content into the pdf and then try to merge it, but I'm getting this exception: 'Cannot copy indirect object from the document that is being written.

这是我正在使用的一些代码:

This is some of the code I'm using:

private byte[] MergePdfForms( HttpPostedFileBase firstPdf, List<SectionAndPdfs> sectionsAndPdf)
        {
var dest = new MemoryStream();
            PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
            PdfMerger merger = new PdfMerger(pdf);
firstSourcePdf = new PdfDocument(new PdfReader(keyValuePair.Value), new PdfWriter(dest));
Document document = new Document(firstSourcePdf);
document.Add(new Paragraph(sectionsAndPdf[i].Key).SetBackgroundColor(iText.Kernel.Colors.Color.GRAY)); 

merger.Merge(firstSourcePdf, 1, subPages); //I'm getting the exception here..
firstSourcePdf.Close();
}


推荐答案

这是一个已知的错误PdfDestination类。它已修复,并将出现在我们的下一个版本中。目前你可以使用快照发布,这应该可以解决问题。

This is a known bug in the class PdfDestination. It was fixed, and will be present in our next release. At the moment you can of course use the snapshot release, which should solve the problem.

这篇关于插入文本然后合并pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆