Yes, I found the same methods (by Shane Stanley) here:
This script works for me (i.e., it saves the web contents of the DT tab as a PDF to the desktop):
use framework "/System/Library/Frameworks/Quartz.framework"
use framework "Foundation"
use scripting additions
tell application id "DNtp"
set thisTab to open tab for URL "https://kernel.org"
repeat while loading of thisTab = true
delay 1
end repeat
set pdfASData to PDF of thisTab
end tell
set pdfNSData to my dataFromASData:pdfASData
set pdfDoc to (current application's PDFDocument's alloc()'s initWithData:pdfNSData)
set posixPath to POSIX path of ((path to desktop as text) & "WritePDFTest.pdf")
set filePath to current application's NSString's stringWithString:posixPath
set fileURL to current application's NSURL's fileURLWithPath:filePath
set writeSuccess to pdfDoc's writeToURL:fileURL
-- convert AppleScript data to NSData
-- by Shane Stanley
-- https://forum.latenightsw.com/t/convert-nsdata-into-raw-data-string/1914/4
on dataFromASData:asData
return (current application's NSArray's arrayWithObject:asData)'s firstObject()'s |data|()
end dataFromASData:
1 Like