Assigning an Existing Custom Layout/Navigator to a

2019-08-28 05:48发布

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

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.

I located this post on SO:

How to embed a .nav file into pdf portfolio?

which lead to:

Adobe® Supplement to the ISO 32000 BaseVersion: 1.7 ExtensionLevel: 3e

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).

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.

1条回答
Rolldiameter
2楼-- · 2019-08-28 06:32

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);

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

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

查看更多
登录 后发表回答