Best way to process images on PDF files

Example requests & Code samples for GdPicture Toolkits.
Post Reply
fervelas
Posts: 6
Joined: Tue Aug 08, 2017 5:09 am

Best way to process images on PDF files

Post by fervelas » Tue Sep 26, 2017 8:52 am

Hey guys,

I'm currently using the latest release of GdPicture v14. The system we're building will mostly handle image-only PDF files and a few TIFF files. Most cleanup and manipulation operations with TIFF files are trivial to implement by using a GdPictureImaging object, but I don't know if there is an easier way to do it when handling PDF files. This is an extract of a cropping operation on a PDF file composed of all images:

Code: Select all

            //This assumes that the first page is selected and shown on a GdViewer and that the user has previously selected an area on the viewer
            float top = 0, left = 0, width = 0, height = 0;
            //extract the pdf page as an image
            int tempImage = gdPdf.RenderPageToGdPictureImage(200, false);
            //get the dimensions and position of the selected area
            imageViewer.GetRectCoordinatesOnDocumentInches(ref left, ref top, ref width, ref height);
            left *= 200;
            top *= 200;
            width *= 200;
            height *= 200;
            //crop the image to the dimensions of the selected area
            gdPicture.Crop(tempImage, (int)left, (int)top, (int)width, (int)height);
            //remove the original page from the pdf file
            gdPdf.DeletePage(1);
            //insert a new, blank page
            gdPdf.InsertPage(width, height, 1);
            //add the cropped image as a resource to the pdf
            string imageResx = gdPdf.AddImageFromGdPictureImage(tempImage, false, false);
            //draw it on the first page
            gdPdf.DrawImage(imageResx, 0, 0, width, height);
            //refresh viewer and thumbnails
            imageViewer.Redraw();
            thumbnailViewer.RedrawItem(0);
This proof of concept snippet works for me, but I feel it's a bit overkill compared to the simplicity involved in doing the same thing with a TIFF file, which only takes 3 lines of code to accomplish the same crop operation. There are other cleanup operations that I'll be performing in the system so I would appreciate it if you guys can shed some light as to better practices while working with image-only PDFs to avoid too much code complexity and to provide fast image manipulation in these cases.

Many thanks in advance for any advice I can get!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest