Get page size in bytes for PDF

Discussions about image processing and document imaging.
Post Reply
akinz
Posts: 1
Joined: Wed Jul 08, 2015 12:27 pm

Get page size in bytes for PDF

Post by akinz » Wed Jul 08, 2015 12:38 pm

HI,

is it possible to get page size in bytes for pdf?

My code for pdf (is there any other way to do this?):

Code: Select all

                        using (GdPicturePDF gdPicturePDF = new GdPicturePDF())
                        {
                            gdPicturePDF.LoadFromFile(filename, true);
                            int pageCount = gdPicturePDF.GetPageCount();
                            try
                            {
                                for (int i = 1; i < pageCount + 1; i++)
                                {
                                    GdPictureStatus gdPictureStatus = gdPicturePDF.SelectPage(i);
                                    if (gdPictureStatus == GdPictureStatus.OK)
                                    {
                                        //get current page size in bytes??!! 
                                        int rasterImageID = gdPicturePDF.RenderPageToGdPictureImage(RASTER_DPI, false);
                                        using (GdPictureImaging ogd = new GdPictureImaging())
                                        {
                                            ogd.SaveAsPDF(rasterImageID, string.Format(@"C:\temp\{0}.pdf", i), false, "", "", "", "", "");
                                            FileInfo fileInfo = new FileInfo(string.Format(@"C:\temp\{0}.pdf", i));
                                            long size = fileInfo.Length;
                                            fileInfo.Delete();
                                       }
                                       
For tiff files I did it like this:

Code: Select all

 
                    DocumentFormat docFormat = gdPictureImaging.GetDocumentFormatFromFile(filename);
                    if (docFormat == DocumentFormat.DocumentFormatTIFF)
                    {
                        int imageId = gdPictureImaging.TiffCreateMultiPageFromFile(filename);
                        int pageCount = gdPictureImaging.TiffGetPageCount(imageId);
                        try
                        {
                            for (int i = 1; i < pageCount + 1; i++)
                            {
                                GdPictureStatus gdPictureStatus = gdPictureImaging.TiffSelectPage(imageId, i);
                                if (gdPictureStatus == GdPictureStatus.OK)
                                {
                                    using (Stream stream = new MemoryStream())
                                    {
                                        gdPictureImaging.TiffExtractPage(imageId, i, stream);
                                        long size = stream.Length;
                                   }
                                }
                                else
                                    throw new Exception(string.Format("Loading image number {0} failed in file  {1}.", i, ""));
                            }
                        }

Cedric
Posts: 269
Joined: Sun Sep 02, 2012 7:30 pm

Re: Get page size in bytes for PDF

Post by Cedric » Wed Jul 29, 2015 10:57 am

Hello,

Knowing the page size in bytes does not really mean anything in the PDF world.
PDF documents cannot be compared to image files as they can contain various elements of different nature and using different compression schemes inside the same document.
If the documents are purely image based (such as scanner acquired documents for instance), in that context your approach is somehow correct if you are using the same rasterization resolution as the image.
In that case it would be safer to use the RenderPageToGdPictureImageEx method instead: https://www.gdpicture.com/guides/gdpicture/web ... ageEx.html
However if your documents are not image based, there is no reliable way to know the page size in bytes.

Cheers!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest