Last active
September 30, 2021 03:47
-
-
Save jca02266/55dcdd70d14b1a2c38aa49203bb6e79a to your computer and use it in GitHub Desktop.
WinMerge Plugin (convert PDF file to image file)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Install: | |
' Download poppler-0.68 from Poppler for Windows (http://blog.alivate.com.au/poppler-windows/) | |
' and extract it on the "C:\Program Files\WinMerge\MergePlugins\poppler-0.68" folder. | |
' | |
<scriptlet> | |
<implements type="Automation" id="dispatcher"> | |
<property name="PluginEvent"> | |
<get/> | |
</property> | |
<property name="PluginDescription"> | |
<get/> | |
</property> | |
<property name="PluginFileFilters"> | |
<get/> | |
</property> | |
<property name="PluginIsAutomatic"> | |
<get/> | |
</property> | |
<property name="PluginUnpackedFileExtension"> | |
<get/> | |
</property> | |
<method name="UnpackFile"/> | |
<method name="PackFile"/> | |
<method name="IsFolder"/> | |
<method name="UnpackFolder"/> | |
<method name="PackFolder"/> | |
</implements> | |
<script language="VBS"> | |
'///////////////////////////////////////////////////////////////////////////// | |
' This is a plugin for WinMerge. | |
' It will display the image of PDF pages. | |
' Copyright (C) 2021 Koji Arai | |
' | |
' This program is free software; you can redistribute it and/or modify | |
' it under the terms of the GNU General Public License as published by | |
' the Free Software Foundation; either version 2 of the License, or | |
' (at your option) any later version. | |
' | |
' This program is distributed in the hope that it will be useful, | |
' but WITHOUT ANY WARRANTY; without even the implied warranty of | |
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
' GNU General Public License for more details. | |
' | |
' You should have received a copy of the GNU General Public License | |
' along with this program; if not, write to the Free Software | |
' Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
' | |
Option Explicit | |
Const REGKEY_PATH = "HKCU\Software\Thingamahoochie\WinMerge" | |
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject") | |
Dim wsh: Set wsh = CreateObject("WScript.Shell") | |
Function regRead(Key, DefaultValue) | |
regRead = DefaultValue | |
On Error Resume Next | |
regRead = wsh.RegRead(Key) | |
End Function | |
Function get_PluginEvent() | |
get_PluginEvent = "FILE_FOLDER_PACK_UNPACK" | |
End Function | |
Function get_PluginDescription() | |
get_PluginDescription = "Display the image of PDF pages" | |
End Function | |
Function get_PluginFileFilters() | |
get_PluginFileFilters = "\.pdf(\..*)?$" | |
End Function | |
Function get_PluginIsAutomatic() | |
get_PluginIsAutomatic = True | |
End Function | |
Function get_PluginUnpackedFileExtension() | |
get_PluginUnpackedFileExtension = ".jpg" | |
End Function | |
Function UnpackFile(fileSrc, fileDst, pbChanged, pSubcode) | |
pbChanged = True | |
pSubcode = 0 | |
UnpackFile = True | |
End Function | |
Function PackFile(fileSrc, fileDst, pbChanged, pSubcode) | |
PackFile = False | |
End Function | |
Function IsFolder(file) | |
IsFolder = True | |
End Function | |
Function Enclose(path) | |
Enclose = """" & path & """" | |
End Function | |
Function UnpackFolder(fileSrc, folderDst, pbChanged, pSubcode) | |
If Not fso.FolderExists(folderDst) Then fso.CreateFolder folderDst | |
Run wsh, Enclose(GetPopplerExeFolder() & "\pdftoppm") & " -jpeg " & Enclose(fileSrc) & " " & Enclose(folderDst & "/file") | |
rem Run wsh, Enclose(GetPopplerExeFolder() & "\pdftocairo") & " -png " & Enclose(fileSrc) & " " & Enclose(folderDst & "/file") | |
rem Run wsh, Enclose(GetPopplerExeFolder() & "\pdftohtml") & " -jpeg " & Enclose(fileSrc) & " " & Enclose(folderDst & "/file") | |
pbChanged = True | |
pSubcode = 0 | |
UnpackFolder = True | |
End Function | |
Function PackFolder(fileSrc, folderDst, pbChanged, pSubcode) | |
PackFolder = False | |
End Function | |
Sub Run(sh, cmd) | |
sh.Run cmd, 1, True | |
End Sub | |
Function GetPopplerExeFolder() | |
Dim winMergeExePath | |
On Error Resume Next | |
winMergeExePath = "C:\Program Files\WinMerge\WinMergeU.exe" | |
winMergeExePath = wsh.RegRead(REGKEY_PATH & "\Executable") | |
GetPopplerExeFolder = fso.BuildPath(fso.GetParentFolderName(winMergeExePath), "MergePlugins\poppler-0.68.0\bin") | |
End Function | |
</script> | |
</scriptlet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment