public void TestRemovePageLabels() { Document document = new Document(); for (int i = 0; i < 3; i++) { document.Pages.Add(new Page(PaperFormat.A4)); } PageLabel pageLabel = new PageLabel(0, PageNumberingStyle.DecimalArabic); document.PageLabels.Add(pageLabel); pageLabel.Style = PageNumberingStyle.LowercaseLetters; pageLabel.FirstPageIndex = 1; document.PageLabels.Add(pageLabel); pageLabel.Style = PageNumberingStyle.UppercaseLetters; pageLabel.FirstPageIndex = 2; document.PageLabels.Add(pageLabel); document.Save(OutputFolder + @"\TestRemovePageLabels_before.pdf"); document.PageLabels.Remove(1); document.Save(OutputFolder + @"\TestRemovePageLabels_after.pdf"); document.Dispose(); }
public void TestAddPageLabels() { Document document = new Document(); for (int i = 0; i < 10; i++) { document.Pages.Add(new Page(PaperFormat.A4)); } // first four pages will have labels i, ii, iii, and iv PageLabel pageLabel = new PageLabel(0, PageNumberingStyle.LowercaseRoman); document.PageLabels.Add(pageLabel); // next three pages will have labels 1, 2, and 3 pageLabel.Style = PageNumberingStyle.DecimalArabic; pageLabel.FirstPageIndex = 4; document.PageLabels.Add(pageLabel); // next three pages will have labels A-8, A-9, and A-10 pageLabel.Style = PageNumberingStyle.DecimalArabic; pageLabel.Prefix = "A-"; pageLabel.StartPortion = 8; pageLabel.FirstPageIndex = 7; document.PageLabels.Add(pageLabel); document.Save(OutputFolder + @"\TestAddPageLabels.pdf"); document.Dispose(); }
static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // If you wish to load an existing document uncomment the line below and comment the Add page section instead // pdfDocument.Load(@".\existing_document.pdf"); // Add twenty pages for (int i = 0; i < 20; i++) { pdfDocument.Pages.Add(new Page(PaperFormat.A4)); } // First five pages will have roman numbers I, II, III, ... PageLabel pageLabel = new PageLabel(0, PageNumberingStyle.UppercaseRoman); pdfDocument.PageLabels.Add(pageLabel); // Next five pages will have arabic numbers 6, 7, 8, ... pageLabel.Style = PageNumberingStyle.DecimalArabic; pageLabel.StartPortion = 6; pageLabel.FirstPageIndex = 5; pdfDocument.PageLabels.Add(pageLabel); // Next five pages will have complex page numbers with prefix A-11, A-12, A-13, ... pageLabel.Style = PageNumberingStyle.DecimalArabic; pageLabel.Prefix = "A-"; pageLabel.StartPortion = 11; pageLabel.FirstPageIndex = 10; pdfDocument.PageLabels.Add(pageLabel); // Next five pages will use letters as page numbers P, Q, R, ... pageLabel.Prefix = ""; pageLabel.Style = PageNumberingStyle.UppercaseLetters; pageLabel.StartPortion = 16; pageLabel.FirstPageIndex = 15; pdfDocument.PageLabels.Add(pageLabel); // Force PDF viewer to show page thumbnails panel on start up pdfDocument.PageMode = PageMode.Thumbnail; // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); }
public static XElement ToXElement(this PageLabel label) { return(new XElement("PageLabel", new XElement("Id", label.Id), new XElement("PageId", label.PageId), new XElement("Key", label.Key), new XElement("Value", label.Value) )); }
static void Main(string[] args) { Console.WriteLine("Page Labels Sample:"); // ReSharper disable once UnusedVariable using (Library lib = new Library()) { Console.WriteLine("Initialized the library."); String sInput = Library.ResourceDirectory + "Sample_Input/pagelabels.pdf"; if (args.Length > 0) { sInput = args[0]; } Console.WriteLine("Input file " + sInput); Document doc = new Document(sInput); // Extract a page label from the document String labelString = doc.FindLabelForPageNum(doc.NumPages - 1); Console.WriteLine("Last page in the document is labeled " + labelString); // Index will equal (doc.NumPages - 1) int index = doc.FindPageNumForLabel(labelString); Console.WriteLine(labelString + " has an index of " + index + " in the document."); // Add a new page to the document // It will start on page 5 and have numbers of the style A-i, A-ii, etc. PageLabel pl = new PageLabel(5, NumberStyle.RomanLowercase, "A-", 1); IList <PageLabel> labels = doc.PageLabels; labels.Add(pl); doc.PageLabels = labels; Console.WriteLine("Added page range starting on page 5."); // Change the properties of the third page range labels = doc.PageLabels; // Get a freshly sorted list labels[2].Prefix = "Section 3-"; labels[2].FirstNumberInRange = 2; doc.PageLabels = labels; Console.WriteLine("Changed the prefix for the third range."); // Now walk the list of page labels foreach (PageLabel label in doc.PageLabels) { Console.WriteLine("Label range starts on page " + label.StartPageIndex + ", ends on page " + label.EndPageIndex); Console.WriteLine("The prefix is '" + label.Prefix + "' and begins with number " + label.FirstNumberInRange); Console.WriteLine(); } } }
public void TestOpenDocument() { Document document = new Document(OutputFolder + @"\TestAddPageLabels.pdf"); PageLabel pageLabel = new PageLabel(9, PageNumberingStyle.LowercaseLetters); document.PageLabels.Add(pageLabel); document.Save(OutputFolder + @"\TestOpenDocument.pdf"); document.Dispose(); }
static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add twenty pages for (int i = 0; i < 20; i++) { pdfDocument.Pages.Add(new Page(PaperFormat.A4)); } // First five pages will have roman numbers I, II, III, ... PageLabel pageLabel = new PageLabel(0, PageNumberingStyle.UppercaseRoman); pdfDocument.PageLabels.Add(pageLabel); // Next five pages will have arabic numbers 6, 7, 8, ... pageLabel.Style = PageNumberingStyle.DecimalArabic; pageLabel.StartPortion = 6; pageLabel.FirstPageIndex = 5; pdfDocument.PageLabels.Add(pageLabel); // Next five pages will have complex page numbers with prefix A-11, A-12, A-13, ... pageLabel.Style = PageNumberingStyle.DecimalArabic; pageLabel.Prefix = "A-"; pageLabel.StartPortion = 11; pageLabel.FirstPageIndex = 10; pdfDocument.PageLabels.Add(pageLabel); // Next five pages will use letters as page numbers P, Q, R, ... pageLabel.Prefix = ""; pageLabel.Style = PageNumberingStyle.UppercaseLetters; pageLabel.StartPortion = 16; pageLabel.FirstPageIndex = 15; pdfDocument.PageLabels.Add(pageLabel); // Force PDF viewer to show page thumbnails panel on start up pdfDocument.PageMode = PageMode.Thumbnail; // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open document in default PDF viewer app Process.Start("result.pdf"); }
public override void Run( ) { string outputFilePath; { // 1. Opening the PDF file... string filePath = PromptFileChoice("Please select a PDF file"); using (var file = new File(filePath)) { Document document = file.Document; // 2. Defining the page labels... PageLabels pageLabels = document.PageLabels; pageLabels.Clear(); /* * NOTE: This sample applies labels to arbitrary page ranges: no sensible connection with their * actual content has therefore to be expected. */ int pageCount = document.Pages.Count; pageLabels[new PdfInteger(0)] = new PageLabel(document, "Introduction ", PageLabel.NumberStyleEnum.UCaseRomanNumber, 5); if (pageCount > 3) { pageLabels[new PdfInteger(3)] = new PageLabel(document, PageLabel.NumberStyleEnum.UCaseLetter); } if (pageCount > 6) { pageLabels[new PdfInteger(6)] = new PageLabel(document, "Contents ", PageLabel.NumberStyleEnum.ArabicNumber, 0); } // 3. Serialize the PDF file! outputFilePath = Serialize(file, "Page labelling", "labelling a document's pages", "page labels"); } } { using (var file = new File(outputFilePath)) { foreach (KeyValuePair <PdfInteger, PageLabel> entry in file.Document.PageLabels) { Console.WriteLine("Page label " + entry.Value.BaseObject); Console.WriteLine(" Initial page: " + (entry.Key.IntValue + 1)); Console.WriteLine(" Prefix: " + (entry.Value.Prefix)); Console.WriteLine(" Number style: " + (entry.Value.NumberStyle)); Console.WriteLine(" Number base: " + (entry.Value.NumberBase)); } } } }
public void TestCountLessThenFirstPageIndexAtPageLabels() { Document document = new Document(); for (int i = 0; i < 3; i++) { document.Pages.Add(new Page(PaperFormat.A4)); } PageLabel pageLabel = new PageLabel(4, PageNumberingStyle.LowercaseLetters); document.PageLabels.Add(pageLabel); document.Save(OutputFolder + @"\TestCountLessThenFirstPageIndexAtPageLabels.pdf"); document.Dispose(); }
public override void Run( ) { string outputFilePath; { // 1. Opening the PDF file... string filePath = PromptFileChoice("Please select a PDF file"); using(File file = new File(filePath)) { Document document = file.Document; // 2. Defining the page labels... PageLabels pageLabels = document.PageLabels; pageLabels.Clear(); /* NOTE: This sample applies labels to arbitrary page ranges: no sensible connection with their actual content has therefore to be expected. */ int pageCount = document.Pages.Count; pageLabels[new PdfInteger(0)] = new PageLabel(document, "Introduction ", PageLabel.NumberStyleEnum.UCaseRomanNumber, 5); if(pageCount > 3) {pageLabels[new PdfInteger(3)] = new PageLabel(document, PageLabel.NumberStyleEnum.UCaseLetter);} if(pageCount > 6) {pageLabels[new PdfInteger(6)] = new PageLabel(document, "Contents ", PageLabel.NumberStyleEnum.ArabicNumber, 0);} // 3. Serialize the PDF file! outputFilePath = Serialize(file, "Page labelling", "labelling a document's pages", "page labels"); } } { using(File file = new File(outputFilePath)) { foreach(KeyValuePair<PdfInteger,PageLabel> entry in file.Document.PageLabels) { Console.WriteLine("Page label " + entry.Value.BaseObject); Console.WriteLine(" Initial page: " + (entry.Key.IntValue + 1)); Console.WriteLine(" Prefix: " + (entry.Value.Prefix)); Console.WriteLine(" Number style: " + (entry.Value.NumberStyle)); Console.WriteLine(" Number base: " + (entry.Value.NumberBase)); } } } }
public IHtmlString GetPageLabel(Page page, string key, bool editableInDesignPage) { var label = page.Labels.FirstOrDefault(i => i.Key == key); if (label == null) { lock (_staticKey) { label = new PageLabel { Key = key, Value = key }; page.Labels.Add(label); SaveChanges(); } } return(Wrapper(LabelType.PageLabel, label, editableInDesignPage)); }
internal PageLabel Clone() { PageLabel pageLabel = new PageLabel(_firstPageIndex, PageLabel.Copy(GetDictionary())); return(pageLabel); }
static void Main(string[] args) { PDFNet.Initialize(); try { //----------------------------------------------------------- // Example 1: Add page labels to an existing or newly created PDF // document. //----------------------------------------------------------- { using (PDFDoc doc = new PDFDoc(input_path + "newsletter.pdf")) { doc.InitSecurityHandler(); // Create a page labeling scheme that starts with the first page in // the document (page 1) and is using uppercase roman numbering // style. doc.SetPageLabel(1, PageLabel.Create(doc, PageLabel.Style.e_roman_uppercase, "My Prefix ", 1)); // Create a page labeling scheme that starts with the fourth page in // the document and is using decimal arabic numbering style. // Also the numeric portion of the first label should start with number // 4 (otherwise the first label would be "My Prefix 1"). PageLabel L2 = PageLabel.Create(doc, PageLabel.Style.e_decimal, "My Prefix ", 4); doc.SetPageLabel(4, L2); // Create a page labeling scheme that starts with the seventh page in // the document and is using alphabetic numbering style. The numeric // portion of the first label should start with number 1. PageLabel L3 = PageLabel.Create(doc, PageLabel.Style.e_alphabetic_uppercase, "My Prefix ", 1); doc.SetPageLabel(7, L3); doc.Save(output_path + "newsletter_with_pagelabels.pdf", SDFDoc.SaveOptions.e_linearized); Console.WriteLine("Done. Result saved in newsletter_with_pagelabels.pdf..."); } } //----------------------------------------------------------- // Example 2: Read page labels from an existing PDF document. //----------------------------------------------------------- { using (PDFDoc doc = new PDFDoc(output_path + "newsletter_with_pagelabels.pdf")) { doc.InitSecurityHandler(); PageLabel label; int page_num = doc.GetPageCount(); for (int i = 1; i <= page_num; ++i) { Console.Write("Page number: {0}", i); label = doc.GetPageLabel(i); if (label.IsValid()) { Console.WriteLine(" Label: {0}", label.GetLabelTitle(i)); } else { Console.WriteLine(" No Label."); } } } } //----------------------------------------------------------- // Example 3: Modify page labels from an existing PDF document. //----------------------------------------------------------- { using (PDFDoc doc = new PDFDoc(output_path + "newsletter_with_pagelabels.pdf")) { doc.InitSecurityHandler(); // Remove the alphabetic labels from example 1. doc.RemovePageLabel(7); // Replace the Prefix in the decimal lables (from example 1). PageLabel label = doc.GetPageLabel(4); if (label.IsValid()) { label.SetPrefix("A"); label.SetStart(1); } // Add a new label PageLabel new_label = PageLabel.Create(doc, PageLabel.Style.e_decimal, "B", 1); doc.SetPageLabel(10, new_label); // starting from page 10. doc.Save(output_path + "newsletter_with_pagelabels_modified.pdf", SDFDoc.SaveOptions.e_linearized); Console.WriteLine("Done. Result saved in newsletter_with_pagelabels_modified.pdf..."); int page_num = doc.GetPageCount(); for (int i = 1; i <= page_num; ++i) { Console.Write("Page number: {0}", i); label = doc.GetPageLabel(i); if (label.IsValid()) { Console.WriteLine(" Label: {0}", label.GetLabelTitle(i)); } else { Console.WriteLine(" No Label."); } } } } //----------------------------------------------------------- // Example 4: Delete all page labels in an existing PDF document. //----------------------------------------------------------- { using (PDFDoc doc = new PDFDoc(output_path + "newsletter_with_pagelabels.pdf")) { doc.GetRoot().Erase("PageLabels"); // ... } } } catch (pdftron.Common.PDFNetException e) { Console.WriteLine(e.Message); } }