Pages PDF Export changes Page size

When exporting a pages document to PDF it's physical page size changes. How do I avoid this?


MacBook Pro 15″, macOS 11.2

Posted on Mar 30, 2021 1:45 PM

Reply
2 replies

Mar 31, 2021 6:57 AM in response to sensslen

Here is an AppleScript that you copy/paste into Script Editor and save as an AppleScript application to the Desktop. When you want to know about the PDF dimensions from directly within the PDF, rather than what the Preview Inspector may present, you run this script. If the CropBox and MediaBox sizes are the same, it will just print a dialog like the following:



Otherwise, both MediaBox and CropBox dimensions will be displayed.



# PDFbox.applescript

# Prompt user for PDF document and display its MediaBox (and CropBox if different)
# with dimensions in pixels, inches, and Centimeters.

# Tested: macOS 11.2.3
# VikingOSX, 2021-03-31, Apple Support Communities, No warranties expressed/implied.

use framework "Foundation"
use framework "PDFKit"
use scripting additions

property NSString : a reference to current application's NSString
property NSURL : a reference to current application's NSURL
property PDFDocument : a reference to current application's PDFDocument
property kPDFDisplayBoxMediaBox : a reference to current application's kPDFDisplayBoxMediaBox
property kPDFDisplayBoxCropBox : a reference to current application's kPDFDisplayBoxCropBox

set thePDF to POSIX path of (choose file of type {"com.adobe.pdf"} default location (path to desktop)) as text
set fname to ((NSString's stringWithString:thePDF)'s lastPathComponent()) as text
set pdfURL to NSURL's fileURLWithPath:thePDF
set pdf to PDFDocument's alloc()'s initWithURL:pdfURL
set page_dim_crop to ((pdf's pageAtIndex:0)'s boundsForBox:kPDFDisplayBoxCropBox) as list
# returned as a list of lists {{0,0}, {612, 792}}
set page_dim_media to ((pdf's pageAtIndex:0)'s boundsForBox:kPDFDisplayBoxMediaBox) as list

# compare CropBox and MediaBox and if equivalent only output MediaBox data
if page_dim_crop = page_dim_media then
	set {Wm, Hm} to (items 1 thru 2 of (item 2 of page_dim_media))
	set inList to my convert_pixels(Wm, Hm, "in")
	set cmList to my convert_pixels(Wm, Hm, "cm")
	set MB_fmt_inches to " • " & (item 1 of inList) & " x " & (item 2 of inList) & space & (item 3 of inList)
	set MB_fmt_metric to " • " & (item 1 of cmList) & " x " & (item 2 of cmList) & space & (item 3 of cmList)
	display dialog "Filename: " & fname & return & "MediaBox: " & Wm & " x " & Hm & MB_fmt_inches & MB_fmt_metric with title "PDF Document Dimensions"
else
	set {Wc, Hc} to (items 1 thru 2 of (item 2 of page_dim_crop))
	set inList to my convert_pixels(Wc, Hc, "in")
	set cmList to my convert_pixels(Wc, Hc, "cm")
	set CB_fmt_inches to " • " & (item 1 of inList) & " x " & (item 2 of inList) & space & (item 3 of inList)
	set CB_fmt_metric to " • " & (item 1 of cmList) & " x " & (item 2 of cmList) & space & (item 3 of cmList)
	
	set {Wm, Hm} to (items 1 thru 2 of (item 2 of page_dim_media))
	set inList to my convert_pixels(Wm, Hm, "in")
	set cmList to my convert_pixels(Wm, Hm, "cm")
	set MB_fmt_inches to " • " & (item 1 of inList) & " x " & (item 2 of inList) & space & (item 3 of inList)
	set MB_fmt_metric to " • " & (item 1 of cmList) & " x " & (item 2 of cmList) & space & (item 3 of cmList)
	
	display dialog "Filename: " & fname & return & "CropBox:   " & Wc & " x " & Hc & CB_fmt_inches & CB_fmt_metric & return & "MediaBox: " & Wm & " x " & Hm & MB_fmt_inches & MB_fmt_metric with title "PDF Document Dimensions"
end if
return

on convert_pixels(nw, nh, si)
	if si = "cm" or si = "CM" then
		set valW to (do shell script "bc -l <<<\"scale=3;(" & nw & " / 72.0) * 2.54\"")
		set valH to (do shell script "bc -l <<<\"scale=3;(" & nh & " / 72.0) * 2.54\"")
	else if si = "in" or si = "IN" then
		set valW to (do shell script "bc -l <<<\"scale=2;" & nw & " / 72.0\"")
		set valH to (do shell script "bc -l <<<\"scale=2;" & nh & " / 72.0\"")
	end if
	return {valW, valH, si} as list
end convert_pixels


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Pages PDF Export changes Page size

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.