當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfCopy.AddNamedDestination方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfCopy.AddNamedDestination方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfCopy.AddNamedDestination方法的具體用法?C# PdfCopy.AddNamedDestination怎麽用?C# PdfCopy.AddNamedDestination使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfCopy的用法示例。


在下文中一共展示了PdfCopy.AddNamedDestination方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: InsertDestinationsIntoDocument

        private void InsertDestinationsIntoDocument(string document, IEnumerable<INamedDestination> nameddests)
        {
            if (!File.Exists(document))
                throw new FileNotFoundException("Document not found.", document);

            var extensionIndex = document.IndexOf(".pdf");
            var tempDoc = document.Substring(0, extensionIndex) + "-2.pdf";
            var doc = new Document();
            var copy = new PdfCopy(doc, new FileStream(tempDoc, FileMode.Create));
            doc.Open();
            var reader = new PdfReader(document);
            copy.Outlines = GetBookmarksFromDocument(document).ToList();
            for (int page = 0; page < reader.NumberOfPages; )
            {
                copy.AddPage(copy.GetImportedPage(reader, ++page));
            }
            foreach (var destination in nameddests)
            {
                copy.AddNamedDestination(destination.Name, destination.Page, destination.Destination);
            }
            copy.FreeReader(reader);
            reader.Close();
            doc.Close();
            // TODO: Uniqueness tests?
        }
開發者ID:CaffeineMachine,項目名稱:TextSharpUtils,代碼行數:25,代碼來源:BookmarkDuplicator.cs

示例2: MergeNamedDestinationsTest

        public void MergeNamedDestinationsTest()  {
            string outputFolder = "PdfCopyTest/";
            string outputFile = "namedDestinations.pdf";
            Directory.CreateDirectory(outputFolder);

            // Create simple document
            MemoryStream main = new MemoryStream();
            Document doc = new Document(new Rectangle(612f,792f),54f,54f,36f,36f);
            PdfWriter pdfwrite = PdfWriter.GetInstance(doc, main);
            doc.Open();
            doc.Add(new Paragraph("Testing Page"));
            doc.Close();

            // Create TOC document
            MemoryStream two = new MemoryStream();
            Document doc2 = new Document(new Rectangle(612f,792f),54f,54f,36f,36f);
            PdfWriter pdfwrite2 = PdfWriter.GetInstance(doc2, two);
            doc2.Open();
            Chunk chn = new Chunk("<<-- Link To Testing Page -->>");
            chn.SetRemoteGoto("DUMMY.PDF","page-num-1");
            doc2.Add(new Paragraph(chn));
            doc2.Close();

            // Merge documents
            MemoryStream three = new MemoryStream();
            PdfReader reader1 = new PdfReader(main.ToArray());
            PdfReader reader2 = new PdfReader(two.ToArray());
            Document doc3 = new Document();
            PdfCopy DocCopy = new PdfCopy(doc3,three);
            doc3.Open();
            DocCopy.AddPage(DocCopy.GetImportedPage(reader2,1));
            DocCopy.AddPage(DocCopy.GetImportedPage(reader1,1));
            DocCopy.AddNamedDestination("page-num-1",2,new PdfDestination(PdfDestination.FIT));
            doc3.Close();

            // Fix references and write to file
            PdfReader finalReader = new PdfReader(three.ToArray());
            finalReader.MakeRemoteNamedDestinationsLocal();
            PdfStamper stamper = new PdfStamper(finalReader,new  FileStream(outputFolder + outputFile, FileMode.Create));
            stamper.Close();

           
            CompareTool compareTool = new CompareTool();
            String errorMessage = compareTool.CompareByContent(outputFolder + outputFile, RESOURCES + "cmp_" + outputFile, outputFolder, "diff");
            if (errorMessage != null) {
                Assert.Fail(errorMessage);
            }
        }
開發者ID:newlysoft,項目名稱:itextsharp,代碼行數:48,代碼來源:PdfCopyTest.cs


注:本文中的iTextSharp.text.pdf.PdfCopy.AddNamedDestination方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。