Current filter:
                                You should refresh the page.
                                  • I have a pdf document and I want to be able to convert a certain region of the document to an image. Exactly as it works with PdfDocumentProcessor.CreateBitmap(...) or .CreateTiff(...)
                                    Instead of the full page, I just want a specific area of the page to be exported. I'm familiar with creating a PdfDocumentArea, I'm just not sure how to convert this selected area to an image.

                                    If this isn't currently an available feature, do you have any ideas on how this could be accomplished in a different fashion?

                                1 Solution

                                Creation Date Importance Sort by

                                Hello Eric,

                                Our Pdf Document Processor does not provide a special API to create an image based on the specified page area. As a workaround, you can create an image from the entire page. Calculate the required area to be represented by an image. You can get the page size using the  PdfPage.CropBox property. Note that it is measured in PDF page unit measurement (points - 1/72 of an inch). And, create a new Bitmap object of the required size and draw the required part of the image using the Graphics.DrawImage method as described in the How to cut a part of image in C#.

                                I have created a small sample that illustrates this approach. You can find it in the attachment.

                                • Eric Upton 01.25.2017

                                  Thank you for sharing your insight and providing the sample. I used it as a starting place to get what I needed.

                                  For anyone interested, here's is the end result:

                                  private void ConvertRegionToImage(PdfDocumentProcessor processor, PdfDocumentArea area) { float dpi = Convert.ToInt32(txtDpi.EditValue); //defaults to 72 float scale = (float)txtScale.EditValue; //1.5f; PdfPage page = processor.Document.Pages[0]; Bitmap pageBitmap = processor.CreateBitmap(1, (int)Math.Max(page.CropBox.Height * scale, page.CropBox.Width * scale)); float widthInPixels = DevExpress.Office.Utils.Units.PointsToPixelsF((float)area.Area.Width * scale, dpi); float heightInPixels = DevExpress.Office.Utils.Units.PointsToPixelsF((float)area.Area.Height * scale, dpi); int x = Convert.ToInt32(DevExpress.Office.Utils.Units.PointsToPixelsF((float)area.Area.Left * scale, dpi)); int y = Convert.ToInt32(DevExpress.Office.Utils.Units.PointsToPixelsF((float)(page.CropBox.Height - area.Area.Top) * scale, dpi)); using (Bitmap bitmap = new Bitmap((int)widthInPixels, (int)heightInPixels)) { using (Graphics graphics = Graphics.FromImage(bitmap)) { graphics.DrawImage(pageBitmap, 0, 0, new Rectangle(x, y, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel); bitmap.Save("result.png"); } } }
                                • Yulia (DevExpress Support) 01.25.2017

                                  Thank you for informing us that the task has been solved and for sharing your code. Please do not hesitate to contact us in case of any difficulty. We will be happy to help you!

                                • emre korkmaz 08.08.2019

                                  I have PdfOrientedRectangle value from PdfDocumentProcessor.NextWord in my hand. I want to get the image of this word rectange. How can I get the image by using this idea ? How is the conversion from PdfOrientedRectangle to PdfDocumentArea? Or do we have other method to do this operation by using PdfOrientedRectangle?


                                • Yulia (DevExpress Support) 08.08.2019


                                  I've created a separate ticket on your behalf (T805079: How to create an image for a word returned by the PdfDocumentProcessor.NextWord method). It has been placed in our processing queue and will be answered shortly.