convert vector paths to raster images

hi
could someone give me a code example of how to convert the path objects in a pdf to raster images
thanks

Hello,

The PDFDraw code sample shows how to rasterize PDF content, saving it to raster images:

http://www.pdftron.com/pdfnet/samplecode.html#PDFDraw

If you’re looking for a command-line tool for rasterization, you might be interested in the PDF2Image tool:

http://www.pdftron.com/pdf2image/downloads.html

Please let me know whether that helps and if you have any further questions.

Hi
thanks for that

I’m trying to extract all the images in a rectangular region; I think because some of the images are in vector format I’m getting only path data;
As suggested in another post, I tried to copy the path data to another PDFDoc and export out as an image, but I’m getting width <0 and height < 0 error.
Could you give me a code example how to do this? or some indication how to convert the path data to an image

Thanks
-Shathish

Hello Shathish,

I’m trying to extract all the images in a rectangular region; I think because some of the images are in vector format I’m getting only path data;

All images in a PDF are rasterized data (i.e., 2D matrices of pixels), not vectors. Vector data is only added to PDFs through paths or text. Thus, it’s a little unclear what you’re trying to export.

Example 5 of the PDFDraw sample (http://www.pdftron.com/pdfnet/samplecode.html#PDFDraw) shows how to rasterize only one subsection of a PDF page:

// Example 5) Zoom into a specific region of the page and rasterize the
// area at 200 DPI.
page.SetCropBox(new Rect(216, 522, 330, 600)); // Set the page crop box.

// Select the crop region to be used for drawing.
draw.SetPageBox(Page.Box.e_crop);
draw.SetDPI(900); // Set the output image resolution to 900 DPI.
draw.Export(page, output_path + “tiger_zoom_900dpi.png”, “PNG”);
Console.WriteLine(“Example 5: Result saved in {0}”, output_path + “tiger_zoom_900dpi.png”);

[In case you want to only extract raster images, the more efficient way of doing so is by avoiding PDF rendering and simply saving the image data directly, as the ImageExtract sample shows: http://www.pdftron.com/pdfnet/samplecode.html#ImageExtract.]

As suggested in another post, I tried to copy the path data to another PDFDoc and export out as an image, but I’m getting width <0 and height < 0 error.

I’m not sure what code you were running. You may want to forward a code sample and/or a sample document to support@pdftron.com.

That said, the ElementBuilder sample (http://www.pdftron.com/pdfnet/samplecode.html#ElementBuilder) shows how to copy PDF elements from one page to another.

In case you want to rasterize only vector data, without any images, you may want to take a look at the ElementEdit sample (http://www.pdftron.com/pdfnet/samplecode.html#ElementEdit), which shows how to strip out all images from a PDF page. You could then rasterize the page (which would only contain paths and text) with PDFDraw.

Please let me know whether that helps and if you have any further questions.

Hi
Thanks for that- you have given me lot of insight
What I’m trying to do is draw a selection marquee in pdf (Using PdfViewCtrl), and then trying to extract the text and images inside that region
The text extraction is working fine, but when it comes to image, I wasn’t able to extract all images inside that region- but I could see in the pdf there are lot of images inside that region
What is the best way to select all images inside a region ? maybe an answer to that would sort my problem
Please let me know if you need more information
Thanks
-Shathish

Hello Shathish,

What is the best way to select all images inside a region ?

As a starting point you should look at the ImageExtract sample (http://www.pdftron.com/pdfnet/samplecode.html#ImageExtract). The sample shows how to extract all images from a given PDF page — however, you can tweak the code so that only elements within a given region/rectangle are extracted. To obtain a bounding box for an element, use element.GetBBox(rect). To test for rectangle intersection, use rect.IntersectRect(r1, r2).