Document Properties in pdf
Hi,
I exported a Pages file to a pdf.
There is Document Properties in Acrobat Reader.
Is there any way to fill in the entries (Title, Author, ...) with Pages?
Hosun
MacBook Pro 13″, macOS 11.4
Hi,
I exported a Pages file to a pdf.
There is Document Properties in Acrobat Reader.
Is there any way to fill in the entries (Title, Author, ...) with Pages?
Hosun
MacBook Pro 13″, macOS 11.4
Not from Pages. You will need to post-process the PDF with a PDF Editor (not included with macOS), or programmatically via a custom application using Apple's PDFKit, writing a new PDF with the added metadata.
I have something in Python/Objective-C that can do this, as I used it just last evening.
Not from Pages. You will need to post-process the PDF with a PDF Editor (not included with macOS), or programmatically via a custom application using Apple's PDFKit, writing a new PDF with the added metadata.
I have something in Python/Objective-C that can do this, as I used it just last evening.
I just whipped up some AppleScript/Objective-C code to do the following:
The original PDF is unchanged.
The prompt for title and author (the last | is the cursor, and is not entered):
and the resulting metadata on the output pdf file after pressing ⌘+i in Apple's Preview to open the Inspector:
Copy and paste the following code into Apple's Script Editor (/Applications/Utilities/Script Editor), click the hammer icon (compile), and then run it by clicking the Run button. You can save this to your Desktop as a script, script bundle, or even an application. Double-click one of those Desktop items to run it.
(*
pdf_title_author.applescript
Reference: https://discussions.apple.com/thread/252859944?page=1
Tested: macOS 11.4
Author: VikingOSX, 2021-06-12, Apple Support Communities, No warranties or support expressed or implied.
*)
use framework "Foundation"
use framework "PDFKit"
use AppleScript version "2.4" -- Yosemite or later
use scripting additions
property NSString : a reference to current application's NSString
property NSURL : a reference to current application's NSURL
property NSMutableDictionary : a reference to current application's NSMutableDictionary
property PDFDocument : a reference to current application's PDFDocument
property PDFDocumentTitleAttribute : a reference to current application's PDFDocumentTitleAttribute
property PDFDocumentAuthorAttribute : a reference to current application's PDFDocumentAuthorAttribute
property DELIM : {"!", "|"}
# get original PDF
set pdf to POSIX path of (choose file of type {"com.adobe.pdf"} default location (path to desktop)) as text
# set the output filename and destination
set out_pdf to POSIX path of (choose file name with prompt "Enter output PDF name" default name "out.pdf" default location (path to desktop)) as text
# prompt the user for the title_author string containing "title|author name"
set title_author to text returned of (display dialog "Enter title and author separated by delimiter" default answer "")
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, DELIM}
# split the title_author string into components based on the DELIM character(s)
# and assign the text items to the pdf_title and pdf_author string variables
# example: {"title string", "author string"}
set {pdf_title, pdf_author} to text items of title_author
set AppleScript's text item delimiters to TID
# run the handler that does the PDF work
my replacePDFMetadata:pdf withOutPDF:out_pdf withTitle:pdf_title withAuthor:pdf_author
return
on replacePDFMetadata:inpdf withOutPDF:outpdf withTitle:stitle withAuthor:sauthor
set pdfURL to NSURL's fileURLWithPath:inpdf
set pdfdoc to PDFDocument's alloc()'s initWithURL:pdfURL
# make a mutable dictionary comprised of all PDF metadata names
set attrs to NSMutableDictionary's alloc()'s initWithDictionary:(pdfdoc's documentAttributes())
# update the title and author values for their corresponding keys
attrs's setObject:stitle forKey:PDFDocumentTitleAttribute
attrs's setObject:sauthor forKey:PDFDocumentAuthorAttribute
pdfdoc's setDocumentAttributes:attrs
pdfdoc's writeToFile:outpdf
return
end replacePDFMetadata:withOutPDF:withTitle:withAuthor:
Document Properties in pdf