• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# pdf.PdfCopy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中iTextSharp.text.pdf.PdfCopy的典型用法代码示例。如果您正苦于以下问题:C# PdfCopy类的具体用法?C# PdfCopy怎么用?C# PdfCopy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PdfCopy类属于iTextSharp.text.pdf命名空间,在下文中一共展示了PdfCopy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Collate

        public static bool Collate(string frontSide, string backSide, string saveAs, bool backSideIsInReverseOrder = true)
        {
            try
            {
                bool backSideIsAscending = !backSideIsInReverseOrder;

                using (FileStream stream = new FileStream(saveAs, FileMode.Create))
                using (Document doc = new Document())
                using (PdfCopy pdf = new PdfCopy(doc, stream))
                {
                    doc.Open();

                    int b = 0;

                    using (PdfReader front = new PdfReader(frontSide))
                    {
                        using (PdfReader back = new PdfReader(backSide))
                        {
                            for (int p = 1; p <= front.NumberOfPages; p++)
                            {
                                pdf.AddPage(pdf.GetImportedPage(front, p));

                                pdf.FreeReader(front);

                                if (p <= back.NumberOfPages)
                                {
                                    if (backSideIsAscending)
                                        b = p;
                                    else
                                        b = back.NumberOfPages - p + 1;

                                    pdf.AddPage(pdf.GetImportedPage(back, b));

                                    pdf.FreeReader(back);
                                }
                            }
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);

                return false;
            }

            return true;
        }
开发者ID:rehanahmedhashmi,项目名称:dyslexic-code,代码行数:49,代码来源:Utilities.cs


示例2: TestExtraXObjects

        public void TestExtraXObjects()
        {
#if DRAWING
            PdfReader sourceR = new PdfReader(CreateImagePdf());
            try
            {
                int sourceXRefCount = sourceR.XrefSize;

                Document document = new Document();
                MemoryStream outStream = new MemoryStream();
                PdfCopy copy = new PdfCopy(document, outStream);
                document.Open();
                PdfImportedPage importedPage = copy.GetImportedPage(sourceR, 1);
                copy.AddPage(importedPage);
                document.Close();

                PdfReader targetR = new PdfReader(outStream.ToArray());
                int destinationXRefCount = targetR.XrefSize;

                //        TestResourceUtils.saveBytesToFile(createImagePdf(), new File("./source.pdf"));
                //        TestResourceUtils.saveBytesToFile(out.toByteArray(), new File("./result.pdf"));

                Assert.AreEqual(sourceXRefCount, destinationXRefCount);
            }
            finally
            {
                sourceR.Close();
            }
#endif// DRAWING
        }
开发者ID:smartleos,项目名称:itextsharp,代码行数:30,代码来源:PdfCopyTest.cs


示例3: Write

// ---------------------------------------------------------------------------
    public void Write(Stream stream) {
      MovieLinks1 ml = new MovieLinks1();
      MovieHistory mh = new MovieHistory();
      List<byte[]> pdf = new List<byte[]>() {
        Utility.PdfBytes(ml),
        Utility.PdfBytes(mh)
      };
      string[] names = {ml.ToString(), mh.ToString()};
      using (ZipFile zip = new ZipFile()) { 
        using (MemoryStream ms = new MemoryStream()) {
          // step 1
          using (Document document = new Document()) {
            // step 2
            using (PdfCopy copy = new PdfCopy(document, ms)) {
              // step 3
              document.Open();
              // step 4
              for (int i = 0; i < pdf.Count; ++i) {
                zip.AddEntry(Utility.ResultFileName(names[i] + ".pdf"), pdf[i]);
                PdfReader reader = new PdfReader(pdf[i]);
                // loop over the pages in that document
                int n = reader.NumberOfPages;
                for (int page = 0; page < n; ) {
                  copy.AddPage(copy.GetImportedPage(reader, ++page));
                }
              }
            }
          }
          zip.AddEntry(RESULT, ms.ToArray());
        }
        zip.Save(stream);    
      }
    }
开发者ID:,项目名称:,代码行数:34,代码来源:


示例4: ExtractPage

        /// <summary>
        /// Extract a single page from PDF file.
        /// </summary>
        /// <param name="sourceFile">The source file.</param>
        /// <param name="outputFile">The output file.</param>
        /// <param name="pageNumber">The specific page number.</param>
        public static void ExtractPage(string sourceFile, string outputFile, int pageNumber)
        {
            try
            {
                PdfReader reader = new PdfReader(sourceFile);
                if (pageNumber > reader.NumberOfPages)
                {
                    Console.WriteLine("This page number is out of reach.");
                    return;
                }

                Document document = new Document();
                PdfCopy pdfCopy = new PdfCopy(document, new FileStream(outputFile, FileMode.Create));
                document.Open();

                PdfImportedPage importedPage = pdfCopy.GetImportedPage(reader, pageNumber);
                pdfCopy.AddPage(importedPage);

                document.Close();
                reader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:cserspring,项目名称:pdf_split_merge,代码行数:32,代码来源:PdfUtilities.cs


示例5: ExtractPage

        public void ExtractPage(string sourcePdfPath, string outputPdfPath,
            int pageNumber, string password = "")
        {
            PdfReader reader = null;
            Document document = null;
            PdfCopy pdfCopyProvider = null;
            PdfImportedPage importedPage = null;

            try
            {
                // Intialize a new PdfReader instance with the contents of the source Pdf file:
                reader = new PdfReader(sourcePdfPath, Encoding.UTF8.GetBytes(password));

                // Capture the correct size and orientation for the page:
                document = new Document(reader.GetPageSizeWithRotation(pageNumber));

                // Initialize an instance of the PdfCopyClass with the source
                // document and an output file stream:
                pdfCopyProvider = new PdfCopy(document,
                    new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));

                document.Open();

                // Extract the desired page number:
                importedPage = pdfCopyProvider.GetImportedPage(reader, pageNumber);
                pdfCopyProvider.AddPage(importedPage);
                document.Close();
                reader.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:somanet,项目名称:iTextTools,代码行数:34,代码来源:PdfExtractor.cs


示例6: PdfConcatenate

 /**
  * Creates an instance of the concatenation class.
  * @param os    the Stream for the PDF document
  * @param smart do we want PdfCopy to detect redundant content?
  */
 public PdfConcatenate(Stream os, bool smart) {
     document = new Document();
     if (smart)
         copy = new PdfSmartCopy(document, os);
     else
         copy = new PdfCopy(document, os);   
 }
开发者ID:,项目名称:,代码行数:12,代码来源:


示例7: Combine

        public void Combine(string saveFileName, IEnumerable<string> files)
        {
            byte[] mergedPdf = null;
            using (MemoryStream ms = new MemoryStream())
            {
                using (Document document = new Document())
                {
                    using (PdfCopy copy = new PdfCopy(document, ms))
                    {
                        document.Open();

                        foreach (var item in files.OrderBy(x=> x))
                        {
                            PdfReader reader = new PdfReader(item);

                            // loop over the pages in that document
                            int n = reader.NumberOfPages;
                            for (int page = 0; page < n; )
                            {
                                copy.AddPage(copy.GetImportedPage(reader, ++page));
                            }

                            reader.Close();
                        }                        
                    }
                }
                mergedPdf = ms.ToArray();
            }

            File.WriteAllBytes(String.Concat(saveFileName, ".pdf"), mergedPdf);
        }
开发者ID:rickreis,项目名称:combine-files-pdf-win-forms,代码行数:31,代码来源:CombineFilesExportToPDF.cs


示例8: MergeFiles

        /// <summary>
        /// Merges multiple pdf files into 1 pdf file.
        /// </summary>
        /// <param name="FilesToMerge">Files to merger (Byte array for each file)</param>
        /// <returns>1 file with all the files passed in</returns>
        public static byte[] MergeFiles(IEnumerable<byte[]> FilesToMerge)
        {
            //Declare the memory stream to use
            using (var MemoryStreamToWritePdfWith = new MemoryStream())
            {
                //declare the new document which we will merge all the files into
                using (var NewFileToMergeIntoWith = new Document())
                {
                    //holds the byte array which we will return
                    byte[] ByteArrayToReturn;

                    //declare the pdf copy to write the data with
                    using (var PdfCopyWriter = new PdfCopy(NewFileToMergeIntoWith, MemoryStreamToWritePdfWith))
                    {
                        //set the page size of the new file
                        //NewFileToMergeIntoWith.SetPageSize(PageSize.GetRectangle("Letter").Rotate().Rotate());

                        //go open the new file that we are writing into
                        NewFileToMergeIntoWith.Open();

                        //now loop through all the files we want to merge
                        foreach (var FileToMerge in FilesToMerge)
                        {
                            //declare the pdf reader so we can copy it
                            using (var PdfFileReader = new PdfReader(FileToMerge))
                            {
                                //figure out how many pages are in this pdf, so we can add each of the pdf's
                                int PdfFilePageCount = PdfFileReader.NumberOfPages;

                                // loop over document pages (start with page 1...not a 0 based index)
                                for (int i = 1; i <= PdfFilePageCount; i++)
                                {
                                    //set the file size for this page
                                    NewFileToMergeIntoWith.SetPageSize(PdfFileReader.GetPageSize(i));

                                    //add a new page for the next page
                                    NewFileToMergeIntoWith.NewPage();

                                    //now import the page
                                    PdfCopyWriter.AddPage(PdfCopyWriter.GetImportedPage(PdfFileReader, i));
                                }
                            }
                        }

                        //now close the new file which we merged everyting into
                        NewFileToMergeIntoWith.Close();

                        //grab the buffer and throw it into a byte array to return
                        ByteArrayToReturn = MemoryStreamToWritePdfWith.GetBuffer();

                        //flush out the memory stream
                        MemoryStreamToWritePdfWith.Flush();
                    }

                    //now return the byte array
                    return ByteArrayToReturn;
                }
            }
        }
开发者ID:dibiancoj,项目名称:ToracLibrary,代码行数:64,代码来源:PdfMerger.cs


示例9: InitializeDocument

 private void InitializeDocument(String name)
 {
     output = OUT + name + ".pdf";
     document = new Document();
     copy = new PdfCopy(document, new FileStream(output, FileMode.Create));
     copy.SetTagged();
     document.Open();
 }
开发者ID:,项目名称:,代码行数:8,代码来源:


示例10: Combiner

        public Combiner(string outputFilePath)
        {
            var outputStream = File.Create(outputFilePath);

            _document = new Document();
            _pdfCopy = new PdfCopy(_document, outputStream);
            _document.Open();
        }
开发者ID:schourode,项目名称:pdfbinder,代码行数:8,代码来源:Binder.cs


示例11: PdfStructTreeController

 protected internal PdfStructTreeController(PdfReader reader, PdfCopy writer){
     if (!writer.IsTagged())
         throw new BadPdfFormatException(MessageLocalization.GetComposedMessage("no.structtreeroot.found"));
     this.writer = writer;
     structureTreeRoot = writer.StructureTreeRoot;
     structureTreeRoot.Put(PdfName.PARENTTREE, new PdfDictionary(PdfName.STRUCTELEM));
     SetReader(reader);
 }
开发者ID:,项目名称:,代码行数:8,代码来源:


示例12: ManipulateWithCopy

 /**
  * Creates a new PDF based on the one in the reader
  * @param reader a reader with a PDF file
  * @throws IOException
  * @throws DocumentException
  */
 private void ManipulateWithCopy(PdfReader reader)
 {
     int n = reader.NumberOfPages;
     Document document = new Document();
     PdfCopy copy = new PdfCopy(document, new MemoryStream());
     document.Open();
     for (int i = 0; i < n; )
     {
         copy.AddPage(copy.GetImportedPage(reader, ++i));
     }
     document.Close();
 }
开发者ID:smartleos,项目名称:itextsharp,代码行数:18,代码来源:PdfReaderSelectPagesTest.cs


示例13: CreatePdf

// ---------------------------------------------------------------------------
    /**
     * Creates a PDF file with director names.
     * @param pdf the PDF file to be used as a reader
     */
    public byte[] CreatePdf(byte[] pdf) {
      byte[] tmpDoc = null;
      using ( MemoryStream ms = new MemoryStream() ) {
        using (Document tmp = new Document()) {
          PdfWriter writer = PdfWriter.GetInstance(tmp, ms);
          // step 3
          tmp.Open();
          // step 4
          var SQL = 
  @"SELECT name, given_name 
  FROM film_director 
  ORDER BY name, given_name";
        using (var c =  AdoDB.Provider.CreateConnection()) {
          c.ConnectionString = AdoDB.CS;
          using (DbCommand cmd = c.CreateCommand()) {
            cmd.CommandText = SQL;            
              c.Open();            
              using (var r = cmd.ExecuteReader()) {
                while ( r.Read() ) {
                  tmp.Add(CreateDirectorParagraph(writer, r));
                }
              }
            }
          }
        }
        tmpDoc = ms.ToArray();
      }

      jsContents = File.ReadAllText(
        Path.Combine(Utility.ResourceJavaScript, RESOURCE)
      );
      List<byte[]> readers = new List<byte[]>() {tmpDoc, pdf};
      using (MemoryStream ms = new MemoryStream()) {
        // step 1
        using (Document document = new Document()) {
          // step 2
          using (PdfCopy copy = new PdfCopy(document, ms)) {
            // step 3
            document.Open();
            // step 4
            copy.AddJavaScript(jsContents);
            for (int i = 0; i < readers.Count; ++i) {
              PdfReader reader = new PdfReader(readers[i]);
              int n = reader.NumberOfPages;
              for (int page = 0; page < n; ) {
                copy.AddPage(copy.GetImportedPage(reader, ++page));
              }
            }
          }
        } 
        return ms.ToArray();     
      }
    } 
开发者ID:,项目名称:,代码行数:58,代码来源:


示例14: ExtractPagesFromFile

        private IList<PdfImportedPage> ExtractPagesFromFile(string sourcePdfPath)
        {
            IList<PdfImportedPage> pages = new List<PdfImportedPage>();

            PdfReader reader = new PdfReader(sourcePdfPath);
            PdfCopy pdfCopyProvider = new PdfCopy(new Document(), new MemoryStream());
            for (int i = 0; i < reader.NumberOfPages; i++)
            {
                pages.Add(pdfCopyProvider.GetImportedPage(reader, i + 1));
            }
            return pages;
        }
开发者ID:proprietor,项目名称:PdfCreator,代码行数:12,代码来源:PdfCreator.cs


示例15: MergeFiles

        public static byte[] MergeFiles(List<byte[]> sourceFiles)
        {
            Document document = new Document();
            using (MemoryStream ms = new MemoryStream())
            {
                PdfCopy copy = new PdfCopy(document, ms);
                document.Open();
                int documentPageCounter = 0;

                // Iterate through all pdf documents
                for (int fileCounter = 0; fileCounter < sourceFiles.Count; fileCounter++)
                {
                    // Create pdf reader
                    PdfReader reader = new PdfReader(sourceFiles[fileCounter]);
                    int numberOfPages = reader.NumberOfPages;

                    // Iterate through all pages
                    for (int currentPageIndex = 1; currentPageIndex <= numberOfPages; currentPageIndex++)
                    {
                        PdfImportedPage importedPage = copy.GetImportedPage(reader, currentPageIndex);

                        //***************************************
                        // Uncomment and alter for watermarking.
                        //***************************************
                        //
                        //documentPageCounter++;
                        //PdfCopy.PageStamp pageStamp = copy.CreatePageStamp(importedPage);
                        //
                        //// Write header
                        //ColumnText.ShowTextAligned(pageStamp.GetOverContent(), Element.ALIGN_CENTER,
                        //    new Phrase("PDF Merged with me.AxeyWorks PDFMerge"), importedPage.Width / 2, importedPage.Height - 30,
                        //    importedPage.Width < importedPage.Height ? 0 : 1);
                        //
                        //// Write footer
                        //ColumnText.ShowTextAligned(pageStamp.GetOverContent(), Element.ALIGN_CENTER,
                        //    new Phrase($"Page {documentPageCounter}"), importedPage.Width / 2, 30,
                        //    importedPage.Width < importedPage.Height ? 0 : 1);
                        //
                        //pageStamp.AlterContents();

                        copy.AddPage(importedPage);
                    }

                    copy.FreeReader(reader);
                    reader.Close();
                }

                document.Close();
                return ms.GetBuffer();
            }
        }
开发者ID:joshaxey,项目名称:Simple-PDFMerge,代码行数:51,代码来源:Program.cs


示例16: ManipulateWithCopy

// ---------------------------------------------------------------------------
    /**
     * Creates a new PDF based on the one in the reader
     * @param reader a reader with a PDF file
     */
    private byte[] ManipulateWithCopy(PdfReader reader) {
      using (MemoryStream ms = new MemoryStream()) {
        int n = reader.NumberOfPages;
        using (Document document = new Document()) {
          using (PdfCopy copy = new PdfCopy(document, ms)) {
            document.Open();
            for (int i = 0; i < n;) {
              copy.AddPage(copy.GetImportedPage(reader, ++i));
            }
          }
        }
        return ms.ToArray();
      }
    }    
开发者ID:,项目名称:,代码行数:19,代码来源:


示例17: Create

        public void Create(Album album, string outputPdfPath)
        {
            Document document = new Document();

            PdfCopy pdfCopyProvider = new PdfCopy(document,
                new FileStream(outputPdfPath, FileMode.Create));

            document.Open();
            foreach (Page page in album.Pages)
            {
                AddTextForPage(pdfCopyProvider, page.Image, page.TextForPage);
                pdfCopyProvider.AddPage(page.Image);
            }
            document.Close();
        }
开发者ID:proprietor,项目名称:PdfCreator,代码行数:15,代码来源:PdfCreator.cs


示例18: AddDataSheets

// ---------------------------------------------------------------------------
    /**
     * Fills out a data sheet, flattens it, and adds it to a combined PDF.
     * @param copy the PdfCopy instance (can also be PdfSmartCopy)
     */
    public void AddDataSheets(PdfCopy copy) {
      IEnumerable<Movie> movies = PojoFactory.GetMovies();
      // Loop over all the movies and fill out the data sheet
      foreach (Movie movie in movies) {
        PdfReader reader = new PdfReader(DATASHEET_PATH);
        using (var ms = new MemoryStream()) {
          using (PdfStamper stamper = new PdfStamper(reader, ms)) {
            Fill(stamper.AcroFields, movie);
            stamper.FormFlattening = true;
          }
          reader = new PdfReader(ms.ToArray());
          copy.AddPage(copy.GetImportedPage(reader, 1));
        }
      }
    }    
开发者ID:,项目名称:,代码行数:20,代码来源:


示例19: AddTextForPage

        private void AddTextForPage(PdfCopy pdfCopyProvider, PdfImportedPage importedPage, TextForPage textForPage)
        {
            PdfCopy.PageStamp stamper = pdfCopyProvider.CreatePageStamp(importedPage);

            ColumnText.ShowTextAligned(stamper.GetOverContent(), Element.ALIGN_CENTER, new Phrase(textForPage.PageNubmer,
                new Font()), 820f, 15, 0);
            stamper.AlterContents();

            AddParagraph(stamper, textForPage.Header, importedPage.Width / 2,
                importedPage.Height - 30, Element.ALIGN_CENTER, 1);

            AddParagraph(stamper, textForPage.Footer, importedPage.Width / 2,
                30, Element.ALIGN_CENTER, 1);

            stamper.AlterContents();
        }
开发者ID:proprietor,项目名称:PdfCreator,代码行数:16,代码来源:PdfCreator.cs


示例20: Merge

        public static void Merge(string file, string OutFile, ref SetupStationaryFields.addresscollection aic)
        {
            using (FileStream stream = new FileStream(OutFile, FileMode.Create))
            {
                using (Document doc = new Document())
                {
                    using (PdfCopy pdf = new PdfCopy(doc, stream))
                    {
                        doc.Open();

                        PdfReader reader = null;
                        PdfImportedPage page = null;

                        //fixed typo
                        int ii = 0;
                        int count = 0;

                        foreach (SetupStationaryFields.addressitem ai in aic)
                        {

                            if ((!ai.ommitted))
                            {

                                reader = new PdfReader(file);
                                PdfReader.unethicalreading = true;
                                count = reader.NumberOfPages;
                                for (int i = 0; i <= reader.NumberOfPages - 1; i++)
                                {
                                    page = pdf.GetImportedPage(reader, i + 1);
                                    pdf.AddPage(page);
                                }

                                pdf.FreeReader(reader);
                                reader.Close();

                                ai.startpage = ((ii) * count) + 1;
                                ai.endpage = (ii * count) + count;
                                ii = ii + 1;

                            }
                        }
                    }
                }
                stream.Close();
            }
        }
开发者ID:FourThousandFour,项目名称:Click2MailTools,代码行数:46,代码来源:Utils.cs



注:本文中的iTextSharp.text.pdf.PdfCopy类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# pdf.PdfDestination类代码示例发布时间:2022-05-26
下一篇:
C# pdf.PdfContentByte类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap