Open PDF at specified page

Previously I was able to open pdf documents at a given page,

Tell app "system events" to set getUrl to URL of alias posixPathPdf
Open location (getUrl & "#page=5" as text)

But this opens just the pdf, not anymore at the page I want


set pdfHFS to (choose file of type "com.adobe.pdf") as text

tell application "System Events" to set getUrl to URL of file pdfHFS
tell application "Safari" to open location getUrl & "#page=5"

When I attempted to run the script, the following command fails to even open the pdf document.

tell application "Safari" to open location getUrl & "#page=5")

The following command opened the pdf document, but did not open the document at page 5

open location getUrl & "#page=5")

I have test this script in Script Editor on Mojave and for me it works.

property pageNumber : "#page=150"

set theURL to "https://nathangrigg.com/images/2012/AppleScriptLanguageGuide.pdf"

tell application "Safari"
	make new document with properties {URL:(theURL & pageNumber)}
end tell

KniazidisR’s script works fine for me in Catalina.

There was no need to add a parenthesis to my script. I don’t know, it looks like it’s your carelessness. Or. trolling, which I will somehow survive.

KniazidisR,
Sorry for the confusion. The opening parenthesis was accidentally left out when I submitted the line of code. No trolling was intended.

Fredrik71,
When I ran your script, Safari successfully downloaded the pdf as a file. It however did open the pdf to the targeted page in the browser, or otherwise.

I am running Catalina.