コード例 #1
0
        static void ExtractImages(Content content)
        {
            for (int i = 0; i < content.NumElements; i++)
            {
                Element e = content.GetElement(i);
                if (e is Datalogics.PDFL.Image)
                {
                    Console.WriteLine("Saving an image");
                    Datalogics.PDFL.Image img = (Datalogics.PDFL.Image)e;
                    Bitmap bitmap             = img.Bitmap;
                    bitmap.Save("ImageExtraction-extract-out" + (next) + ".bmp", ImageFormat.Bmp);

                    Datalogics.PDFL.Image newimg = img.ChangeResolution(500);
                    bitmap = newimg.Bitmap;
                    bitmap.Save("ImageExtraction-extracted-out" + (next) + ".bmp", ImageFormat.Bmp);
                    next++;

                    // The bitmap may be saved in any supported ImageFormat, e.g.:
                    //bitmap.Save("extract" + i + ".gif", ImageFormat.Gif);
                    //bitmap.Save("extract" + i + ".png", ImageFormat.Png);
                }
                else if (e is Container)
                {
                    ExtractImages((e as Container).Content);
                }
                else if (e is Group)
                {
                    ExtractImages((e as Group).Content);
                }
                else if (e is Form)
                {
                    ExtractImages((e as Form).Content);
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("WriteNChannelTiff Sample:");

            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sInput  = "../../Resources/Sample_Input/sample.pdf";
                String sOutput = "../WriteNChannelTiff-out.tif";

                if (args.Length > 0)
                {
                    sInput = args[0];
                }

                if (args.Length > 1)
                {
                    sOutput = args[1];
                }

                Console.WriteLine("Input file: " + sInput + " writing to " + sOutput);

                Document doc = new Document(sInput);
                Page     pg  = doc.GetPage(0);

                // Get all inks that are present on the page
                List <Ink> inks = (List <Ink>)pg.ListInks();
                List <SeparationColorSpace> colorants = new List <SeparationColorSpace>();

                // Here we decide, which inks should be drawn
                foreach (Ink theInk in inks)
                {
                    // note: if the Ink can't be found in page's resources,
                    // default tintTransform and alternate will be used
                    colorants.Add(new SeparationColorSpace(pg, theInk));
                }

                PageImageParams pip = new PageImageParams();
                pip.HorizontalResolution = 300;
                pip.VerticalResolution   = 300;

                Datalogics.PDFL.Image images = pg.GetImage(pg.CropBox, pip, colorants);
                // Save images as multi-channeled tiff.
                images.Save(sOutput, ImageType.TIFF);
            }
        }
コード例 #3
0
        static void ResampleImages(Content content)
        {
            int i = 0;

            while (i < content.NumElements)
            {
                Element e = content.GetElement(i);
                Console.WriteLine(i + " / " + content.NumElements + " = " + e.GetType().ToString());
                if (e is Datalogics.PDFL.Image)
                {
                    Datalogics.PDFL.Image img = (Datalogics.PDFL.Image)e;
                    try
                    {
                        Datalogics.PDFL.Image newimg = img.ChangeResolution(400);
                        Console.WriteLine("Replacing an image...");
                        content.AddElement((Element)newimg, i);
                        content.RemoveElement(i);
                        Console.WriteLine("Replaced.");
                        numreplaced++;
                    }
                    catch (ApplicationException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (e is Container)
                {
                    Console.WriteLine("Recursing through a Container");
                    ResampleImages((e as Container).Content);
                }
                else if (e is Group)
                {
                    Console.WriteLine("Recursing through a Group");
                    ResampleImages((e as Group).Content);
                }
                else if (e is Form)
                {
                    Console.WriteLine("Recursing through a Form");
                    Content formcontent = (e as Form).Content;
                    ResampleImages(formcontent);
                    (e as Form).Content = formcontent;
                }
                i++;
            }
        }
コード例 #4
0
        public static void CreatePageImageBasedOnPhysicalSize(Page pg, string filename, ImageType imgtype, ColorSpace cspace)
        {
            // Get the dimensions, in pixels, of an image that is
            // half the physical size of the page at a resolution of 96 DPI.
            // The dimensions will be stored in the PixelWidth and
            // PixelHeight fields of the PageImageParams object.
            double          scalefactor = 0.5;
            double          resolution  = 96.0;
            PageImageParams pip         = ScalePage(pg, scalefactor, resolution);

            pip.ImageColorSpace = cspace;

            // Create the image and save it to a file.
            // We want to create an image of the entire page, so we'll use the
            // page's CropBox as the exportRect.
            Datalogics.PDFL.Image img = pg.GetImage(pg.CropBox, pip);
            img.Save(filename, imgtype);
            Console.WriteLine("Created " + filename + "...");
        }
コード例 #5
0
        public void Export_Image(Content content, ColorSpace csp, Page pg, int pNum)
        {
            ImageSaveParams isp;

            try
            {
                isp             = new ImageSaveParams();
                isp.Compression = CompressionCode.LZW;

                PageImageParams pip = new PageImageParams();
                pip.ImageColorSpace = csp;

                Datalogics.PDFL.Image outImage = pg.GetImage(pg.CropBox, pip);

                String filenamevar = "";

                pip.RenderIntent = RenderIntent.Saturation;
                outImage         = pg.GetImage(pg.CropBox, pip);
                filenamevar      = "ImageEmbedICCProfile-out_sat" + pNum + ".tif";
                outImage.Save(filenamevar, exporttype, isp);

                pip.RenderIntent = RenderIntent.AbsColorimetric;
                outImage         = pg.GetImage(pg.CropBox, pip);
                filenamevar      = "ImageEmbedICCProfile-out_abs" + pNum + ".tif";
                outImage.Save(filenamevar, exporttype, isp);

                pip.RenderIntent = RenderIntent.Perceptual;
                outImage         = pg.GetImage(pg.CropBox, pip);
                filenamevar      = "ImageEmbedICCProfile-out_per" + pNum + ".tif";
                outImage.Save(filenamevar, exporttype, isp);

                pip.RenderIntent = RenderIntent.RelColorimetric;
                outImage         = pg.GetImage(pg.CropBox, pip);
                filenamevar      = "ImageEmbedICCProfile-out_rel" + pNum + ".tif";
                outImage.Save(filenamevar, exporttype, isp);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Cannot write file: " + ex.Message);
            }
        }
コード例 #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("RasterizePage Sample:");

            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String sInput  = Library.ResourceDirectory + "Sample_Input/ducky.pdf";
                String sOutput = "../RasterizePage.pdf";

                if (args.Length > 0)
                {
                    sInput = args[0];
                }

                if (args.Length > 1)
                {
                    sOutput = args[1];
                }

                Console.WriteLine("Using input file " + sInput + " writing to output with prefix " + sOutput);

                Document doc = new Document(sInput);
                Page     pg  = doc.GetPage(0);

                /////////////////////////////////////////////////////////
                //
                //  First, we'll make an image that is exactly 400 pixels
                //  wide at a resolution of 300 DPI.
                //
                ////////////////////////////////////////////////////////

                // Create a PageImageParams with the default settings.
                PageImageParams pip = new PageImageParams();
                pip.PageDrawFlags = DrawFlags.UseAnnotFaces;

                // Set the PixelWidth to be exactly 400 pixels.
                // We don't need to set the PixelHeight, as the Library will calculate
                // this for us automatically based on the PixelWidth and resolution.
                //
                // If you'd like a specific height, you can specify that too.
                // Be aware that the image may end up looking warped if the aspect ratio
                // of the specified PixelWidth and PixelHeight don't match the
                // aspect ratio of the original.
                pip.PixelWidth = 400;

                // Since the default resolution is 300 DPI, we don't need to explicitly
                // set the HorizontalResolution and VerticalResolution in this case.
                //
                // Again, we'll create an image of the entire page using the page's
                // CropBox as the exportRect.  The default ColorSpace is DeviceRGB,
                // so the image will be DeviceRGB.
                Datalogics.PDFL.Image inputImage = pg.GetImage(pg.CropBox, pip);
                inputImage.Save(sOutput + "-400pixel-width.jpg", ImageType.JPEG);
                Console.WriteLine("Created " + sOutput + "-400pixel-width.jpg...");

                /////////////////////////////////////////////////////////
                //
                //  Next, we'll make a grayscale image that is half the
                //  physical size of the page at 96 DPI.
                //
                ////////////////////////////////////////////////////////

                CreatePageImageBasedOnPhysicalSize(pg, sOutput + "-grayscale-halfsize.jpg", ImageType.JPEG, ColorSpace.DeviceGray);


                /////////////////////////////////////////////////////////
                //
                //  Next, we'll make an image that contains just the
                //  top half of the page at a resolution of 300 DPI.
                //
                //  We'll also use GetBitmap intead of GetImage.  If the
                //  final result is to be a System.Drawing.Bitmap, use
                //  GetBitmap instead of GetImage.  GetBitmap is faster
                //  because it draws directly into a new System.Drawing.Bitmap
                //  object and does not incur the time and memory overhead
                //  of creating a PDF Image object.
                //
                ////////////////////////////////////////////////////////

                System.Drawing.Bitmap halfImage = CreateBitmapWithTopHalfOfPage(pg, sOutput + "-tophalf.jpg",
                                                                                System.Drawing.Imaging.ImageFormat.Jpeg, ColorSpace.DeviceRGB);
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("ImageFromStream Sample:");

            using (Library lib = new Library())
            {
                Console.WriteLine("Initialized the library.");

                String bitmapInput = Library.ResourceDirectory + "Sample_Input/Datalogics.bmp";
                String jpegInput   = Library.ResourceDirectory + "Sample_Input/ducky.jpg";
                String docOutput   = "../ImageFromStream-out2.pdf";

                if (args.Length > 0)
                {
                    bitmapInput = args[0];
                }

                if (args.Length > 1)
                {
                    jpegInput = args[1];
                }

                if (args.Length > 2)
                {
                    docOutput = args[2];
                }

                Console.WriteLine("using bitmap input " + bitmapInput + " and jpeg input " + jpegInput + ". Writing to output " + docOutput);

                // Create a .NET MemoryStream object.
                // A MemoryStream is used here for demonstration only, but the technique
                // works just as well for other streams which support seeking.
                System.IO.MemoryStream BitmapStream = new System.IO.MemoryStream();

                // Load a bitmap image into the MemoryStream.
                System.Drawing.Bitmap BitmapImage = new System.Drawing.Bitmap(bitmapInput);
                BitmapImage.Save(BitmapStream, System.Drawing.Imaging.ImageFormat.Bmp);

                // Reset the MemoryStream's seek position before handing it to the DLE API,
                // which expects the seek position to be at the beginning of the stream.
                BitmapStream.Seek(0, System.IO.SeekOrigin.Begin);

                // Create the DLE Image object.
                Datalogics.PDFL.Image DLEBitmapImage = new Datalogics.PDFL.Image(BitmapStream);

                // Save the image to a PNG file.
                DLEBitmapImage.Save("ImageFromStream-out.png", ImageType.PNG);

                // The following demonstrates reading an image from a Stream and placing it into a document.
                // First, create a new Document and add a Page to it.
                Document doc = new Document();
                doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 612, 792));

                // Create a new MemoryStream for a new image file.
                System.IO.MemoryStream JpegStream = new System.IO.MemoryStream();

                // Load a JPEG image into the MemoryStream.
                System.Drawing.Image JpegImage = System.Drawing.Image.FromFile(jpegInput);
                JpegImage.Save(JpegStream, System.Drawing.Imaging.ImageFormat.Jpeg);

                // An alternative method for resetting the MemoryStream's seek position.
                JpegStream.Position = 0;

                // Create the DLE Image object and put it in the Document.
                // Since the image will be placed in a Document, use the constructor with the optional
                // Document parameter to optimize data usage for this image within the Document.
                Datalogics.PDFL.Image DLEJpegImage = new Datalogics.PDFL.Image(JpegStream, doc);
                Page pg = doc.GetPage(0);
                pg.Content.AddElement(DLEJpegImage);
                pg.UpdateContent();
                doc.Save(SaveFlags.Full, docOutput);
            }
        }