Extract a range of data from pdf into a JPG

Hi
How can I create an image from PDF, but only a portion of the PDF? Say 0,0, 1000,1000.
I can extract the whole PDF. But only need a section. I’ve have seen the following.

thanks in advance

for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream = new FileStream(Temp + “\image” + pageCount + “_out” + “.jpg”, FileMode.Create))
{
// Create PNG device with specified attributes
// Width, Height, Resolution, Quality
// Quality [0-100], 100 is Maximum
// Create Resolution object
Resolution resolution = new Resolution(300);
JpegDevice jpgDevice = new JpegDevice(resolution);

                        jpgDevice.Process(pdfDocument.Pages[pageCount], imageStream);

                        // Close stream
                        imageStream.Close();
                    }
                }

@jon_elster_i3intel_com

Please check following Documentation Article in order to get what you require:

Document document = new Document("Input.pdf");

// Get rectangle of a particular page region
Rectangle pageRect = new Rectangle(20, 671, 693, 1125);

for (Page page : document.getPages()) {
    // Set CropBox value as per the rectangle of the desired page region
    page.setCropBox(pageRect);
}

// Save the cropped document into a stream
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
document.save(outStream);

// Open the cropped PDF document from the stream and convert to an image
document = new Document(new ByteArrayInputStream(outStream.toByteArray()));

for (Page page : document.getPages()) {
    // Create a Resolution object
    com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(300);
    
    // Create a BMP device with specified attributes
    com.aspose.pdf.devices.BmpDevice bmpDevice = new com.aspose.pdf.devices.BmpDevice(resolution);
    
    // Convert a particular page and save the image to stream
    bmpDevice.process(page, page.getNumber() + "Output.bmp");
}

Thx… How I convert a region on all pages from a multi page PDF.
I want the same region from all pages?
I doing the following? where do I add the ‘Rectangle’ region?
thanks again

for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream = new FileStream(TempOCR + “\image” + pageCount + “_out” + “.jpg”, FileMode.Create))
{
// Create PNG device with specified attributes
// Width, Height, Resolution, Quality
// Quality [0-100], 100 is Maximum
// Create Resolution object
Resolution resolution = new Resolution(300);
JpegDevice jpgDevice = new JpegDevice(resolution);

                        jpgDevice.Process(pdfDocument.Pages[pageCount], imageStream);


                        // Close stream
                        imageStream.Close();
                    }
                }

@jon_elster_i3intel_com

In order to convert all pages with specific region, please use following code snippet:

Document document = new Document("Input.pdf");
// Get rectangle of particular page region
Rectangle pageRect = new Rectangle(20, 671, 693, 1125);
for(Page page: document.getPages()){
     // set CropBox value as per rectangle of desired page region
     page.setCropBox(pageRect);
}
// save cropped document into stream
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
document.save(outStream);
// open cropped PDF document from stream and convert to image
document = new Document(new ByteArrayInputStream(outStream.toByteArray()));
for(Page page:document.getPages()){
     // Create Resolution object
     com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(300);
     // Create BMP device with specified attributes
     com.aspose.pdf.devices.BmpDevice bmpDevice = new com.aspose.pdf.devices.BmpDevice(resolution);
     // Convert a particular page and save the image to stream
     bmpDevice.process(page, page.getNumber() + "Output.bmp");
}

Thanks again!

What is equivalent code in C# ? I don’t see the same methods?

Rectangle pageRect = new Rectangle(20, 671, 693, 1125);
for(Page page: document.getPages()){
// set CropBox value as per rectangle of desired page region
page.setCropBox(pageRect);
}
// save cropped document into stream
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
document.save(outStream);
// open cropped PDF document from stream and convert to image
document = new Document(new ByteArrayInputStream(outStream.toByteArray()));
for(Page page:document.getPages()){
// Create Resolution object
com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(300);
// Create BMP device with specified attributes
com.aspose.pdf.devices.BmpDevice bmpDevice = new com.aspose.pdf.devices.BmpDevice(resolution);
// Convert a particular page and save the image to stream
bmpDevice.process(page, page.getNumber() + “Output.bmp”);
}

@jon_elster_i3intel_com

Please check following code snippet:

Rectangle pageRect = new Rectangle(20, 671, 693, 1125);
foreach (Page page in document.Pages)
{
 // set CropBox value as per rectangle of desired page region
 page.CropBox = pageRect;
}
// save cropped document into stream
MemoryStream outStream = new MemoryStream();
document.save(outStream);
outStream.Seek(0, SeekOrigin.Begin);
// open cropped PDF document from stream and convert to image
document = new Document(outStream);
foreach (Page page in document.Pages)
{
 // Create Resolution object
 Resolution resolution = new Resolution(300);
 // Create BMP device with specified attributes
 BmpDevice bmpDevice = new BmpDevice(resolution);
 // Convert a particular page and save the image to stream
 bmpDevice.process(page, page.Number + "Output.bmp");
}