PDF import in photoshop
Copy link to clipboard
Copied
Hi All,
I am using the below code for import the PDF into Photoshop. It is working fine with 72 resolution and produce the correct output. But if we fix for 400 resolution, script produce the wrong output (image stretched vertically).
Please do the needful to get correct output and 400 resolution.
Thanks!
var inputFiles = File.openDialog("Choose the Input PDF File", "*.pdf", false);
var pdfOption = new PDFOpenOptions();
pdfOption.cropPage = CropToType.TRIMBOX;
pdfOption.antiAlias = true;
pdfOption.constrainProportions = true;
pdfOption.resolution = 400;
pdfOption.mode = OpenDocumentMode.RGB;
pdfOption.bitsPerChannel = BitsPerChannelType.EIGHT;
pdfOption.suppressWarnings = true;
app.open(inputFiles, pdfOption, false);
Explore related tutorials & articles
Copy link to clipboard
Copied
Please porvide a pdf for which the problem happens.
Copy link to clipboard
Copied
Hi @c.pfaffenbichler i have attached the sample pdf document and also attached manual output and script produced output screen shot.
Manual output:
Script produced output:
  
Copy link to clipboard
Copied
I suspect you hit limits when trying to convert a pdf at 400ppi that’s more than 4m broad.
Copy link to clipboard
Copied
Hi,
Thanks for the replies. Is there any possible way in script to give the same output as manual for this kind of Large size PDF?
If I receive the javascript code for that then its much useful for me.
Please advise.
Thanks
Copy link to clipboard
Copied
As I wrote, for me, in Photoshop 2021 (22.5.7), the manual open and the script open both results in exactly the same image, there is no difference/distrotion. I can't reproduce your issue with your test file.
Copy link to clipboard
Copied
The PDF page boxes are 162.6 x 62.51 inches in size, however, if you crop to the bouding box it is only 8.33 x 3.93 inches. As @c.pfaffenbichler mentioned, this large size page box multiplied by 400ppi will create an image that is large in pixel size – 32,000 x 25004 pixels. Photoshop 2021 allows me to do both manually and scripted and the results are exactly the same for me, no distortion in the script version.
Copy link to clipboard
Copied
Hi Stephen,
Thanks. But in my end, there is a problem in both 2021 version and 2022 version. Can you please guide me, if the pdf have more than 4m size in width or heigth then how do we arrest this by script?
Thanks
Copy link to clipboard
Copied
Are you Intel Mac, M1 Mac or Windows OS? I'm testing on an Intel Mac.
Why is there such a discrepancy between the page box sizes and the bounding box size of the test file? Is this truly representative of a production file?
Copy link to clipboard
Copied
Hi Stephen,
I am using, iMac (Monterey OS 12.2.1), with Adobe Photoshop 2022 version.
For the confidential product I am unable to place that original production file here. So for that I have recreated the sample by myself.
Thanks
Copy link to clipboard
Copied
OK, I'm on Big Sur (11.6.5), but are you on Intel or M1 processor?
What is the correct page box? In your test file, all page boxes are the same size. The content bounding box is much smaller.
Your script is rasterizing on the trim box. Can you ensure that all incoming PDF files have a correct trim box?
Copy link to clipboard
Copied
Hi Stephen,
My processor is "3.5 GHz Quad-Core Intel Core i5".
I have create another sample file and attached here with same as production file.
Thanks
Copy link to clipboard
Copied
What is the point of this ultimately?
Why are you converting the pdfs to pixel data?
Why do you need such a high resolution?
Copy link to clipboard
Copied
Hi,
Our ultimate goal is to import the pdf with 400 resolution, and we need to crop the pdf in trim size.
High resolution request is user requirments.
Thanks
Copy link to clipboard
Copied
OK, I can now reproduce the distorted result.
There appears to be a 32,000 pixel size limit for rasterizing a PDF before it is distorted.
When I rasterized at 100 ppi and then resampled to 400 ppi, the result is 65040 px wide, however, the largest size that I can rasterize is 32,000px.
Are you trying to use Photoshop as a print RIP?
Copy link to clipboard
Copied
Hi Stephen,
Sorry, I am not clear about "Photoshop as a print RIP"?
Our ultimate goal is to import the pdf with 400 resolution, and we need to crop the pdf in trim size through script.
Please note that the pdfs may suffle with different sizes (small width, or large width).
Can you please guide me to out from this?
Thanks
Copy link to clipboard
Copied
I meant that are you trying to rasterize the PDF for printing, rather than sending the PDF through a RIP (Raster Image Processor) for printing to say an inkjet printer.
https://en.wikipedia.org/wiki/Raster_image_processor
The width and height settings are deprecated, I tried:
pdfOption.width = (UnitValue(30000, "px"));
However as it is deprecated, it is overridden by the resolution PPI value.
Copy link to clipboard
Copied
Prabu I wrote:Our ultimate goal is to import the pdf with 400 resolution, and we need to crop the pdf in trim size through script
But that isn't the ultimate goal is it, otherwise, what is the point?
Are you wishing to print direct from Photoshop?
Are you wishing to save the file as a PSB?
What happens after rasterizing into Photoshop?
Copy link to clipboard
Copied
Hi Stephen,
After import PDF (with crop and 400 resolution) I saved that file to JPEG.
Thanks
Copy link to clipboard
Copied
That limit seems to also apply to manual conversion for me, though.
As a work-around I would recommend:
• converting at a low resolution (and filling white)
• placing as a Smart Object
• upsampling the image
@Prabu I , what is the ultimate use?
Print? If so the destruction of vector and font data would seem suboptimal.
Copy link to clipboard
Copied
c.pfaffenbichler wrote:
That limit seems to also apply to manual conversion for me, though.
Yes agreed, I didn't mean that the apparent 32,000 pixel limit was only for scripting, but also opening manually.
Copy link to clipboard
Copied
Hi @c.pfaffenbichler ,
After import PDF (with crop and 400 resolution) I saved that file to JPEG.
Thanks
Copy link to clipboard
Copied
To get around the pixel limitations I would recommend employing a »simple« work-around, see previous post.
It would take a »little« more time, but if the results needs to be thus it may be hard to avoid.
Copy link to clipboard
Copied
Hi @c.pfaffenbichler , Thanks!
Copy link to clipboard
Copied
Hi @c.pfaffenbichler , @Stephen Marsh , Is there any possible way to get PDF width and height using javascript before opening into the photoshop.
Thanks


-
- 1
- 2