public void Empty() { var tree = new NameTree(Enumerable.Empty<string>()); Assert.AreEqual(0, tree.Root.Children.Count); Assert.AreEqual(string.Empty, tree.Root.Name); Assert.AreEqual(string.Empty, tree.Root.FullName); }
public void Empty() { var tree = new NameTree(Enumerable.Empty <string>()); Assert.AreEqual(0, tree.Root.Children.Count); Assert.AreEqual(string.Empty, tree.Root.Name); Assert.AreEqual(string.Empty, tree.Root.FullName); }
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); } }
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("Collection"); } // You could here manipulate any entry in the Collection dictionary. // 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 details. collection.PutName("View", "T"); }
static void Main(string[] args) { Console.WriteLine("NameTree Sample:"); using (Library lib = new Library()) { Console.WriteLine("Initialized the library."); // Create a new document and blank first page Document doc = new Document(); Rect rect = new Rect(0, 0, 612, 792); Page page = doc.CreatePage(Document.BeforeFirstPage, rect); Console.WriteLine("Created new document and first page."); // Create a NumberTree and put a key-value pair in it NameTree nametree = new NameTree(doc); // Use put() to put a key-value pair in it PDFString key = new PDFString("Bailout", doc, false, false);; PDFString value = new PDFString("Smorgasbord", doc, false, false); nametree.Put(key, value); Console.WriteLine("\nCreated NameTree and added first key-value pair."); // Put another key-value pair in it nametree.Put(new PDFString("Brandish", doc, false, false), new PDFString("Copasetic", doc, false, false)); // Retrieve second entry PDFString keysearchstring = new PDFString("Brandish", doc, false, false); PDFObject lookup = nametree.Get(keysearchstring); Console.WriteLine("\nRetrieving two entries:"); Console.WriteLine(lookup); // Retrieve first entry lookup = nametree.Get(new PDFString("Bailout", doc, false, false)); Console.WriteLine(lookup); // Use remove() method to remove first entry nametree.Remove(new PDFString("Bailout", doc, false, false)); // Get both entries, and demonstrate that first is now gone Console.WriteLine("\nAfter removing entry 1, we now have:"); lookup = nametree.Get(new PDFString("Bailout", doc, false, false)); Console.WriteLine(lookup); lookup = nametree.Get(new PDFString("Brandish", doc, false, false)); Console.WriteLine(lookup); // Create two new NameTrees and set each to our original numbertree NameTree abc = nametree; NameTree xyz = nametree; // Show they are equal if (abc.Equals(xyz)) { Console.WriteLine("\nThe two NameTrees abc and xyz are the same"); } else { Console.WriteLine("\nThe two NameTrees abc and xyz are not the same"); } // Create two new NameTrees abc = new NameTree(doc); xyz = new NameTree(doc); // Show they are not equal if (abc.Equals(xyz)) { Console.WriteLine("\nThe two NameTrees abc and xyz are the same"); } else { Console.WriteLine("\nThe two NameTrees abc and xyz are not the same"); } // Get the PDFDict from the NameTree PDFDict dict = nametree.PDFDict; Console.WriteLine("\nThe PDFDict from the NameTree:"); Console.WriteLine(dict); // Kill the NameTree object nametree.Dispose(); Console.WriteLine("\nKilled the NameTree object."); ////////////////////////////////////////////////// // Now use Document methods to operate on NameTree ////////////////////////////////////////////////// // Create a NameTree in the document using createNameTree() method NameTree docCreatedNameTree = doc.CreateNameTree("MyNameTree"); docCreatedNameTree.Put(new PDFString("Argyle", doc, false, false), new PDFString("Seamstress", doc, false, false)); Console.WriteLine("Created a NameTree object in the document."); // Look for the NameTree in the document by using the getNameTree() method Console.WriteLine("\nTwo searches for NameTree using getNameTree() method; first fails, second succeeeds:"); docCreatedNameTree = doc.GetNameTree("Garbage"); Console.WriteLine(docCreatedNameTree); docCreatedNameTree = doc.GetNameTree("MyNameTree"); Console.WriteLine(docCreatedNameTree); // Remove the NameTree from the document by using the remove NameTree() method Console.WriteLine("\nRemove the NameTree from the document."); doc.RemoveNameTree("Garbage"); docCreatedNameTree = doc.GetNameTree("MyNameTree"); Console.WriteLine(docCreatedNameTree); doc.RemoveNameTree("MyNameTree"); docCreatedNameTree = doc.GetNameTree("MyNameTree"); Console.WriteLine(docCreatedNameTree); // Kill the doc object doc.Dispose(); } }
public void WithoutRoot() { var tree = new NameTree( new[] { // level 0 // (empty root) // level 1 "i", "j", // missing "k" on purpose // level 2 "i.m", "i.n", // missing "k.m" on purpose // level 3 "i.m.x", "i.n.x", "i.n.y", "k.m.x", "k.m.y", "k.m.z", } ); // level 0 Assert.AreEqual(string.Empty, tree.Root.Name); Assert.AreEqual(string.Empty, tree.Root.FullName); // level 1 Assert.AreEqual(3, tree.Root.Children.Count); var i = tree.Root.Children[0]; Assert.AreEqual("i", i.Name); Assert.AreEqual("i", i.FullName); var j = tree.Root.Children[1]; Assert.AreEqual("j", j.Name); Assert.AreEqual("j", j.FullName); var k = tree.Root.Children[2]; Assert.AreEqual("k", k.Name); Assert.AreEqual("k", k.FullName); // level 2 Assert.AreEqual(2, i.Children.Count); Assert.AreEqual(1, k.Children.Count); var im = i.Children[0]; Assert.AreEqual("m", im.Name); Assert.AreEqual("i.m", im.FullName); var @in = i.Children[1]; Assert.AreEqual("n", @in.Name); Assert.AreEqual("i.n", @in.FullName); var km = k.Children[0]; Assert.AreEqual("m", km.Name); Assert.AreEqual("k.m", km.FullName); // level 3 Assert.AreEqual(1, im.Children.Count); Assert.AreEqual(2, @in.Children.Count); Assert.AreEqual(3, km.Children.Count); var imx = im.Children[0]; Assert.AreEqual("x", imx.Name); Assert.AreEqual("i.m.x", imx.FullName); var inx = @in.Children[0]; Assert.AreEqual("x", inx.Name); Assert.AreEqual("i.n.x", inx.FullName); var iny = @in.Children[1]; Assert.AreEqual("y", iny.Name); Assert.AreEqual("i.n.y", iny.FullName); var kmx = km.Children[0]; Assert.AreEqual("x", kmx.Name); Assert.AreEqual("k.m.x", kmx.FullName); var kmy = km.Children[1]; Assert.AreEqual("y", kmy.Name); Assert.AreEqual("k.m.y", kmy.FullName); var kmz = km.Children[2]; Assert.AreEqual("z", kmz.Name); Assert.AreEqual("k.m.z", kmz.FullName); }
public void WithRoot() { var tree = new NameTree( new[] { "a.i.m.x", "a.i.n.x", "a.i.n.y", "a.j.m.x", "a.j.m.y", "a.j.m.z", } ); // level 0 var a = tree.Root; Assert.AreEqual("a", a.Name); Assert.AreEqual("a", a.FullName); // level 1 Assert.AreEqual(2, a.Children.Count); var ai = a.Children[0]; Assert.AreEqual("i", ai.Name); Assert.AreEqual("a.i", ai.FullName); var aj = a.Children[1]; Assert.AreEqual("j", aj.Name); Assert.AreEqual("a.j", aj.FullName); // level 2 Assert.AreEqual(2, ai.Children.Count); Assert.AreEqual(1, aj.Children.Count); var aim = ai.Children[0]; Assert.AreEqual("m", aim.Name); Assert.AreEqual("a.i.m", aim.FullName); var ain = ai.Children[1]; Assert.AreEqual("n", ain.Name); Assert.AreEqual("a.i.n", ain.FullName); var ajm = aj.Children[0]; Assert.AreEqual("m", ajm.Name); Assert.AreEqual("a.j.m", ajm.FullName); // level 3 Assert.AreEqual(1, aim.Children.Count); Assert.AreEqual(2, ain.Children.Count); Assert.AreEqual(3, ajm.Children.Count); var aimx = aim.Children[0]; Assert.AreEqual("x", aimx.Name); Assert.AreEqual("a.i.m.x", aimx.FullName); var ainx = ain.Children[0]; Assert.AreEqual("x", ainx.Name); Assert.AreEqual("a.i.n.x", ainx.FullName); var ainy = ain.Children[1]; Assert.AreEqual("y", ainy.Name); Assert.AreEqual("a.i.n.y", ainy.FullName); var ajmx = ajm.Children[0]; Assert.AreEqual("x", ajmx.Name); Assert.AreEqual("a.j.m.x", ajmx.FullName); var ajmy = ajm.Children[1]; Assert.AreEqual("y", ajmy.Name); Assert.AreEqual("a.j.m.y", ajmy.FullName); var ajmz = ajm.Children[2]; Assert.AreEqual("z", ajmz.Name); Assert.AreEqual("a.j.m.z", ajmz.FullName); }
private void loadDestinations() { PDFDictionary dictionary = _dictionary["Dests"] as PDFDictionary; _dests = dictionary == null ? new NameTree() : new NameTree(dictionary); }