예제 #1
0
        // For this sample to work, the following file
        // need to exist: unicode.pdf.
        // Compile the corresponding sample to get this file
        public static void SplitFile()
        {
            //PDF4NET v5: PDFFile.SplitFile("Sample_Unicode.pdf", "Sample_Unicode-page.pdf");
            FileStream stm  = File.OpenRead("..\\..\\..\\..\\..\\SupportFiles\\content.pdf");
            PDFFile    file = new PDFFile(stm);

            for (int i = 0; i < file.PageCount; i++)
            {
                PDFFixedDocument document = new PDFFixedDocument();
                document.Pages.Add(file.ExtractPage(i));
                document.Save(i + ".pdf");
            }
        }
예제 #2
0
        private static void SplitPagesNoUnusedResourcesRemoval()
        {
            using (FileStream fs = File.OpenRead("PDF4NET.Features.pdf"))
            {
                PDFFile sourceFile = new PDFFile(fs);

                for (int i = 0; i < sourceFile.PageCount; i++)
                {
                    PDFFixedDocument document = new PDFFixedDocument();
                    PDFPage          page     = sourceFile.ExtractPage(i);
                    document.Pages.Add(page);

                    document.Save($"UnusedResourcesKept.Page.{i}.pdf");
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            // The input file is split by extracting pages from source file and inserting them in new empty PDF documents.
            PDFFile file = new PDFFile(input);

            SampleOutputInfo[] output = new SampleOutputInfo[file.PageCount];

            for (int i = 0; i < file.PageCount; i++)
            {
                PDFFixedDocument document = new PDFFixedDocument();
                PDFPage          page     = file.ExtractPage(i);
                document.Pages.Add(page);

                output[i] = new SampleOutputInfo(document, string.Format("documentsplit.{0}.pdf", i + 1));
            }

            return(output);
        }
예제 #4
0
        private static void SplitPagesWithUnusedResourcesRemoval()
        {
            using (FileStream fs = File.OpenRead("PDF4NET.Features.pdf"))
            {
                PDFFile sourceFile = new PDFFile(fs);

                for (int i = 0; i < sourceFile.PageCount; i++)
                {
                    PDFFixedDocument document = new PDFFixedDocument();
                    PDFPage          page     = sourceFile.ExtractPage(i);

                    RemoveUnusedResourcesTransform transform       = new RemoveUnusedResourcesTransform();
                    PDFPageTransformer             pageTransformer = new PDFPageTransformer(page);
                    pageTransformer.ApplyTransform(transform);

                    document.Pages.Add(page);

                    document.Save($"UnusedResourcesRemoved.Page.{i}.pdf");
                }
            }
        }
예제 #5
0
        // For this sample to work, the following files
        // need to exist: unicode.pdf and multicolumntextandimages.pdf.
        // Compile the corresponding samples to get these files
        public static void MixFiles()
        {
            //PDF4NET v5: PDFFile unicodeFile = PDFFile.FromFile("Sample_Unicode.pdf");
            FileStream stm1  = File.OpenRead("..\\..\\..\\..\\..\\SupportFiles\\content.pdf");
            PDFFile    file1 = new PDFFile(stm1);
            //PDF4NET v5: PDFFile mctiFile = PDFFile.FromFile("Sample_MultiColumnTextAndImages.pdf");
            FileStream stm2  = File.OpenRead("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf");
            PDFFile    file2 = new PDFFile(stm2);
            //PDF4NET v5: PDFImportedPage ip = null;
            PDFPage ip = null;

            //PDF4NET v5: PDFDocument doc = new PDFDocument();
            PDFFixedDocument doc = new PDFFixedDocument();

            for (int i = 0; i < 4; i++)
            {
                // extract the page
                ip = file1.ExtractPage(i);

                // add the page to new document
                doc.Pages.Add(ip);

                // extract the page
                ip = file2.ExtractPage(i);

                // add the page to new document
                doc.Pages.Add(ip);
            }

            // save the mixed document
            doc.Save("Sample_Mix.pdf");

            //PDF4NET v5: unicodeFile.Close();
            stm1.Close();
            //PDF4NET v5: mctiFile.Close();
            stm2.Close();
        }