3 Windows PDF view helper
4 Author: Uwe Stöhr and Joost Verburg
6 This will be installed as pdfview.exe.
8 The application will launch the default PDF viewer to display the PDF file,
9 but works around the file locking problems of Adobe Reader and Acrobat.
15 #doesn't work with the Uniode system.dll of NSIS 3.0.2
20 #--------------------------------
25 Icon "..\packaging\icons\lyx.ico"
28 #--------------------------------
29 # Windows Vista (and later) settings
31 RequestExecutionLevel user
33 #--------------------------------
49 #--------------------------------
52 !macro SystemCall STACK
54 # Call a Windows API function
57 CallInstDLL "$EXEDIR\System.dll" Call
61 !macro HideConsole COMMAND_LINE
63 # Run an application and hide console output
65 Push `${COMMAND_LINE}`
66 CallInstDLL "$EXEDIR\Console.dll" Exec
69 ${If} $RunAppReturn == "error"
70 MessageBox MB_OK|MB_ICONSTOP "Error opening PDF file $PDFFile."
75 #--------------------------------
78 Section "View PDF file"
80 InitPluginsDir # Temporary directory for PDF file
82 # Command line parameters
83 ${GetParameters} $OriginalFile
86 StrCpy $Character $OriginalFile 1
87 ${If} $Character == '"'
88 StrCpy $OriginalFile $OriginalFile "" 1
90 StrCpy $Character $OriginalFile 1 -1
91 ${If} $Character == '"'
92 StrCpy $OriginalFile $OriginalFile -1
95 GetFullPathName $OriginalFile $OriginalFile
96 ${GetFileName} $OriginalFile $OriginalFileName
97 ${GetParent} $OriginalFile $OriginalDir # tmpbuf
98 ${GetParent} $OriginalDir $OriginalDir # tmpdir
100 SetOutPath $TEMP # The LyX tmpbuf should not be locked
102 StrCpy $PDFFile $PLUGINSDIR\$OriginalFileName
104 # Check whether the file will be opened with Adobe Reader or Adobe Acrobat
105 !insertmacro SystemCall "shell32::FindExecutable(t '$OriginalFile', t '', t .s)"
107 ${GetFileName} $ViewerFileName $Viewer
110 MessageBox MB_OK|MB_ICONEXCLAMATION "No PDF viewer is installed. \
111 Please install a PDF viewer such as Adobe Reader."
115 ${if} $Viewer == "AcroRd32.exe"
116 ${orif} $Viewer == "AcroRd64.exe"
117 ${orif} $Viewer == "Acrobat.exe"
119 # get the version of Acrobat - currenly not necessary
120 GetDLLVersion $ViewerFileName $R0 $R1
122 IntOp $R2 $R2 & 0x0000FFFF ; $R2 now contains major version
123 #IntOp $R3 $R0 & 0x0000FFFF ; $R3 now contains minor version
125 #IntOp $R4 $R4 & 0x0000FFFF ; $R4 now contains release
126 #IntOp $R5 $R1 & 0x0000FFFF ; $R5 now contains build
127 StrCpy $ViewerVersion $R2
129 # check if there is a windows open containing the PDF
130 ${if} $Viewer == "AcroRd32.exe"
131 ${orif} $Viewer == "AcroRd64.exe"
132 ${if} $ViewerVersion > 14
133 FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat Reader DC"
135 FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Reader"
137 ${elseif} $Viewer == "Acrobat.exe"
138 FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat"
139 ${if} $ViewerHandle == "0"
140 FindWindow $ViewerHandle "" "$OriginalFileName - Adobe Acrobat Pro"
143 ${if} $ViewerHandle <> "0" # close the window
144 SendMessage $ViewerHandle 16 0 0
147 # Copy PDF to temporary file to allow LyX to overwrite the original
148 CopyFiles /SILENT $OriginalFile $PDFFile
151 !insertmacro HideConsole '"$ViewerFileName" "$PDFFile"'
155 # Another PDF viewer like GSView is used
156 # No need for special actions, just forward to ShellExecute
157 ExecShell open $OriginalFile