topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 10:08 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: [DONE] lightweight pdf viewer and editor  (Read 13427 times)

kalos

  • Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 1,823
    • View Profile
    • Donate to Member
[DONE] lightweight pdf viewer and editor
« on: November 05, 2012, 12:33 PM »
hello!

most of the times i open a pdf, i only want to read it and not edit it

that's why my default pdf viewer is sumatrapdf, which is very fast at opening and rendering pdf files, which unfortunately doesnt offer any editing features

for editing, i use nitropdf, which unfortunately is very slow at opening a pdf file

so, i would like to have the fastest possible pdf viewer as default app to handle pdf files (mupdf would be better, since it's the ultimate fast app) and with a click of a button to bring up the editing features (even if I have to wait a bit)

thanks!

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #1 on: November 05, 2012, 01:16 PM »
I think this Autohotkey script will do what you want. Run it and then press F4 (or change it to some other hotkey) when Sumaptra is active to open the same document in nitro. You only need to change [path_to_nitro_folder] to whatever folder you have nitropdf installed in.
#IfWinActive, ahk_class SUMATRA_PDF_FRAME
F4::
clipsave := ClipBoardAll
clipboard =
send ^d  ;open file properties
winwaitactive, Document Properties
send ^c  ;copy properties
clipwait
send {esc}
RegExMatch(clipboard, "U)File: (.*\.pdf)\R",xpath)  ;put pdf file path in variable
if xpath1 !=
 run [path_to_nitro_folder]\NitroPDF.exe "%xpath1%"
clipboard := clipsave
return
#IfWinActive
edit: fixed regex code and made run conditional on finding a matching pdf file (not epub or any other file type that Sumatra also supports)
« Last Edit: November 05, 2012, 04:02 PM by Nod5 »

kalos

  • Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 1,823
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #2 on: November 05, 2012, 01:53 PM »
wow, this is great, thanks!

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #3 on: November 05, 2012, 04:00 PM »
Glad you like it. I updated the code with a small improvement.

kalos

  • Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 1,823
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #4 on: November 06, 2012, 06:49 PM »
Glad you like it. I updated the code with a small improvement.
  :Thmbsup:

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #5 on: November 07, 2012, 03:48 AM »
I could use this too!

Adobe Reader is my default PDF reader.
Occasionally I then want to open the PDF in PDF-Xchange

so I tried changed window class to
ADOBE_PDF_FRAME
and put in the PDF-Xchange path in place of Nitro (there's no spaces in. Also it's the portable version)

I also had to change the F4 as that is used in Adobe Reader - I tried a couple, have F12 now.

Maybe I have the window class wrong? This doesnt work either:
ADOBEREADER_PDF_FRAME

TIA
Tom

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,612
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #6 on: November 07, 2012, 05:03 AM »
Maybe I have the window class wrong? This doesnt work either:
ADOBEREADER_PDF_FRAME
Be sure to check the exact Window ClassName using the Window spy/info tool that comes installed with AHK. And, these names are usually checked case-sensitive.

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #7 on: November 07, 2012, 06:13 AM »
mmm [scratches head]  :-\

I found the window class:
AcrobatSDIWindow

All shortcuts now have an effect, but not as planned:
They open the 'Document Properties' window (within Adobe Reader). Once. If I close the properties window, the key kombo has no effect next time.

(These shortcuts otherwise have no effect, i.e. only have an effect when the script is running.)

What with Adobe wanting to take over the world (who doesn't these days) it wouldn't suprise me that they somehow block any 'meddling'.

If you've any ideas, let me know. It's not so important to me, but always interesting to learn a little :-)
Tom

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,612
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #8 on: November 07, 2012, 08:21 AM »
They open the 'Document Properties' window (within Adobe Reader). Once. If I close the properties window, the key kombo has no effect next time.
Does this have anything to do with the actual input focus? Maybe if you click inside the PDF document, the hotkey for Document Properties (^d ?? not sure, don't have that pdf reader installed...) starts to work again? Adobe Reader is MDI, AFAIK, and pressing the hotkey outside of a pdf document probably does nothing.

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #9 on: November 07, 2012, 09:21 AM »
IIUC the next step in the script is to copy the file path from properties -
this seems to be not possible with adobe -
see the file properties dialogue:

Screenshot - 2012-11-07 , 16_15_21.png[DONE] lightweight pdf viewer and editor

the tab 'Description' has focus - but I dont see anyway of copying the file path cause it isn't shown in one string anywhere in the properties...
Tom

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,612
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #10 on: November 07, 2012, 09:41 AM »
Location:  F:\Documents\Paperwork\unreadable-name.pdf perhaps?  :tellme:

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #11 on: November 07, 2012, 02:55 PM »
Location:  F:\Documents\Paperwork\unreadable-name.pdf perhaps?  :tellme:

you mean Adobe couldnt read my screenshot either ??? :D
Tom

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #12 on: November 07, 2012, 03:30 PM »
Try this tomos (I have tested it in Acrobat but not Acrobat Reader)
#IfWinActive, ahk_class AcrobatSDIWindow
F12::
send ^d  ;open file properties
winwaitactive, Document Properties
ControlGetText, xname, Static2, Document Properties
ControlGetText, xpath, Static18, Document Properties
send {esc}
ifexist %xpath%%xname%
 run [full path to pdf-xchange here] "%xpath%%xname%"
return
#IfWinActive
If it doesn't work, open Document Properties in Acrobat Reader and also open AU3_Spy that comes with Autohotkey. Hold the mouse over the filename in the properties window and check the ClassNN value in AU3_Spy. Replace Static2 above with that value. Repeat for the file path part of the properties window.

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,959
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #13 on: November 07, 2012, 04:17 PM »
Works out of the box :-*

many thanks Nod5 :Thmbsup:
Tom

Attronarch

  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 147
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #14 on: November 07, 2012, 04:48 PM »
I think this Autohotkey script will do what you want. Run it and then press F4 (or change it to some other hotkey) when Sumaptra is active to open the same document in nitro. You only need to change [path_to_nitro_folder] to whatever folder you have nitropdf installed in.

Spoiler
#IfWinActive, ahk_class SUMATRA_PDF_FRAME
F4::
clipsave := ClipBoardAll
clipboard =
send ^d  ;open file properties
winwaitactive, Document Properties
send ^c  ;copy properties
clipwait
send {esc}
RegExMatch(clipboard, "U)File: (.*\.pdf)\R",xpath)  ;put pdf file path in variable
if xpath1 !=
 run [path_to_nitro_folder]\NitroPDF.exe "%xpath1%"
clipboard := clipsave
return
#IfWinActive


edit: fixed regex code and made run conditional on finding a matching pdf file (not epub or any other file type that Sumatra also supports)

Thank you for posting this piece of code. Extremely useful, since Sumatra doesn't lock in .pdf files, allowing editing and viewing at the same time.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #15 on: November 08, 2012, 09:27 AM »
Extremely useful, since Sumatra doesn't lock in .pdf files, allowing editing and viewing at the same time.
Nice! I just tested it with a pdf in Sumatra and editor side by side. And indeed as soon as changes are saved in the editor they immediately appear in Sumatra. If some pdf editor can be set to autosave on any change then we could have real-time updates in Sumatra.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: [DONE] lightweight pdf viewer and editor
« Reply #16 on: November 14, 2012, 08:35 AM »
Nice work, folks.  I'm going to set this one as done.  Thanks.