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


C# PdfCopy.AddDocument方法代碼示例

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


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

示例1: CreateMergedPDF

        static void CreateMergedPDF(string targetPDF, string sourceDir)
        {
            using (FileStream stream = new FileStream(targetPDF, FileMode.Create))
            {
                Document pdfDoc = new Document(PageSize.A4);
                PdfCopy pdf = new PdfCopy(pdfDoc, stream);
                pdfDoc.Open();
                var files = Directory.GetFiles(sourceDir);
                Console.WriteLine("Merging files count: " + files.Length);
                int i = 1;
                foreach (string file in files)
                {
                    Console.WriteLine(i + ". Adding: " + file);
                    pdf.AddDocument(new PdfReader(file));
                    i++;
                }

                if (pdfDoc != null)
                    pdfDoc.Close();

                Console.WriteLine("SpeedPASS PDF merge complete.");
            }
        }
開發者ID:VimalKumarS,項目名稱:CodingChallenge,代碼行數:23,代碼來源:Program.cs

示例2: MergePDFs

 //Code found on net
 /// <summary>
 /// Gets the 2 file names in the array and adds in that specific order
 /// </summary>
 /// <param name="fileNames"></param>
 /// <param name="targetPdfName"></param>
 /// <returns></returns>
 private static bool MergePDFs(string[] fileNames, string targetPdfName)
 {
     bool merged = true;
     using (FileStream stream = new FileStream(targetPdfName, FileMode.Create))
     {
         Document document = new Document();
         PdfCopy pdf = new PdfCopy(document, stream);
         PdfReader reader = null;
         try
         {
             document.Open();
             foreach (string file in fileNames)
             {
                 reader = new PdfReader(file);
                 pdf.AddDocument(reader);
                 reader.Close();
             }
         }
         catch (Exception)
         {
             merged = false;
             if (reader != null)
             {
                 reader.Close();
             }
         }
         finally
         {
             if (document != null)
             {
                 document.Close();
             }
         }
     }
     return merged;
 }
開發者ID:sath1994,項目名稱:ResumeCVCombiner,代碼行數:43,代碼來源:Form1.cs

示例3: MergePDFs

        // PDF 파일 Merge하는 핵심 메소드
        private void MergePDFs(/*IEnumerable<string> fileNames, string targetPdf*/)
        {
            List<string> fileNames = mFileListToMerge;
            string targetPdf = mDestFilePath;
            int count = 0;
            Document document;
            PdfCopy pdfCopy;
            bool merged = true;

            using (FileStream destStream = new FileStream(targetPdf, FileMode.Create))
            {
                document = new Document();
                pdfCopy = new PdfCopy(document, destStream);  // 항상 PdfCopy는 Documnet.Open() 보다 먼저 생성되어야 한다.
                document.Open();
                PdfReader reader = null;

                try
                {
                    foreach (string file in fileNames)
                    {
                        reader = new PdfReader(file);

                        // 파일 합침.
                        pdfCopy.AddDocument(reader);

                        // 스레드 내부에서 Control 접근
                        this.setProgressBar(++count);
                        this.setMessage(string.Format("병합중입니다({0}/{1})", count, fileNames.Count));
                        reader.Close();
                    }

                }
                catch (Exception e)
                {
                    MessageBox.Show("error:" + e.Message);

                    merged = false;
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
                finally
                {
                    if (document != null)
                    {
                        document.Close();
                        destStream.Close();
                    }

            #if false
                    // DialogResult에 값을 넣고 나서 이 함수를 빠져나가면 자동으로 Form이
                    // 종료되는 현상이 있음. 굳이 exitForm()을 호출하지 않아도 됨.
                    if (merged == true)
                    {
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    }
                    else
                    {
                        this.DialogResult = System.Windows.Forms.DialogResult.Abort;
                    }
            #endif

                    // Form 종료
                    if( merged == true)
                        this.exitForm(System.Windows.Forms.DialogResult.OK);
                    else
                        this.exitForm(System.Windows.Forms.DialogResult.Abort);
                }
            }
        }
開發者ID:somanet,項目名稱:iTextTools,代碼行數:72,代碼來源:PDFMergerForm.cs

示例4: LargeFilePerformanceTest

        public virtual void LargeFilePerformanceTest() {
            const string target = "PdfCopyTest/";
            const string output = "copyLargeFile.pdf";
            const string cmp = "cmp_copyLargeFile.pdf";
            
            Directory.CreateDirectory(target);

            Stopwatch timer = new Stopwatch();
            timer.Start();

            PdfReader firstSourceReader = new PdfReader(RESOURCES + "frontpage.pdf");
            PdfReader secondSourceReader = new PdfReader(RESOURCES + "large_pdf.pdf");

            Document document = new Document();

            PdfCopy copy = new PdfCopy(document, File.Create(target + output));
            copy.SetMergeFields();

            document.Open();
            copy.AddDocument(firstSourceReader);
            copy.AddDocument(secondSourceReader);

            copy.Close();
            document.Close();

            timer.Stop();
            Console.WriteLine(timer.ElapsedMilliseconds);

            CompareTool cmpTool = new CompareTool();
            String errorMessage = cmpTool.CompareByContent(target + output, RESOURCES + cmp, target, "diff");

            if (errorMessage != null) {
                Assert.Fail(errorMessage);
            }
        }
開發者ID:newlysoft,項目名稱:itextsharp,代碼行數:35,代碼來源:PdfCopyTest.cs

示例5: CopyFields4Test

        public virtual void CopyFields4Test() {
            string target = "PdfCopyTest/";
            Directory.CreateDirectory(target);
            const string outfile = "copyFields4.pdf";
            const string inputFile = "link.pdf";

            Document document = new Document();
            MemoryStream stream = new MemoryStream();
            PdfWriter.GetInstance(document, stream);
            Font font = new Font(BaseFont.CreateFont(RESOURCES + "fonts/georgia.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED), 9);
            document.Open();
            document.Add(new Phrase("text", font));
            document.Close();

            Document pdfDocument = new Document();
            PdfCopy copier = new PdfCopy(pdfDocument, new FileStream(target + outfile, FileMode.Create));
            copier.SetMergeFields();
            pdfDocument.Open();

            PdfReader reader1 = new PdfReader(RESOURCES + inputFile);
            PdfReader reader2 = new PdfReader(stream.ToArray());

            copier.AddDocument(reader1);
            copier.AddDocument(reader2);
            copier.Close();
            CompareTool cmpTool = new CompareTool();
            string errorMessage = cmpTool.CompareByContent(target + outfile, RESOURCES + "cmp_" + outfile, target, "diff");
            if (errorMessage != null)
                Assert.Fail(errorMessage);
        }
開發者ID:newlysoft,項目名稱:itextsharp,代碼行數:30,代碼來源:PdfCopyTest.cs

示例6: CopyFields3Test

        public virtual void CopyFields3Test() {
            Document pdfDocument = new Document();
            Directory.CreateDirectory("PdfCopyTest/");
            PdfCopy copier = new PdfCopy(pdfDocument, new FileStream("PdfCopyTest/copyFields3.pdf", FileMode.Create));
            copier.SetMergeFields();
            pdfDocument.Open();

            PdfReader reader = new PdfReader(RESOURCES + "hello2_with_comments.pdf");
            copier.AddDocument(reader);
            copier.Close();
            CompareTool compareTool = new CompareTool();
            String errorMessage = compareTool.CompareByContent("PdfCopyTest/copyFields3.pdf", RESOURCES + "cmp_copyFields3.pdf", "PdfCopyTest/", "diff");
            if (errorMessage != null) {
                Assert.Fail(errorMessage);
            }
        }
開發者ID:newlysoft,項目名稱:itextsharp,代碼行數:16,代碼來源:PdfCopyTest.cs

示例7: CopyFields1Test

        public virtual void CopyFields1Test() {
            Document pdfDocument = new Document();
            Directory.CreateDirectory("PdfCopyTest/");
            PdfCopy copier = new PdfCopy(pdfDocument, new FileStream("PdfCopyTest/copyFields.pdf", FileMode.Create));
            copier.SetMergeFields();

            pdfDocument.Open();

            PdfReader readerMain = new PdfReader(RESOURCES + "fieldsOn3-sPage.pdf");
            PdfReader secondSourceReader = new PdfReader(RESOURCES + "fieldsOn2-sPage.pdf");
            PdfReader thirdReader = new PdfReader(RESOURCES + "appearances1.pdf");

            copier.AddDocument(readerMain);
            copier.CopyDocumentFields(secondSourceReader);
            copier.AddDocument(thirdReader);

            copier.Close();
            readerMain.Close();
            secondSourceReader.Close();
            thirdReader.Close();
            CompareTool compareTool = new CompareTool();
            String errorMessage = compareTool.CompareByContent("PdfCopyTest/copyFields.pdf", RESOURCES + "cmp_copyFields.pdf", "PdfCopyTest/", "diff");
            if (errorMessage != null) {
                Assert.Fail(errorMessage);
            }
        }
開發者ID:newlysoft,項目名稱:itextsharp,代碼行數:26,代碼來源:PdfCopyTest.cs

示例8: TestFullCompression2

        public virtual void TestFullCompression2() {
            Directory.CreateDirectory("PdfCopyTest/");
            String outfile = "PdfCopyTest/out-forms.pdf";
            String first = RESOURCES + "subscribe.pdf";
            String second = RESOURCES + "filled_form_1.pdf";
            FileStream out_ = new FileStream(outfile, FileMode.Create);
            PdfReader reader = new PdfReader(first);
            PdfReader reader2 = new PdfReader(second);
            Document pdfDocument = new Document();
            PdfCopy pdfCopy = new PdfCopy(pdfDocument, out_);
            pdfCopy.SetMergeFields();
            pdfCopy.SetFullCompression();
            pdfCopy.CompressionLevel = PdfStream.BEST_COMPRESSION;
            pdfDocument.Open();
            pdfCopy.AddDocument(reader);
            pdfCopy.AddDocument(reader2);
            pdfCopy.Close();
            reader.Close();
            reader2.Close();

            reader = new PdfReader("PdfCopyTest/out-forms.pdf");
            Assert.NotNull(reader.GetPageN(1));
            reader.Close();
        }
開發者ID:newlysoft,項目名稱:itextsharp,代碼行數:24,代碼來源:PdfCopyTest.cs

示例9: CombineMultiplePDFs

 /// <summary>
 /// 
 /// </summary>
 /// <param name="fileNames"></param>
 /// <param name="outFile"></param>
 public static void CombineMultiplePDFs(string[] fileNames, string outFile)
 {
     using (FileStream stream = new FileStream(outFile, FileMode.Create))
     {
         Document pdfDoc = new Document(PageSize.A4);
         PdfCopy pdf = new PdfCopy(pdfDoc, stream);
         pdfDoc.Open();
         foreach (string file in fileNames) pdf.AddDocument(new PdfReader(file));
         if (pdfDoc != null) pdfDoc.Close();
     }
 }
開發者ID:BathnesDevelopment,項目名稱:PDF-Joiner,代碼行數:16,代碼來源:MainWindow.xaml.cs

示例10: PdfMerger

        public bool PdfMerger(string[] fileNames, string targetPdf)
        {
           
            try
            {

                bool merged = true;
                using (FileStream stream = new FileStream(targetPdf, FileMode.Create))
                {
                    Document document = new Document();
                    PdfCopy pdf = new PdfCopy(document, stream);
                    PdfReader reader = null;
                    try
                    {
                        document.Open();
                        foreach (string file in fileNames)
                        {
                            reader = new PdfReader(file);
                            pdf.AddDocument(reader);
                            reader.Close();
                        }
                    }
                    catch (Exception)
                    {
                        merged = false;
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }
                    finally
                    {
                        if (document != null)
                        {
                            document.Close();
                        }
                    }
                }
                return merged;
               
            }
            catch (Exception e)
            {
                LogHelper.Logger(commandType + e.Message, _logPath);
                return false;
            }
            
 
        }
開發者ID:bkferareza,項目名稱:DarthMaul,代碼行數:49,代碼來源:TableauCommandExecutor.cs

示例11: CreateMergedPDF

        static void CreateMergedPDF(string targetPDF, string sourceDir)
        {
            using (FileStream stream = new FileStream(targetPDF, FileMode.Create))
            {
                Document pdfDoc = new Document(PageSize.A4);
                PdfCopy pdf = new PdfCopy(pdfDoc, stream);
                pdfDoc.Open();
                var files = Directory.GetFiles(sourceDir);

                int i = 1;
                foreach (string file in files)
                {
                    int cnt = file.Length;
                    pdf.AddDocument(new PdfReader(file));
                    i++;
                }

                if (pdfDoc != null)
                    pdfDoc.Close();

            }
        }
開發者ID:BTEEMRIYAS,項目名稱:TestProject,代碼行數:22,代碼來源:ReportController.cs

示例12: MergePdfBlobsToC

        public static Blob.Blob MergePdfBlobsToC(List<Blob.Blob> blobsParam, ref Dictionary<string, int> pages)
        {
            blobsParam = blobsParam
                .Where(el => el != null && el.Data != null)
                .ToList();

            //Dictionary of file names (for display purposes) and their page numbers
            //var pages = new Dictionary<string, int>();

            //PDFs start at page 1
            var lastPageNumber = 1;

            //Will hold the final merged PDF bytes
            byte[] mergedBytes;

            //Most everything else below is standard
            using (var ms = new MemoryStream())
            {
                using (var document = new Document())
                {
                    using (var writer = new PdfCopy(document, ms))
                    {
                        document.Open();

                        foreach (var blob in blobsParam)
                        {

                            //Add the current page at the previous page number
                            pages.Add(blob.Name, lastPageNumber);

                            using (var reader = new PdfReader(blob.Data))
                            {
                                writer.AddDocument(reader);

                                //Increment our current page index
                                lastPageNumber += reader.NumberOfPages;
                            }
                        }
                        document.Close();
                    }
                }
                mergedBytes = ms.ToArray();
            }

            //Will hold the final PDF
            //            byte[] finalBytes;
            //            using (var ms = new MemoryStream())
            //            {
            //                using (var reader = new PdfReader(mergedBytes))
            //                {
            //                    using (var stamper = new PdfStamper(reader, ms))
            //                    {
            //
            //                        //The page number to insert our TOC into
            //                        var tocPageNum = reader.NumberOfPages + 1;
            //
            //                        //Arbitrarily pick one page to use as the size of the PDF
            //                        //Additional logic could be added or this could just be set to something like PageSize.LETTER
            //                        var tocPageSize = reader.GetPageSize(1);
            //
            //                        //Arbitrary margin for the page
            //                        var tocMargin = 20;
            //
            //                        //Create our new page
            //                        stamper.InsertPage(tocPageNum, tocPageSize);
            //
            //                        //Create a ColumnText object so that we can use abstractions like Paragraph
            //                        var ct = new ColumnText(stamper.GetOverContent(tocPageNum));
            //
            //                        //Set the working area
            //                        ct.SetSimpleColumn(tocPageSize.GetLeft(tocMargin), tocPageSize.GetBottom(tocMargin),
            //                            tocPageSize.GetRight(tocMargin), tocPageSize.GetTop(tocMargin));
            //
            //                        //Loop through each page
            //                        foreach (var page in pages)
            //                        {
            //                            var link = new Chunk(page.Key);
            //                            var action = PdfAction.GotoLocalPage(page.Value, new PdfDestination(PdfDestination.FIT),
            //                                stamper.Writer);
            //                            link.SetAction(action);
            //                            ct.AddElement(new Paragraph(link));
            //                        }
            //
            //                        ct.Go();
            //                    }
            //                }
            //                finalBytes = ms.ToArray();
            //            }

            var toReturn = new Blob.Blob { Data = mergedBytes/*finalBytes*/ };
            return toReturn;
        }
開發者ID:avannini,項目名稱:uisp-mobile,代碼行數:92,代碼來源:AttachmentHelper.cs

示例13: Merge

        public static byte[] Merge(List<byte[]> filesContents)
        {
            using (var memoryStream = new MemoryStream())
            {
                var document = new Document();
                var pdf = new PdfCopy(document, memoryStream);
                PdfReader reader = null;

                try
                {
                    document.Open();

                    foreach (byte[] fileContent in filesContents)
                    {
                        reader = new PdfReader(fileContent);
                        pdf.AddDocument(reader);
                        reader.Close();
                    }
                }
                catch (Exception)
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
                finally
                {
                    if (document != null)
                    {
                        document.Close();
                    }
                }

                return memoryStream.ToArray();
            }
        }
開發者ID:fabiohvp,項目名稱:DocumentSigner,代碼行數:37,代碼來源:PdfHelper.cs

示例14: CreateMergedPDF

        /// <summary>
        /// 
        /// </summary>
        /// <param name="targetPDF"></param>
        /// <param name="selectedFiles"></param>
        public void CreateMergedPDF(string targetPDF, List<string> selectedFiles )
        {
            using (FileStream stream = new FileStream(targetPDF, FileMode.Create))
            {
                Document pdfDoc = new Document(PageSize.LETTER);
                PdfCopy pdf = new PdfCopy(pdfDoc, stream);
                pdfDoc.Open();

                logger.Debug("Merging files count: " + selectedFiles.Count);
                int i = 1;
                foreach (string file in selectedFiles)
                {
                    logger.Debug(i + ". Adding: " + file);
                    pdf. AddDocument(new PdfReader(file));
                    i++;
                }

                if (pdfDoc != null)
                    pdfDoc.Close();

                logger.Debug(" PDF merge complete.");
            }
        }
開發者ID:ibadyer,項目名稱:seed,代碼行數:28,代碼來源:BuildSubmittalPackage.cs

示例15: MergePDFs

        public bool MergePDFs(IEnumerable<string> fileNames, string targetPdf)
        {
            bool merged = true;

            preProcess();

            using (FileStream stream = new FileStream(targetPdf, FileMode.Create))
            {
                Document document = new Document();
                PdfCopy pdf = new PdfCopy(document, stream);
                PdfReader reader = null;
                try
                {
                    document.Open();
                    foreach (string file in fileNames)
                    {
                        reader = new PdfReader(file);
                        pdf.AddDocument(reader);

                        // 아래 함수 호출로 중간중간 Form의 이벤트를 처리해주어 
                        // "현재 Form이 "응답없음"에 빠지지 않게 함. 
                        Application.DoEvents();

                        mParent.Invoke(new MethodInvoker(delegate()
                            {
                                ///실행할 내용
                                mMergeProgressBar.Value++;
                                mMergeProgressBar.Text = mMergeProgressBar.Value.ToString();
                            }
                        ));

                        reader.Close();
                    }

#if false
                    //progressbar 닫기
                    mParent.Invoke(new MethodInvoker(
                        delegate()
                        {
                            ///실행할 내용
                            mMergeProgressBar.close();
                        }
                    )
               );

                    
#endif
                }
                catch (Exception)
                {
                    merged = false;
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
                finally
                {
                    if (document != null)
                    {
                        document.Close();
                    }
                }
            }
            return merged;
        }
開發者ID:somanet,項目名稱:iTextTools,代碼行數:66,代碼來源:Form1.cs


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