How do I create PDF Portfolios? How do extract parts from a PDF Package?

Q: I am looking to create PDF Portfolios programmatically. Is this
possible using PDFNet SDK ( (I'm not
sure if PDF Packages are different, but that would be okay too.)
Basically my end result needs to be a single .pdf file that contains
multiple pdfs within it. Example a cover sheet, and various other
separate pdfs all contained within this one single .pdf file. Do you
have an idea on how this can be done?
A: You can use PDFNet to create, extract, or manage PDF Packages. PDF
Portfolios are just another name for PDF Packages and they refer to
the same thing.

Attached is a sample project (
sdk/web/ that illustrates how to create a PDF
Portfolio as well as how to extract document parts from an existing
PDF package. To run the example simple extract the archive in 'PDFNet/
Samples' folder. You can download PDFNet SDK from

// Copyright (c) 2001-2009 by PDFTron Systems Inc. All Rights
using System;
using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

namespace AnnotationTestCS
  /// <summary>
  /// This sample illustrates how to create, extract, and manipulate
PDF Portfolios
    /// (a.k.a. PDF Packages) using PDFNet SDK.
  /// </summary>
  class Class1
    // Relative path to the folder containing test files.
    const string input_path = "../../../../TestFiles/";
    const string output_path = "../../../../TestFiles/Output/";

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main(string[] args)

      // Create a PDF Package.
        PDFDoc doc = new PDFDoc();
        AddPackage(doc, input_path + "numbered.pdf", "My File 1");
        AddPackage(doc, input_path + "newsletter.pdf", "My
        AddPackage(doc, input_path + "peppers.jpg", "An image");
        doc.Save(output_path + "package.pdf",
      catch (PDFNetException e)

      // Extract parts from a PDF Package.
        PDFDoc doc = new PDFDoc(output_path + "package.pdf");

        pdftron.SDF.NameTree files = NameTree.Find(doc, "EmbeddedFiles");
          // Traverse the list of embedded files.
          NameTreeIterator i = files.GetIterator();
          for (int counter = 0; i.HasNext(); i.Next(), ++counter)
            string entry_name = i.Key().GetAsPDFText();
            Console.WriteLine("Part: {0}", entry_name);
            FileSpec file_spec = new FileSpec(i.Value());
            Filter stm = file_spec.GetFileData();
            if (stm!=null)
              FilterReader reader = new FilterReader(stm);
              string fname = output_path + "extract_" + counter.ToString();
              StdFile f = new StdFile(fname, StdFile.OpenMode.e_write_mode);
              FilterWriter writer = new FilterWriter(f);

    static void AddPackage(PDFDoc doc, string file, string desc)
      NameTree files = NameTree.Create(doc, "EmbeddedFiles");
      FileSpec fs = FileSpec.Create(doc, file, true);
      byte[] file1_name = System.Text.Encoding.UTF8.GetBytes(file);
      files.Put(file1_name, fs.GetSDFObj());
      fs.GetSDFObj().PutText("Desc", desc);

      Obj collection = doc.GetRoot().FindObj("Collection");
      if (collection == null) collection = doc.GetRoot().PutDict

      // You could here manipulate any entry in the Collection
      // For example, the following line sets the tile mode for initial
view mode
      // Please refer to section '2.3.5 Collections' in PDF Reference for
      collection.PutName("View", "T");

    static void AddCovePage(PDFDoc doc)
      // Here we dynamically generate cover page (please see
      // sample for more extensive coverage of PDF creation API).
      Page page = doc.PageCreate(new Rect(0, 0, 200, 200));

      ElementBuilder b = new ElementBuilder();
      ElementWriter w = new ElementWriter();
      Font font = Font.CreateTrueTypeFont(doc.GetSDFDoc(), new
System.Drawing.Font("Comic Sans MS", 12), true, false);
      w.WriteElement(b.CreateTextBegin(font, 12));
      Element e = b.CreateTextRun("My PDF Collection");
      e.SetTextMatrix(1, 0, 0, 1, 50, 96);
      e.GetGState().SetFillColor(new ColorPt(1, 0, 0));

      // Alternatively we could import a PDF page from a template PDF
      // (for an example please see PDFPage sample project).
      // ...