Copy link to a part (e.g. page) of a PDF document?

I am using DT’s ability to copy (into an external app) a link to a PDF document that was imported into DT.

Is there any way to copy a link to something within a PDF document, such as a particular page?

Thanks.

No, that’s not (yet) possible.

Thanks Christian. Can you comment on whether it will be available in 2.0?

Kay, I often create rich text notes about reference materials. Within these notes I can create hyperlinks based on the Name of a referenced document. Clicking on that link will open that document, but only at the beginning, the first page.

Here’s a little trick that will let me jump to, for example, page 67 of a PDF.

Suppose on page 67 of that PDF there’s a text string such as “Aldous Huxley, author of Eyeless in Gaza”. I’ll select that text, copy it to the clipboard, paste it (within quotation marks) into my rich text note and use it as a ‘marker’ string.

Now, from that rich text note, if I want to “jump to” page 67 of that PDF, I can select the marker string (including the quotation marks) within the note and press Command-/ (the Lookup command).

A Search window will open with the string already entered. In DEVONthink 2.0 those quotation marks mean that the search is to be for an exact string of text in the database.

Hit Return and the PDF that contains that string will be in the results list. Select it, and it will scroll down to page 67, highlighting the query string.

Although this is indirect, I find it easy to select a ‘marker’ text string that will usually limit the search result to just the document I’m referencing (plus, of course, the occurrence in my rich text note), even though there are more than 25,000 documents in my database. Better yet, this approach isn’t limited to PDFs. The same trick works to find a particular segment of a text or HTML document. I’ve got an open view (in the Search window text pane) of the desired portion of that referenced document.

Suppose I’d like to have more than one view of that referenced document open in a Search view, perhaps, for example, a reference to Huxley’s Brave New World. That’s easily accomplished by opening a second Search window and entering the ‘marker’ string to scroll to the page, e.g., page 72, that contains that ‘marker’ string.

Now I’ve got two open windows into that referenced document, displaying different portions of that document.

I showed this trick to an attorney. He tells me that he finds it very useful when he’s making notes about a court record. He can have open at the same time portions of the court record dealing with one side’s argument, the rebuttal by the opposing attorney and the judge’s comments and ruling on that issue. To switch among the views, he uses Exposé by swooping the cursor to the upper right corner of the screen, so that images of the open views are visible for selection. He makes his notes using DEVONnote, set to float its window above DEVONthink Pro and minimized to the Dock when he’s not using it. His comment: it’s a great set of tools for analysis of the strengths and weaknesses of arguments in a case. In addition to the court record, he’s also got at his fingertips many other references.

Yes, the Lookup approach isn’t as direct and convenient as a direct link to a particular page of a PDF; but it works, is available already and perhaps offers some advantages in its own way.

Nice hint, Bill!

Best, Charles

Nice hint, Bill. But is there a way to do something like this with an external app? I need to link from an outside app back into specific points of a DT document. Some of my pdfs are book-sized, and something like a page-level reference, or a reference to a Skim bookmark, would help a lot.

1 Like

Sure. If you can type into the external application, use an appropriate marker string (enclosed in quotation marks) for the desired page of the PDF.

For example, I just picked a string that’s unique to page 183 of a PDF. Typed that string into a Pages document. As Pages recognizes the Lookup Service of DT Pro 2, select the string (including the quotation marks) and press Command-/ (Lookup). A Search window opens in DT Pro 2 with the string entered. Press Return, then select the PDF. There’s page 183.

If the external application doesn’t recognize Services (e.g., MS Word), it’s necessary to copy the string (including the quotation marks) to the clipboard, return to DT Pro 2 and enter the string into the Search query field. Press Return, then select the PDF. There’s page 183.

As previously noted, this trick requires a bit of judgement to pick a string that’s unique to the desired page. Assuming the author of the document isn’t excessively redundant, that’s really not as difficult as it might seem. I can usually pick a string that works on the first try, sometimes ‘bridging’ the last portion of one sentence and the beginning portion of another.

That is going to be very useful, thank you very much!

Bill,

There is a part of your very helpful hint that seems a bit awkward for me. After I do the search for the marker string, and select the document I want, I am in the search window with the marker highlighted. Fine.

However, usually I then double click on the document name to get a new larger window, with a bigger font, that is easier for me to read and edit in. If I do this, I lose the place and the marker and then have to do a search within the new, larger, window.

So essentially I am searching twice. Is there a way around this redundancy? How do you do it?

Many thanks.

Mitchell

Fortunately, at age 77 I can still read fine print. :slight_smile:

However, I’ve sized my Search windows to the largest size possible on my 13-inch ModBook screen, and my documents open in the text pane with view set to Fit to Width. So almost all documents open in the text pane with font at a comfortable size for me.

Tip: Want to see a still larger view of that scrolled-to page? Press Command-F7 to enter Full Screen view. Afterwards, press that key combination once more, or the Escape key, to return to the Search window view.

I’ve put together a script that makes this workflow so much quicker. I prefer to read and annotate my PDFs in Skim.

It’s based on a modified version of a script that @ChristinWhite shared over in the topic Video Playback and Annotations.
Basically all I did was take their script, and then use find/replace to substitute words like “video” and “time” with “PDF” and “page”, then spent a couple minutes fixing errors. It’s not perfect, but its very close! Sometimes the page numbers are off by one.

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

# # Copy Markdown Link for DEVONthink PDF Open in Skim on Current Page
#
# This script will copy that URL as a markdown link in the format: [352](x-devonthink-item://45151EC1-8A15-4109-AFE9-1B4EA8C6DE2B?page=352)
#
# Created by [Christin White](http://christindwhite.com)
# and then heavily modified to work with Skim instead of VLC
#

# # Set Options
# 
# - `DatabaseName`     *text*: The name for the database to use, if a valid database is not found the front database will be used.
# - `parameter` *boolean*: this is leftover from the VLC version, but it breaks when deleted.
#
set DatabaseName to "Research"
set parameter to true

try
	# Get Reference URL from DEVONthink and Assemble Link
	set thePDF to GetPDFFromSkim(parameter)
	
	# Get Reference URL
	set TheReferenceURL to GetReferenceURLFromPath(thePDFPath of thePDF, DatabaseName)
	
	# Assemble Link
	set PageCodeURL to TheReferenceURL & "?page=" & (TheCurrentPage of thePDF)
	set PageCode to (TheCurrentPage of thePDF)
	set MarkdownLink to "[" & PageCode & "](" & PageCodeURL & ")"
	
	# Copy to Clipboard
	set the clipboard to MarkdownLink
on error ErrorMessage number ErrorNumber
	if the ErrorNumber is not -128 then display alert "DEVONthink" message ErrorMessage as warning
end try


# # GetReferenceURLFromPath
#
# Get the reference URL for a file in a specified or active database.
#
# Parameters:
# - `TheFilepath`  *text*: The path to the file.
# - `DatabaseName` *text*: That database to look in.
#
# Returns:
# - *text*: The Reference URL.
#
on GetReferenceURLFromPath(TheFilePath, DatabaseName)
	tell application id "DNtp"
		# Check if the database is valid, if not use the active database.
		if exists database DatabaseName then
			set TheRecordList to lookup records with path TheFilePath in database DatabaseName
		else
			display notification "The specified database wasn't found, trying the active database instead" subtitle "Invalid Database"
			set TheRecordList to lookup records with path TheFilePath
		end if
		
		# Make sure we found a matching record.
		if (count of TheRecordList) is greater than 0 then
			# A list could return more than one record such as if a file is indexed to more than one group. Use the first item but notify the user.
			if (count of TheRecordList) is greater than 1 then
				display notification "More than one record was found, using the first record" subtitle "Multiple Records"
			end if
			set TheReferenceURL to reference URL of item 1 of TheRecordList
			return TheReferenceURL
		else
			error "File not found in database."
		end if
	end tell
end GetReferenceURLFromPath


# # GetPDFFromSkim
#
# Gets metadata about the front PDF open in Skim
#
# Parameters:
# - `parameter` *boolean*: leftover from VLC.
#
# Returns:
# - *list* (indexed)
#   - `thePDFPath`     *text*: The path for front PDF.
#   - `TheCurrentPage` *number*: The current page of playback.
on GetPDFFromSkim(parameter)
	tell application "Skim"
		if (exists path of front document) then
			set thePDFPath to path of front document
			set TheCurrentPage to index of current page of the front document
		else
			error "Skim does not have a PDF open."
		end if
		
		return {thePDFPath:thePDFPath, TheCurrentPage:TheCurrentPage}
	end tell
end GetPDFFromSkim
1 Like