将现有自定义布局/导航器分配给iTextSharp生成的投资组合 [英] Assigning an Existing Custom Layout/Navigator to a Portfolio Generated By iTextSharp

查看:122
本文介绍了将现有自定义布局/导航器分配给iTextSharp生成的投资组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过iTextSharp生成馆藏(Acrobat Portfolios)。我想将现有的自定义导航器(自定义布局)分配给生成的集合。我相信iTextSharp允许CUSTOM参数定义自定义导航器,如此块的最后一个代码行:

I am generating collections (Acrobat Portfolios) via iTextSharp. I would like to assign an existing custom navigator (custom layout) to the generated collection. I believe iTextSharp allows for the CUSTOM parameter to define a custom navigator, as in the last code line of this block:

        Document document = new Document();
        FileStream stream = new FileStream(portfolioPath, FileMode.Create);
        PdfWriter writer = PdfWriter.GetInstance(document, stream);
        document.Open();
        document.Add(new Paragraph(" "));
        PdfCollection collection = new PdfCollection(PdfCollection.CUSTOM); 
        //The integer 3 can also substitute for PdfCollection.CUSTOM

然而,当集合时/ portfolio产生CUSTOM参数在生成的集合中插入TILE布局。我想让CUSTOM参数使用我开发的自定义.nav导航器来插入自定义布局。

However, when the collection/portfolio is generated the CUSTOM parameter inserts the TILE layout within the generated collection. I want to have the CUSTOM parameter use a custom .nav navigator I developed to insert a custom layout.

我将此帖子放在SO上:

I located this post on SO:

如何嵌入.nav归档为pdf组合?

导致:

Adobe®补充
ISO 32000
BaseVersion: 1.7
ExtensionLevel:3e

本文档的第34-37页说,通过调整导航器,集合可以访问自定义导航器在集合字典和导航器字典本身中输入。此外,第二版iText in Action 的第541页暗示这是可能的(我希望在iTextSharp中也可以实现iText的可能性。)

Pages 34 - 37 of this document says it is possible to have the collection access the custom navigator by adjusting the Navigator entry in the collection dictionary and the navigator dictionary itself. Additionally, page 541 of the Second Edition of iText in Action implies this is possible (and it is my hope what is possible in iText is also possible in iTextSharp).

因此可以使用iTextSharp获得生成的集合/组合访问权限并实现自定义布局/导航器吗?如果是这样,怎么样?或者有其他方法通过C#和/或通过一些解决方法来做到这一点?非常感谢所有帮助。

So is it possible -- using iTextSharp -- to have a generated collection/portfolio access and implement a custom layout/navigator? If so, how? Or is there another way to do this via C# and/or through some workaround? All help is greatly appreciated.

推荐答案

我找到了一种使用iTextSharp指定自定义布局/导航器的不同方法。

I found a different way to dictate the custom layout/navigator using iTextSharp. Instead of defining the custom layout during or after

PdfCollection collection = new PdfCollection(PdfCollection.CUSTOM);

我扔掉了我的问题中列出的代码并使用了iTextSharp压模。

I threw out the code listed in my question and used the iTextSharp stamper.

首先,我创建了一个空的投资组合文件。在这个文件中,我分配了我想要使用的自定义布局。打开时,文件显示布局,但不包含附加文件。此文件将用作模板,并使用以下代码将其导航器分配给每个新创建的iTextSharp PDF:

First, I created an empty portfolio file. Within this file I assigned the custom layout that I wanted to use. When opened the file displays the layout, but contains no attached files. This file will serve as a template and assign it's navigator to each newly created iTextSharp PDF using this code:

 const string templatePath = @"C:\PortfolioTemplate\PortfolioTemplate.pdf"; //this file will contain the custom navigator/layout for the new pdf
 const string portfolioPath = @"C:\OutputFile\NewPortfolio.pdf";
 string[] packageitems = { file-to-add-to-collection };

 PdfReader reader = new PdfReader(templatePath);
 FileStream outputstream = new FileStream(portfolioPath, FileMode.Create);
 PdfStamper stamp = new PdfStamper(reader, outputstream);
 PdfFileSpecification fs = PdfFileSpecification.FileEmbedded(stamp.Writer, packageitems[0], packageitems[0], null);
 stamp.AddFileAttachment(packageitems[0], fs);
 stamp.Close();

我使用上面的概念证明来遍历目录文件夹中的所有文件并且我创建了没有问题的大型投资组合使用我想要的自定义导航器/布局设置样式。

I used the above proof of concept to loop through all the files in a directory folder and I have created large portfolios without issue that are styled using the custom navigator/layout I wanted.

在提出使用模板将导航器传递到新创建的投资组合的想法之后,我使用下面链接中的代码指导我得出上述结论:

After coming up with the idea of using a template to pass the navigator into a newly created portfolio, I used the code in the below link to guide me to the above conclusion:

http://itextsharp.10939.n7.nabble.com/Attach-file-td3812.html

这篇关于将现有自定义布局/导航器分配给iTextSharp生成的投资组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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