Esempio n. 1
0
        public static byte[] GetPictureFromPdf(Stream stream)
        {
            byte[] imageData = new byte[0];
            string path      = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).FullName, "wwwroot", "CV Parser", "Pictures");

            using (PdfReader pdfReader = new PdfReader(stream))
            {
                for (int i = 0; i < pdfReader.XrefSize; i++)
                {
                    PdfObject po = pdfReader.GetPdfObject(i);

                    if (po == null || !po.IsStream()) //object not found so continue
                    {
                        continue;
                    }

                    PRStream  pst  = (PRStream)po;
                    PdfObject type = pst.Get(PdfName.SUBTYPE); //get the object type
                                                               //check if the object is the image type object
                    if (type != null && type.ToString().Equals(PdfName.IMAGE.ToString()))
                    {
                        PdfImageObject pio = new PdfImageObject(pst);

                        int imageLength = pio.GetImageAsBytes().Length;

                        if (imageLength != WatermarkSize && imageLength > imageData.Length)
                        {
                            imageData = pio.GetImageAsBytes();
                        }
                    }
                }
            }

            return(imageData);
        }
Esempio n. 2
0
        public virtual bool CompareStreams(PRStream outStream, PRStream cmpStream)
        {
            bool decodeStreams = PdfName.FLATEDECODE.Equals(outStream.Get(PdfName.FILTER));

            byte[] outStreamBytes = PdfReader.GetStreamBytesRaw(outStream);
            byte[] cmpStreamBytes = PdfReader.GetStreamBytesRaw(cmpStream);
            if (decodeStreams)
            {
                outStreamBytes = PdfReader.DecodeBytes(outStreamBytes, outStream);
                cmpStreamBytes = PdfReader.DecodeBytes(cmpStreamBytes, cmpStream);
            }
            return(Util.ArraysAreEqual(outStreamBytes, cmpStreamBytes));
        }
        private void UpdateImageStream(PRStream imageStream, byte[] newData)
        {
            PdfImage image = new PdfImage(Image.GetInstance(newData), "", null);

            if (imageStream.Contains(PdfName.SMASK))
            {
                image.Put(PdfName.SMASK, imageStream.Get(PdfName.SMASK));
            }

            if (imageStream.Contains(PdfName.MASK))
            {
                image.Put(PdfName.MASK, imageStream.Get(PdfName.MASK));
            }

            if (imageStream.Contains(PdfName.SMASKINDATA))
            {
                image.Put(PdfName.SMASKINDATA, imageStream.Get(PdfName.SMASKINDATA));
            }

            imageStream.Clear();
            imageStream.PutAll(image);
            imageStream.SetDataRaw(image.GetBytes());
        }