4
$\begingroup$

I have a pdf file that I want to resize after importing. However, ImageResize doesn't seem to take into account the high-resolution of the initial image, and resizing makes it very pixelated. I can rescale the original import by hand for better effect, but how can I get this result automatically?

G0 = Import["Structure.pdf"][[1]];
Style[Grid[{{G0, ImageResize[G0, Scaled[2]], G0}}],ImageSizeMultipliers -> {1, 1}]

Original import, image resize, and manually resized original image

$\endgroup$
6
  • $\begingroup$ Please make that link to the image a 1-click download such that no sign-on to any service is required. Thanks. $\endgroup$
    – Syed
    Apr 27, 2022 at 9:34
  • $\begingroup$ I'm not sure what site I can use to upload a pdf that way. $\endgroup$
    – ChaSta
    Apr 27, 2022 at 10:25
  • $\begingroup$ Link to google drive with sharing enabled? $\endgroup$
    – Syed
    Apr 27, 2022 at 10:27
  • $\begingroup$ Ok, thanks. I have changed it. $\endgroup$
    – ChaSta
    Apr 27, 2022 at 11:36
  • 1
    $\begingroup$ I guess, you should add the option "PageImages" into Import command. This will give you the full-scale images instead of the thumbnails $\endgroup$
    – Rom38
    Apr 27, 2022 at 12:32

1 Answer 1

7
$\begingroup$

In general, you should use the "EmbeddedImages" element when importing raster images from a PDF file:

Import["http://exampledata.wolfram.com/article.pdf", "EmbeddedImages"]

From the Documentation:

screenshot

But your file "Structure.pdf" doesn't contain raster images - it is a pure vertor figure. Hence if you wish to convert it to raster, you can use the "PageImages" element with either ImageResolution or "RasterSize" option for controlling the resolution of the final raster image:

Import["Structure.pdf", {"PageImages", 1}, ImageResolution -> 300]

screenshot

Import["Structure.pdf", {"PageImages", 1}, "RasterSize" -> 500]

screenshot

Alternatively, you can import it as a vector figure, and then use Rasterize to convert it to a raster image:

vectFig = Import["Structure.pdf", If[$VersionNumber >= 12.2, {"PDF", "PageGraphics"}, {"PDF", "Pages"}]][[1]]
Rasterize[vectFig, ImageSize -> 500]

screenshot

$\endgroup$
1
  • $\begingroup$ Thanks, this works! $\endgroup$
    – ChaSta
    Apr 29, 2022 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.