Пример #1
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            // Load the input file.
            PDFFixedDocument document = new PDFFixedDocument(input);

            PDFConvertToGrayTransform grayTransform   = new PDFConvertToGrayTransform();
            PDFPageTransformer        pageTransformer = new PDFPageTransformer(document.Pages[3]);

            pageTransformer.ApplyTransform(grayTransform);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "grayscaleconversion.pdf") };
            return(output);
        }
Пример #2
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream input)
        {
            // Load the input file.
            PDFFixedDocument document = new PDFFixedDocument(input);

            PDFReplaceImageTransform replaceImageTransform = new PDFReplaceImageTransform();

            replaceImageTransform.ReplaceImage += new EventHandler <PDFReplaceImageEventArgs>(HandleReplaceImage);
            PDFPageTransformer pageTransformer = new PDFPageTransformer(document.Pages[2]);

            pageTransformer.ApplyTransform(replaceImageTransform);
            replaceImageTransform.ReplaceImage -= new EventHandler <PDFReplaceImageEventArgs>(HandleReplaceImage);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "removereplaceimages.pdf") };
            return(output);
        }
Пример #3
0
        private void PerformSeparation(string outputPdfFile, bool keepSeparation)
        {
            FileStream       input    = File.OpenRead(pdfFile);
            PDFFixedDocument document = new PDFFixedDocument(input);

            input.Close();

            PDFPageTransformer          pageTransformer = new PDFPageTransformer(document.Pages[0]);
            PDFSeparateContentTransform sct             = new PDFSeparateContentTransform(separationName, keepSeparation);

            pageTransformer.ApplyTransform(sct);

            using (FileStream output = File.Create(outputPdfFile))
            {
                document.Save(output);
                output.Flush();
            }
        }
Пример #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");
                }
            }
        }