// ---------------------------------------------------------------------------     
		/**
		 * @see com.itextpdf.text.pdf.parser.RenderListener#renderImage(
		 *     com.itextpdf.text.pdf.parser.ImageRenderInfo)
		 */
        public void RenderImage(ImageRenderInfo renderInfo)
        {
            PdfImageObject image = renderInfo.GetImage();
            //PdfName filter = (PdfName)image.Get(PdfName.FILTER);

            string imageName = string.Format("{0:0000}_{1:0000}.{2}", PageIndex, ImagesList.Count, image.GetImageBytesType().FileExtension);
            var pageImageIndex = new PageImageIndex
            {
                ImageName = imageName,
                ImageIndex = ImagesList.Count,
                PageIndex = PageIndex
            };
            var imageType = image.GetImageBytesType();
            //if (imageType != PdfImageObject.ImageBytesType.JBIG2)
            //{
            //var bmp = image.GetDrawingImage();                

            // Write image to file
            string pathToSave = string.Format(@"{0}\{1}", OutputPath, imageName);
            //bmp.Save(string.Format(pathToSave));
            // bmp.Dispose();

            // Sometime gdi+ error happen. We must write byte directly to disk
            if (!Directory.Exists(OutputPath))
                Directory.CreateDirectory(OutputPath);
            var bytes = image.GetImageAsBytes();
            File.WriteAllBytes(pathToSave, bytes);

            ImagesList.Add(pageImageIndex, null);
            //}
        }
        public virtual void RenderImage(ImageRenderInfo renderInfo) {
            IList<Rectangle> areasToBeCleaned = GetImageAreasToBeCleaned(renderInfo);

            if (areasToBeCleaned == null || newClippingPath.IsEmpty()) {
                chunks.Add(new PdfCleanUpContentChunk.Image(false, null));
            } else {
                PdfImageObject pdfImage = renderInfo.GetImage();
                byte[] imageBytes = ProcessImage(pdfImage.GetImageAsBytes(), areasToBeCleaned);

                if (renderInfo.GetRef() == null && pdfImage != null) { // true => inline image
                    PdfDictionary dict = pdfImage.GetDictionary();
                    PdfObject imageMask = dict.Get(PdfName.IMAGEMASK);
                    Image image = Image.GetInstance(imageBytes);

                    if (imageMask == null) {
                        imageMask = dict.Get(PdfName.IM);
                    }

                    if (imageMask != null && imageMask.Equals(PdfBoolean.PDFTRUE)) {
                        image.MakeMask();
                    }

                    PdfContentByte canvas = Context.Canvas;
                    canvas.AddImage(image, 1, 0, 0, 1, 0, 0, true);
                } else if (pdfImage != null && imageBytes != pdfImage.GetImageAsBytes()) {
                    chunks.Add(new PdfCleanUpContentChunk.Image(true, imageBytes));
                }
            }
        }
        public void RenderImage(ImageRenderInfo renderInfo)
        {
            PdfImageObject imagen = renderInfo.GetImage();
            PdfName filtro = (PdfName)imagen.Get(PdfName.FILTER);

            if (filtro != null)
            {
                System.Drawing.Image drawingImage = imagen.GetDrawingImage();
                string extension = ".";

                if (filtro == PdfName.DCTDECODE)
                {
                    extension += PdfImageObject.ImageBytesType.JPG.FileExtension;
                }
                else if (filtro == PdfName.JPXDECODE)
                {
                    extension += PdfImageObject.ImageBytesType.JP2.FileExtension;
                }
                else if (filtro == PdfName.FLATEDECODE)
                {
                    extension += PdfImageObject.ImageBytesType.PNG.FileExtension;
                }
                else if (filtro == PdfName.LZWDECODE)
                {
                    extension += PdfImageObject.ImageBytesType.CCITT.FileExtension;
                }

                this.Imagenes.Add(drawingImage, extension);
            }
        }
Beispiel #4
0
 public void RenderImage(ImageRenderInfo renderInfo)
 {
     Image imageRange = null;
     iTextSharp.text.pdf.parser.PdfImageObject image = renderInfo.GetImage();
     if (image == null) return;
     try
     {
         imageRange = Image.FromStream(new MemoryStream(image.GetImageAsBytes()));
     }
     catch (Exception) {}
     if (imageRange != null)
     {
         if (textRange.Trim() != "")
             AddAllTextPars();
         ExtractedParagraphs.Add(new BookParagraph(BookParagraph.TYPE_PICTURE, imageRange, index, ++index));
     }
 }
        /**
         * Calculates intersection of the image and the render filter region in the coordinate system relative to the image.
         * 
         * @return <code>null</code> if the image is not allowed, {@link java.util.List} of 
         *         {@link com.itextpdf.text.Rectangle} objects otherwise.
         */
        protected internal virtual IList<Rectangle> GetCoveredAreas(ImageRenderInfo renderInfo) {
            Rectangle imageRect = CalcImageRect(renderInfo);
            IList<Rectangle> coveredAreas = new List<Rectangle>();

            if (imageRect == null) {
                return null;
            }

            foreach (Rectangle rectangle in rectangles) {
                Rectangle intersectionRect = Intersection(imageRect, rectangle);

                if (intersectionRect != null) {
                    // True if the image is completely covered
                    if (imageRect.Equals(intersectionRect)) {
                        return null;
                    }
                    
                    coveredAreas.Add(TransformIntersection(renderInfo.GetImageCTM(), intersectionRect));
                }
            }

            return coveredAreas;
        }
Beispiel #6
0
// ---------------------------------------------------------------------------     
    /**
     * @see com.itextpdf.text.pdf.parser.RenderListener#renderImage(
     *     com.itextpdf.text.pdf.parser.ImageRenderInfo)
     */
    public void RenderImage(ImageRenderInfo renderInfo) {
      try {
        PdfImageObject image = renderInfo.GetImage();
        if (image == null 
/*
 * do not attempt to parse => jbig2 decoder not fully implemented.
 * THE JAVA EXAMPLE INCORRECTLY CREATES A CORRUPT JBIG2 IMAGE
 * BECAUSE THERE IS NO EXPLICIT CHECK. I POSTED TWICE TO THE MAILING
 * LIST, SINCE VERSION 5.1.3 BUT THE ERROR HAS NOT BEEN CORRECTED.
 */
          || image.GetImageBytesType() == PdfImageObject.ImageBytesType.JBIG2
        ) 
        return;
        
        _imageNames.Add(string.Format(
          "Image{0}.{1}", 
          renderInfo.GetRef().Number, image.GetFileType()
        ) );
        _myImages.Add(image.GetImageAsBytes());
      }
      catch {
// pass through any other unsupported image types
      }
    }
Beispiel #7
0
 /**
  * Create an ImageRenderInfo object based on inline image data.  This is nowhere near completely thought through
  * and really just acts as a placeholder.
  * @param ctm the coordinate transformation matrix at the time the image is rendered
  * @param imageObject the image object representing the inline image
  * @return the ImageRenderInfo representing the rendered embedded image
  * @since 5.0.1
  */
 protected internal static ImageRenderInfo CreatedForEmbeddedImage(Matrix ctm, PdfImageObject imageObject){
     ImageRenderInfo renderInfo = new ImageRenderInfo(ctm, null);
     renderInfo.imageObject = imageObject;
     return renderInfo;
 }
Beispiel #8
0
 /**
  *
  * @param renderInfo
  * @return true is the image render operation should be performed
  */
 public virtual bool AllowImage(ImageRenderInfo renderInfo)
 {
     return(true);
 }
Beispiel #9
0
 /**
  * @see com.itextpdf.text.pdf.parser.RenderListener#renderImage(com.itextpdf.text.pdf.parser.ImageRenderInfo)
  */
 virtual public void RenderImage(ImageRenderInfo renderInfo)
 {
     // do nothing
 }
Beispiel #10
0
        /**
         * Create an ImageRenderInfo object based on inline image data.  This is nowhere near completely thought through
         * and really just acts as a placeholder.
         * @param ctm the coordinate transformation matrix at the time the image is rendered
         * @param imageObject the image object representing the inline image
         * @return the ImageRenderInfo representing the rendered embedded image
         * @since 5.0.1
         */
        protected internal static ImageRenderInfo CreateForEmbeddedImage(Matrix ctm, InlineImageInfo inlineImageInfo, PdfDictionary colorSpaceDictionary)
        {
            ImageRenderInfo renderInfo = new ImageRenderInfo(ctm, inlineImageInfo, colorSpaceDictionary);

            return(renderInfo);
        }
Beispiel #11
0
 public void RenderImage(ImageRenderInfo renderInfo) {
 }
Beispiel #12
0
 /**
  * 
  * @param renderInfo
  * @return true is the image render operation should be performed
  */
 public virtual bool AllowImage(ImageRenderInfo renderInfo){
     return true;
 }
Beispiel #13
0
 /// <summary>
 /// Converts the Matrix containing the coordinates of an image as stored
 /// in an ImageRenderInfo object into a Rectangle.
 /// </summary>
 /// <param name="imageRenderInfo">Object that contains info about an image</param>
 /// <returns>coordinates in the form of a Rectangle object</returns>
 private static Rectangle GetRectangle(ImageRenderInfo imageRenderInfo)
 {
     Matrix ctm = imageRenderInfo.GetImageCTM();
     return new Rectangle(ctm[6], ctm[7], ctm[6] + ctm[0], ctm[7] + ctm[4]);
 }
 /**
  * no-op method - this renderer isn't interested in image events
  * @see com.itextpdf.text.pdf.parser.RenderListener#renderImage(com.itextpdf.text.pdf.parser.ImageRenderInfo)
  * @since 5.0.1
  */
 public virtual void RenderImage(ImageRenderInfo renderInfo)
 {
     // do nothing - we aren't tracking images in this renderer
 }
Beispiel #15
0
 /**
  * Create an ImageRenderInfo object based on inline image data.  This is nowhere near completely thought through
  * and really just acts as a placeholder.
  * @param ctm the coordinate transformation matrix at the time the image is rendered
  * @param imageObject the image object representing the inline image
  * @return the ImageRenderInfo representing the rendered embedded image
  * @since 5.0.1
  */
 protected internal static ImageRenderInfo CreateForEmbeddedImage(Matrix ctm, InlineImageInfo inlineImageInfo, PdfDictionary colorSpaceDictionary) {
     ImageRenderInfo renderInfo = new ImageRenderInfo(ctm, inlineImageInfo, colorSpaceDictionary);
     return renderInfo;
 }
 /**
  * @return null if the image is not allowed (either it is fully covered or ctm == null).
  * List of covered image areas otherwise.
  */
 private IList<Rectangle> GetImageAreasToBeCleaned(ImageRenderInfo renderInfo) {
     return filter.GetCoveredAreas(renderInfo);
 }
Beispiel #17
0
 //-------------------------------------------------------------------------
 private Bitmap RenderImage(ImageRenderInfo renderInfo)
 {
     PdfImageObject image = renderInfo.GetImage();
     using (System.Drawing.Image dotnetImg = image.GetDrawingImage())
     {
         if (dotnetImg != null)
         {
             using (MemoryStream ms = new MemoryStream())
             {
                 dotnetImg.Save(ms, ImageFormat.Tiff);
                 Bitmap d = new Bitmap(dotnetImg);
                 return d;//d.Save(imgPath);
             }
         }
     }
     return null;
 }
Beispiel #18
0
        public void RenderImage(ImageRenderInfo renderInfo)
        {
            PdfImageObject image = renderInfo.GetImage();
            PdfName filter = (PdfName)image.Get(PdfName.FILTER);

            //int width = Convert.ToInt32(image.Get(PdfName.WIDTH).ToString());
            //int bitsPerComponent = Convert.ToInt32(image.Get(PdfName.BITSPERCOMPONENT).ToString());
            //string subtype = image.Get(PdfName.SUBTYPE).ToString();
            //int height = Convert.ToInt32(image.Get(PdfName.HEIGHT).ToString());
            //int length = Convert.ToInt32(image.Get(PdfName.LENGTH).ToString());
            //string colorSpace = image.Get(PdfName.COLORSPACE).ToString();

            /* It appears to be safe to assume that when filter == null, PdfImageObject 
             * does not know how to decode the image to a System.Drawing.Image.
             * 
             * Uncomment the code above to verify, but when I've seen this happen, 
             * width, height and bits per component all equal zero as well. */
            if (filter != null)
            {
                System.Drawing.Image drawingImage = image.GetDrawingImage();

                string extension = ".";

                if (filter == PdfName.DCTDECODE)
                {
                    extension += PdfImageObject.ImageBytesType.JPG.FileExtension;
                }
                else if (filter == PdfName.JPXDECODE)
                {
                    extension += PdfImageObject.ImageBytesType.JP2.FileExtension;
                }
                else if (filter == PdfName.FLATEDECODE)
                {
                    extension += PdfImageObject.ImageBytesType.PNG.FileExtension;
                }
                else if (filter == PdfName.LZWDECODE)
                {
                    extension += PdfImageObject.ImageBytesType.CCITT.FileExtension;
                }

                /* Rather than struggle with the image stream and try to figure out how to handle 
                 * BitMapData scan lines in various formats (like virtually every sample I've found 
                 * online), use the PdfImageObject.GetDrawingImage() method, which does the work for us. */
                this.Images.Add(drawingImage, extension);
            }
        }
Beispiel #19
0
            public void HandleXObject(PdfContentStreamProcessor processor, PdfStream xobjectStream, PdfIndirectReference refi)
            {
                ImageRenderInfo renderInfo = ImageRenderInfo.CreateForXObject(processor.Gs().ctm, refi);

                processor.renderListener.RenderImage(renderInfo);
            }
Beispiel #20
0
        public void RenderImage(ImageRenderInfo renderInfo)
        {
            PdfImageObject image = renderInfo.GetImage();
            try
            {
                image = renderInfo.GetImage();
                if (image == null) return;

                using (MemoryStream ms = new MemoryStream(image.GetImageAsBytes()))
                {
                    string filename = string.Format(@"{0}\Image-{1:0000}.{2}", outputPath, imageNumber++, image.GetFileType());
                    using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                    {
                        fs.Write(ms.ToArray(), 0, (int)ms.Length);
                    }
                    this.statusListView.Invoke(new MainForm.AddStatusItemDelegate(mainForm.AddStatusItem), new object[] { filename, "Extracted" });
                }
            }
            catch (IOException ie)
            {
                /*
                 * pass-through; image type not supported by iText[Sharp]; e.g. jbig2
                */
            }
        }
 /// <see cref="IRenderListener.RenderImage"/>
 public void RenderImage(ImageRenderInfo renderInfo)
 {
     items.Add(new ImageItem(renderInfo));
 }
        /**
         * Callback when an inline image is found.  This requires special handling because inline images don't follow the standard operator syntax
         * @param info the inline image
         * @param colorSpaceDic the color space for the inline immage
         */
        virtual protected void HandleInlineImage(InlineImageInfo info, PdfDictionary colorSpaceDic)
        {
            ImageRenderInfo renderInfo = ImageRenderInfo.CreateForEmbeddedImage(Gs().ctm, info, colorSpaceDic);

            renderListener.RenderImage(renderInfo);
        }
 /**
  * @see com.itextpdf.text.pdf.parser.RenderListener#renderImage(com.itextpdf.text.pdf.parser.ImageRenderInfo)
  */
 public void RenderImage(ImageRenderInfo renderInfo)
 {
     // do nothing
 }
        /**
         * Create an ImageRenderInfo object based on inline image data.  This is nowhere near completely thought through
         * and really just acts as a placeholder.
         * @param ctm the coordinate transformation matrix at the time the image is rendered
         * @param imageObject the image object representing the inline image
         * @return the ImageRenderInfo representing the rendered embedded image
         * @since 5.0.1
         */
        protected internal static ImageRenderInfo CreateForEmbeddedImage(GraphicsState gs, InlineImageInfo inlineImageInfo, PdfDictionary colorSpaceDictionary, ICollection markedContentInfos)
        {
            ImageRenderInfo renderInfo = new ImageRenderInfo(gs, inlineImageInfo, colorSpaceDictionary, markedContentInfos);

            return(renderInfo);
        }
Beispiel #25
0
 /// <summary>
 /// Creates an ImageItem based on an ImageRenderInfo object.
 /// </summary>
 /// <param name="imageRenderInfo">Object containing info about an image</param>
 public ImageItem(ImageRenderInfo imageRenderInfo) : base()
 {
     rectangle = GetRectangle(imageRenderInfo);
     color = IMG_COLOR;
 }
 /**
  * Applies filters, then delegates to the deleg if all filters pass
  * @see com.itextpdf.text.pdf.parser.RenderListener#renderImage(com.itextpdf.text.pdf.parser.ImageRenderInfo)
  * @since 5.0.1
  */
 public void RenderImage(ImageRenderInfo renderInfo) {
     foreach (RenderFilter filter in filters) {
         if (!filter.AllowImage(renderInfo))
             return;
     }
     deleg.RenderImage(renderInfo);
 }
 public virtual void RenderImage(ImageRenderInfo renderInfo) {
 }
        /**
         * @return Image boundary rectangle in device space.
         */
        private Rectangle CalcImageRect(ImageRenderInfo renderInfo) {
            Matrix ctm = renderInfo.GetImageCTM();

            if (ctm == null) {
                return null;
            }

            Point2D[] points = TransformPoints(ctm, false, new Point(0, 0), new Point(0, 1),
                                                           new Point(1, 0), new Point(1, 1));
            return GetRectangle(points[0], points[1], points[2], points[3]);
        }
Beispiel #29
0
 /**
  * no-op method - this renderer isn't interested in image events
  * @see com.itextpdf.text.pdf.parser.RenderListener#renderImage(com.itextpdf.text.pdf.parser.ImageRenderInfo)
  * @since 5.0.1
  */
 public virtual void RenderImage(ImageRenderInfo renderInfo) {
     // do nothing - we aren't tracking images in this renderer
 }
 public override bool AllowImage(ImageRenderInfo renderInfo) {
     throw new NotImplementedException();
 }