コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("FlattenTransparency sample:");

            using (Library lib = new Library())
            {
                String sInput1  = "../../Resources/Sample_Input/trans_1page.pdf";
                String sOutput1 = "../FlattenTransparency-out1.pdf";
                String sInput2  = "../../Resources/Sample_Input/trans_multipage.pdf";
                String sOutput2 = "../FlattenTransparency-out2.pdf";

                if (args.Length > 0)
                {
                    sInput1 = args[0];
                }
                if (args.Length > 1)
                {
                    sInput2 = args[1];
                }
                if (args.Length > 2)
                {
                    sOutput1 = args[2];
                }
                if (args.Length > 3)
                {
                    sOutput2 = args[3];
                }

                // Open a document with a single page.
                Document doc1 = new Document(sInput1);

                // Verify that the page has transparency.  The parameter indicates
                // whether to include the appearances of annotations or not when
                // checking for transparency.
                Page pg1           = doc1.GetPage(0);
                bool isTransparent = pg1.HasTransparency(true);

                // If there is transparency, flatten the document.
                if (isTransparent)
                {
                    // Flattening the document will check each page for transparency.
                    // If a page has transparency, DLE will create a new, flattened
                    // version of the page and replace the original page with the
                    // new one.  Because of this, make sure to dispose of outstanding Page objects
                    // that refer to pages in the Document before calling flattenTransparency.
                    pg1.Dispose();

                    doc1.FlattenTransparency();
                    Console.WriteLine("Flattened single page document " + sInput1 + " as " + sOutput1 + ".");
                    doc1.Save(SaveFlags.Full, sOutput1);
                }

                // Open a document with multiple pages.
                Document doc2 = new Document(sInput2);

                // Iterate over the pages of the document and find the first page that has
                // transparency.
                isTransparent = false;
                int totalPages  = doc2.NumPages;
                int pageCounter = 0;
                while (!isTransparent && pageCounter <= totalPages)
                {
                    Page pg = doc2.GetPage(pageCounter);
                    if (pg.HasTransparency(true))
                    {
                        isTransparent = true;
                        // Explicitly delete the page here, to ensure the reference is gone before we
                        // attempt to flatten the document.
                        pg.Dispose();
                        break;
                    }
                    pageCounter++;
                }

                if (isTransparent)
                {
                    // Set up some parameters for the flattening.
                    FlattenTransparencyParams ftParams = new FlattenTransparencyParams();

                    // The Quality setting indicates the percentage (0%-100%) of vector information
                    // that is preserved.  Lower values result in higher rasterization of vectors.
                    ftParams.Quality = 50;

                    // Flatten transparency in the document, starting from the first page
                    // that has transparency.
                    doc2.FlattenTransparency(ftParams, pageCounter, Document.LastPage);
                    Console.WriteLine("Flattened a multi-page document " + sInput2 + " as " + sOutput2 + ".");
                    doc2.Save(SaveFlags.Full, sOutput2);
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("ConvertTextToOutlines sample:");

            using (Library lib = new Library())
            {
                String sInput1  = Library.ResourceDirectory + "Sample_Input/TextSearch.pdf";
                String sOutput1 = "../TextSearch-converted.pdf";

                if (args.Length > 0)
                {
                    sInput1 = args[0];
                }
                if (args.Length > 1)
                {
                    sOutput1 = args[1];
                }

                // Open a document with multiple pages.
                Document doc = new Document(sInput1);

                // Iterate over the pages of the document and add a translucent element to the pages
                int totalPages  = doc.NumPages;
                int pageCounter = 0;

                while (pageCounter < totalPages)
                {
                    Page pg = doc.GetPage(pageCounter);

                    Path         tinyLine = new Path();
                    GraphicState gs       = tinyLine.GraphicState;

                    gs.FillColor     = new Color(1.0, 1.0, 1.0);  // White
                    gs.StrokeColor   = new Color(1.0, 1.0, 1.0);  // white
                    tinyLine.PaintOp = PathPaintOpFlags.Stroke;;  // PathPaintOpFlags.EoFill
                    gs.Width         = 1.0;

                    ExtendedGraphicState xgs = new ExtendedGraphicState();
                    xgs.BlendMode                   = BlendMode.Normal;
                    xgs.OpacityForStroking          = 0.5;
                    xgs.OpacityForOtherThanStroking = 0.5;
                    gs.ExtendedGraphicState         = xgs;
                    tinyLine.GraphicState           = gs;

                    Point Origin = new  Point(0.0, 0.0);
                    Point Point1 = new Point(1.0, 1.0); // line that goes from 0,0 to 1,1
                    tinyLine.MoveTo(Origin);
                    tinyLine.AddLine(Point1);
                    tinyLine.ClosePath();
                    pg.Content.AddElement(tinyLine);   // Add the new element to the Content of the page.
                    pg.UpdateContent();                // Update the PDF page with the changed content

                    pg.Dispose();
                    pageCounter++;
                }

                // Set up some parameters for the flattening.
                FlattenTransparencyParams ftParams = new FlattenTransparencyParams();

                // The Quality setting indicates the percentage (0%-100%) of vector information
                // that is preserved.  Lower values result in higher rasterization of vectors.
                ftParams.Quality         = 100;
                ftParams.UseTextOutlines = true;


                doc.FlattenTransparency(ftParams, 0, Document.LastPage);
                Console.WriteLine("Flattened a multi-page document " + sInput1 + " as " + sOutput1 + ".");
                doc.Save(SaveFlags.Full, sOutput1);
            }
        }