Set preferred width when capturing PDFs

The width of captured PDFs is based on the current window settings as has been mentioned before:

Recently I noticed that Keep!It PDF has a setting to set the width when capturing PDFs. Would it also be possible to add such an (optional) setting on DEVONthink? It would make for more consistent / usable PDFs.

When capturing a PDF via the Safari web clipper (using the icon) the width is determined by the current Safari window size. But when clipping via the Share extension (using the Share extension and choosing “Add to DEVONthink”) the width seems independent from the window size.

The Share extension gets only the information provided by the source app whereas the browser extension can grab more useful information.

That makes sense, but does this also mean that the share extension uses a default width for capturing PDFs? That would in some cases be preferred (to not end up with completely different scaled PDFs)

In this case a default width is indeed used.

Thanks. I’m still trying to wrap my head around what’s actually happening when DT captures PDFs:

  • When using the Safari extension DT uses information from the browser (width, title, …) and creates a PDF based on the current browser width.

  • When using the Add to DT share extension it does not use browser specific information (it probably only gets URL and title?) and creates a PDF based on certain defaults (which aren’t configurable for the user)

But there’s another interesting difference in the outputs (using the URL of this page as an example). Because you can also use the in-app DT3 browser to capture.

Using the methods above (via web clipper / share extension) both pages are captured in a (sort of) print layout (and interestingly /print is added to the URL - not sure if DT is doing that or Discourse through some JS/CSS @media magic?).

But when creating a bookmark in DT and capturing this page subsequently it creates a near-perfect copy as view in the in-app browser. See below for the differences:

Using the Safari extension or Add to DT share extension:

Using the in-app browser function to capture

1 Like

By the way: my current workflow is that I’m running DT3 on a separate Mac with predefined workspaces / in-app browser sizes so I’m always capturing the PDF formats I want. But a more robust solution like Keep!It by being able to set a specific width would be great.

That’s right.

This is just a special handling for our forum.

Ah! That’s hardcoded in DT?

It is.

Thanks. As I was looking for a script that saves a PDF of the current view I was happy to notice that the script from this 14(!) year old post still does the trick (with some minor updates) Capture PDF document to current group

tell application id "DNtp"
		if not (exists think window 1) or not (exists content record of think window 1) then error "No window/document is open."
		set theWindow to think window 1
		set theURL to URL of theWindow
		set theName to name of theWindow
		set thePDF to PDF of theWindow
		if exists current group then
			set theRecord to create record with {name:theName, type:picture, URL:theURL} in current group
			set theRecord to create record with {name:theName, type:picture, URL:theURL}
		end if
		set data of theRecord to thePDF
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

1 Like

@cgrunenberg @bluefrog is it possible to directly create a captured PDF via AppleScript without having to have / create a bookmark first?

Sure, see create PDF document from command.

1 Like

Excellent - thanks!

Download Script Debugger. Its representation of an app’s AppleScript dictionary (Window > Dictionary) might help.

(And Script Debugger is in general very useful)

Thanks Pete! I had Script Debugger installed on my previous MacBook, but hadn’t reinstalled it yet on this machine.

1 Like

Using Script Debugger (which indeed has better documentation than the standard Script Editor - thanks Pete) I found out the create PDF document from actually just has a width argument which works exactly like I want. I’m now using this script:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application id "DNtp"
		set theURL to "https:///"
		set thePDF to create PDF document from theURL width 800
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell
1 Like

Yes, it’s really great – plus, the fact that you can log in to a website within DEVONthink’s browser means that you can capture pages behind paywalls.

If you are going down this road of opening pages in DEVONthink and then creating a PDF from it, you may be interested in reading the following forum postings,

and also something I wrote and posted about before, a hackacious approach to causing web pages to be loaded more fully in DEVONthink to improve the capture of pages that have dynamic content.

While true this often works - and is our advocated method in such cases, we cannot reasonably guaranteed it 100%. However, the averages are high enough it’s a good option to try.

1 Like

Thanks for pointing these out
again. I’ve looked at your scripts before and they are indeed very helpful. I’ve used some your ideas before in GitHub - mdbraber/save-safari-pdf: Automatically open websites in Safari and Export as PDF (converting that to a full DT approach. I also have a working set of scripts specifically to capture all of my LinkedIn profiles including contact info.

One thing: it seems that because your approach is dependent on the window width / UI - the width from the Applescript command cannot be used. How are you solving the width ‘issue’? By just keeping the window at the same size?