Z
Z
Zakharov Alexander2017-12-21 10:43:38
C++ / C#
Zakharov Alexander, 2017-12-21 10:43:38

IText. Extracting images. Am I only getting thumbnails?

Hello.
There is a document with scanned pictures. You need to extract them. Code example:

string src = PDFSourcePath;
            PdfReader reader = null;
            try {
                reader = new PdfReader(src);
                for (int i = 0; i <= reader.NumberOfPages - 1; i++) {
                    try {
                        PdfDictionary page = reader.GetPageN(i);
                        PdfDictionary resources = page.GetAsDict(PdfName.RESOURCES);
                        PdfDictionary xobjects = resources.GetAsDict(PdfName.XOBJECT);
                        int j=0;
                        foreach (PdfName imgRef in xobjects.Keys) {
                            j++;
                            try {
                                PRStream imgStream = (PRStream) xobjects.GetAsStream(imgRef);
                                PdfImageObject imgObject = new PdfImageObject(imgStream);
                                System.Drawing.Image ImgPDF = imgObject.GetDrawingImage();
                                string image_ext = GetImageExtention(ImgPDF);
                                ByteArrayToFile(System.IO.Path.GetDirectoryName(PDFSourcePath) + "\\image"+i+"."+j+".jpg", imgObject.GetImageAsBytes());
                                ImgPDF.Save(System.IO.Path.GetDirectoryName(PDFSourcePath) + "\\image." + i + "." + j + ".png", ImageFormat.Png);
                            }
                            catch (Exception _ex) {

                            }
                        }
                    }catch(Exception _ex01) {

                    }
                }
            }
            catch(Exception _ex) { 
            }
            finally {
                if (reader != null) {
                    reader.Close();
                }
            }

But instead of a normal image, I get only thumnails of images, but with large sizes in bytes. I open it, and there are only squares and pieces of text: No one came across? Is there any way to extract normal quality images? PS When viewing a PDF-reader, I observe how these tumbnails appear for a split second and then are replaced by normal images.
5a3b65986e3e1922665866.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question