Example #1
0
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            // Create a PDF Package.
            try
            {
                using (PDFDoc doc = new PDFDoc())
                {
                    AddPackage(doc, input_path + "numbered.pdf", "My File 1");
                    AddPackage(doc, input_path + "newsletter.pdf", "My Newsletter...");
                    AddPackage(doc, input_path + "peppers.jpg", "An image");
                    AddCovePage(doc);
                    doc.Save(output_path + "package.pdf", SDFDoc.SaveOptions.e_linearized);
                    Console.WriteLine("Done.");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

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

                    pdftron.SDF.NameTree files = NameTree.Find(doc, "EmbeddedFiles");
                    if (files.IsValid())
                    {
                        // 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)
                            {
                                string fname = output_path + "extract_" + counter.ToString() + ".pdf";
                                stm.WriteToFile(fname, false);
                            }
                        }
                    }
                }

                Console.WriteLine("Done.");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }