我正在使用iTextSharp 5.x.我正在尝试合并两个pdf并保留isTagged标志。当我删除copy.SetTagged();结果pdf包含两个pdfs,这很棒。添加copy.SetTagged()时会出现异常
Exception -->System.ObjectDisposedException: Cannot access a closed file.
at System.IO.__Error.FileNotOpen()
at System.IO.FileStream.get_Position()
这是代码
List<string> filesToMerge = new List<string> { "C:/dev/dcs/wp-cla-dcs/Hex/Docs/metadata/coverPage.pdf", "C:/dev/dcs/wp-cla-dcs/Hex/Docs/metadata/49W7a.pdf" };
string outputFileName = "C:/dev/dcs/wp-cla-dcs/Hex/Docs/metadata/results.pdf";
using (FileStream outFS = new FileStream(outputFileName, FileMode.Create))
using (Document document = new Document())
// using (PdfCopy copy = new PdfCopy(document, outFS))
using (PdfCopy copy = new PdfSmartCopy(document, outFS))
{
{
copy.SetTagged();
// Set up the iTextSharp document
document.Open();
foreach (string pdfFile in filesToMerge)
{
using (var reader = new PdfReader(pdfFile))
{
copy.AddDocument(reader);
copy.FreeReader(reader);
}
}
}
}
答案 0 :(得分:0)
尽管有@ bruno-lowagie的评论,但使用iText5可以达到更好的效果。
Uisng iText7,[Given(@"Create new user of type ""(.*)""")]
public void CreateNewUser(UserTypeEnum userType)
{
// some code like e.g.:
MyUser user = new MyUser(userType);
//...
}
enum UserTypeEnum { CommonUser, PlatinumUser, Spectre }
留下了几个未加标签的内容(所有内容都在源文档中加了标签)。 iText5中的PdfMerger
可以正常工作,只需要手动添加Xmp元数据,标题,lang等即可。
PdfCopy