This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
software:musicpdf:dev [2009/10/15 06:50] – admin | software:musicpdf:dev [2009/10/27 01:24] (current) – admin | ||
---|---|---|---|
Line 6: | Line 6: | ||
Please install [[http:// | Please install [[http:// | ||
< | < | ||
+ | ; MusicPDF, Automatic cleaning and leveling pdf files with Neuratron | ||
+ | ; Copyright (C) Oktober 2009 by Marc Nijdam | ||
+ | ; | ||
+ | ; 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 3 of the License, or | ||
+ | ; 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. | ||
+ | ; GNU General Public License for more details. | ||
+ | ; | ||
+ | ; You should have received a copy of the GNU General Public License | ||
+ | ; along with this program. | ||
+ | ; | ||
+ | ; Contact details: http:// | ||
+ | |||
+ | # | ||
+ | |||
#include < | #include < | ||
#include < | #include < | ||
Line 14: | Line 34: | ||
#Include < | #Include < | ||
- | # | + | ; Current version |
- | ; Automate Neuratron Photoscore, written by Marc Nijdam, Oktober 2009 | + | |
- | + | ||
- | ; $CmdLine[0] = number | + | |
- | ; $CmdLine[1] = first parameter | + | |
- | + | ||
- | ; Compatible | + | |
- | ; The slider for Pending Pages should be beginning just under the middle of the configuration settings wheel. | + | |
; | ; | ||
- | ; Requires Imagemagick installation from http:// | + | ; Requires Imagemagick installation from http:// |
; Path environment variable should be pointing to imagemagick, | ; Path environment variable should be pointing to imagemagick, | ||
- | ; If not it the following | + | ; If not there, this script adds the following |
; | ; | ||
- | ; Requires Ghostview, which may be installed through Photoscore. | + | ; This program requires Ghostscript, which may be installed through Photoscore. |
; Path environment variable should be pointing to: %PROGRAMFILES%\gs\gs8.56\bin; | ; Path environment variable should be pointing to: %PROGRAMFILES%\gs\gs8.56\bin; | ||
; | ; | ||
- | ; Does this solve a R6034 error - http:// | + | ; This solve a R6034 (AutoIt3 related) |
+ | ; http:// | ||
; | ; | ||
- | ; Write an environment variable | + | ; Nb.: |
- | ; EnvSet ( " | + | ; Write an environment variable: EnvSet ( " |
- | ; Code snippet: | + | |
; ControlClick($parentWindowName," | ; ControlClick($parentWindowName," | ||
- | ; Debug optie: ConsoleWrite(" | + | ; $CmdLine[0] = number of parameters |
- | ; ConsoleWrite(" | + | ; $CmdLine[1] |
- | ; Set program run environment. During code development it is easier if this program takes set input output files | + | |
- | Const $envDebug | + | |
Const $NeuratronVersion = " | Const $NeuratronVersion = " | ||
Const $Version6 = " | Const $Version6 = " | ||
- | Const $ThisProgramVersion = "0.9.0" ; Current release of this software | + | Const $ThisProgramVersion = "0.9.3" ; Current release of this software |
Const $_ERROR_MissingImageMagickObject = -1 | Const $_ERROR_MissingImageMagickObject = -1 | ||
Const $_ERROR_PdfInputFileIsNotValid = -2 | Const $_ERROR_PdfInputFileIsNotValid = -2 | ||
Line 56: | Line 68: | ||
Const $_ERROR_MSVisualCPlusPlus2008RedistNotInstalled = -12 | Const $_ERROR_MSVisualCPlusPlus2008RedistNotInstalled = -12 | ||
- | Const $Gui_Width = 300 | + | Const $Gui_Title = "PDF Sheetmusic raw scan Processor" |
+ | Const $Gui_Xpos = 140 | ||
+ | Const $Gui_Ypos = 23 | ||
+ | Const $Gui_Width = 518 | ||
Const $Gui_Height = 200 | Const $Gui_Height = 200 | ||
Const $Gui_Border = 15 | Const $Gui_Border = 15 | ||
Line 64: | Line 79: | ||
Const $img_uniquename = " | Const $img_uniquename = " | ||
- | Const $img_width = 2480 ; constant in pixels, defining what the page width may be at most | + | Const $img_width = 2480 ; constant in pixels, defining what the page width may be at most when portrait modus is used |
- | Const $img_height = 3508 ; constant in pixels, defining what the page height may be at most | + | Const $img_height = 3508 ; constant in pixels, defining what the page height may be at most when portrait modus is used |
+ | Const $resolution = 300 ; Resolution in dpi | ||
+ | Const $img_dims[2] = [$img_width, | ||
+ | Const $rastering = 72 ; PDF rastering value | ||
+ | Const $pdf_dims[2] = [String(Int(($rastering*$img_width/ | ||
+ | Dim | ||
+ | Dim | ||
Const $img_empty_name = AddSlash(@TempDir) & $img_uniquename & " | Const $img_empty_name = AddSlash(@TempDir) & $img_uniquename & " | ||
Const $Pdf_tmp_FileName = AddSlash(@TempDir) & $img_uniquename & " | Const $Pdf_tmp_FileName = AddSlash(@TempDir) & $img_uniquename & " | ||
- | Const $QQ='"' | + | Const $QQ = '"' |
+ | Const $SQ = "'" | ||
+ | Dim $szDrive, $szDir, $szFName, $szExt | ||
+ | Dim $i , $j | ||
Const $X_firstItem_Sel = 1 ; neuratron buttons window positions | Const $X_firstItem_Sel = 1 ; neuratron buttons window positions | ||
Const $X_firstItem_Del = 2 ; neuratron buttons window positions | Const $X_firstItem_Del = 2 ; neuratron buttons window positions | ||
Const $Y_firstItem = 3 ; neuratron buttons window positions | Const $Y_firstItem = 3 ; neuratron buttons window positions | ||
- | Const $NeuratronDelay = 5 ; loop is breaked when it runs for more than 5 seconds | + | Const $NeuratronDelay = 10 ; loop is breaked when it runs for more than 10 seconds |
Const $Pdf_ListOfFiles2Proces = AddSlash(@TempDir) & $img_uniquename & " | Const $Pdf_ListOfFiles2Proces = AddSlash(@TempDir) & $img_uniquename & " | ||
Line 105: | Line 130: | ||
; Parse program start options | ; Parse program start options | ||
- | If $envDebug | + | If @Compiled == 0 Then ; $envDebug == True means Program runs in Debug mode |
; Dim $Pdf_InputFile = " | ; Dim $Pdf_InputFile = " | ||
; Dim $Pdf_InputFile = " | ; Dim $Pdf_InputFile = " | ||
Line 118: | Line 143: | ||
; Dim $Pdf_InputFile = " | ; Dim $Pdf_InputFile = " | ||
; Dim $Pdf_InputFile = " | ; Dim $Pdf_InputFile = " | ||
- | Dim $Pdf_InputFile = " | + | ; Dim $Pdf_InputFile = " |
+ | ; Dim $Pdf_InputFile = " | ||
+ | Dim $Pdf_InputFile = " | ||
Dim $Pdf_OutputFile = " | Dim $Pdf_OutputFile = " | ||
$Pdf_InputFile = AddSlash(@WorkingDir) & $Pdf_InputFile ; Add absolute path to filename. | $Pdf_InputFile = AddSlash(@WorkingDir) & $Pdf_InputFile ; Add absolute path to filename. | ||
Line 130: | Line 157: | ||
Case 1 | Case 1 | ||
Dim $Pdf_InputFile = $CmdLine[1] ; inputfile | Dim $Pdf_InputFile = $CmdLine[1] ; inputfile | ||
- | local $szDrive, $szDir, $szFName, $szExt | ||
_PathSplit($Pdf_InputFile, | _PathSplit($Pdf_InputFile, | ||
Dim $Pdf_OutputFile = '"' | Dim $Pdf_OutputFile = '"' | ||
Line 144: | Line 170: | ||
Opt(" | Opt(" | ||
HotKeySet(" | HotKeySet(" | ||
- | GUICreate("PDF Sheetmusic raw scan Processor" | + | GUICreate($Gui_Title, |
$nEdit = GUICtrlCreateEdit ("", | $nEdit = GUICtrlCreateEdit ("", | ||
GUICtrlSetBkColor($nEdit, | GUICtrlSetBkColor($nEdit, | ||
Line 160: | Line 186: | ||
_RunDos(" | _RunDos(" | ||
$Param_Command = OpenFileAndGrep(AddSlash(@TempDir) & $img_uniquename & " | $Param_Command = OpenFileAndGrep(AddSlash(@TempDir) & $img_uniquename & " | ||
- | |||
If Not $Param_Command Then ; The supplied file is not an pdf file, exit program | If Not $Param_Command Then ; The supplied file is not an pdf file, exit program | ||
ShowError ($_ERROR_PdfInputFileIsNotValid) | ShowError ($_ERROR_PdfInputFileIsNotValid) | ||
Line 169: | Line 194: | ||
Const $PdfPagesCount = Number(StringReplace($Param_Command, | Const $PdfPagesCount = Number(StringReplace($Param_Command, | ||
GUICtrlSetData($nEdit, | GUICtrlSetData($nEdit, | ||
- | |||
; ############################################################################################################## | ; ############################################################################################################## | ||
; # Preprocessing scanned pages | ; # Preprocessing scanned pages | ||
Line 185: | Line 209: | ||
; # Empty pages, holding no data, give no output from the Identify command | ; # Empty pages, holding no data, give no output from the Identify command | ||
; ############################################################################################################## | ; ############################################################################################################## | ||
- | |||
Dim $PagesStats | Dim $PagesStats | ||
GUICtrlSetData($nEdit, | GUICtrlSetData($nEdit, | ||
- | Dim $width_largest | + | $max_dims[0] |
- | Dim $height_largest | + | $max_dims[1] |
Dim $img_dimensions | Dim $img_dimensions | ||
Dim $img_scale = False ; False means scaling is not necessary, because image fits within $img_width and $img_height | Dim $img_scale = False ; False means scaling is not necessary, because image fits within $img_width and $img_height | ||
Dim $img_greyconverted = False ; False means image has not been converted from black and white to grey scale | Dim $img_greyconverted = False ; False means image has not been converted from black and white to grey scale | ||
+ | Dim $PaperOrientation[$PdfPagesCount] ; Store page orientation for each page, 0 means portrait, 1 means landscape | ||
; Extract all pages from document to single pdf pages | ; Extract all pages from document to single pdf pages | ||
for $i = 1 To $PdfPagesCount | for $i = 1 To $PdfPagesCount | ||
Line 202: | Line 225: | ||
; From pdf file extract a single pdf page (as pdf) | ; From pdf file extract a single pdf page (as pdf) | ||
- | $Param_Command = $QQ & " | + | $Param_Command = $QQ & " |
- | " | + | $QQ & " |
+ | $QQ & "-dQUIET" & $QQ & " " & _ | ||
+ | $QQ & "-dBATCH" & $QQ & " | ||
+ | $QQ & " | ||
+ | $QQ & " | ||
$QQ & " | $QQ & " | ||
$QQ & " | $QQ & " | ||
$QQ & " | $QQ & " | ||
$QQ & $Pdf_InputFile & $QQ | $QQ & $Pdf_InputFile & $QQ | ||
- | |||
_RunDos(" | _RunDos(" | ||
Line 216: | Line 242: | ||
If StringInStr($PagesStats, | If StringInStr($PagesStats, | ||
GUICtrlSetData($nEdit, | GUICtrlSetData($nEdit, | ||
- | $oIMG.Convert(" | + | $oIMG.Convert(" |
$oIMG.Mogrify(" | $oIMG.Mogrify(" | ||
$img_greyconverted = True | $img_greyconverted = True | ||
Else | Else | ||
- | $oIMG.Convert(" | + | $oIMG.Convert(" |
EndIf | EndIf | ||
FileDelete($ThisFileName); | FileDelete($ThisFileName); | ||
Line 228: | Line 254: | ||
$img_dimensions = DOSResult(" | $img_dimensions = DOSResult(" | ||
+ | $this_dims[0] = Number(StringRegExpReplace($img_dimensions, | ||
+ | $this_dims[1] = Number(StringRegExpReplace($img_dimensions, | ||
- | If Number(StringRegExpReplace($img_dimensions, | + | If $this_dims[0] <= $this_dims[1] Then ; Normal portrait modus. |
- | $width_largest = Number(StringRegExpReplace($img_dimensions, | + | $PaperOrientation[$i-1] = 0 |
- | $img_scale = True ; Image doesn' | + | Else |
- | EndIf | + | GUICtrlSetData($nEdit, " |
- | + | $PaperOrientation[$i-1] | |
- | If Number(StringRegExpReplace($img_dimensions, "([0-9]+)x([0-9]+)", " | + | |
- | $height_largest = Number(StringRegExpReplace($img_dimensions, | + | |
- | $img_scale | + | |
EndIf | EndIf | ||
+ | ; $this_dims[$PaperOrientation[$i-1]] is always the short side | ||
+ | ; $this_dims[1-$PaperOrientation[$i-1]] is always the long side | ||
+ | ; $max_dims[0] carries always the maximum of the shorter side | ||
+ | ; $max_dims[1] carries always the maximum of the longer side | ||
+ | ; $j = 0 -> find the widest page for the short side | ||
+ | ; $j = 1 -> find the longest page for the long side | ||
+ | ; The BitXOR function will output only a logical 1 of two arguments are different. | ||
+ | For $j = 0 To 1 | ||
+ | If $this_dims[BitXOR($j, | ||
+ | $max_dims[$j] = $this_dims[BitXOR($j, | ||
+ | $img_scale = True ; Image doesn' | ||
+ | EndIf | ||
+ | Next | ||
Next | Next | ||
+ | |||
; # If there were one or more images exceeding size limit, scale them all with the same percentage. | ; # If there were one or more images exceeding size limit, scale them all with the same percentage. | ||
If $img_scale Then | If $img_scale Then | ||
- | Dim $resize_scale | + | Dim $resize_scale = Calc_scalingfactor($max_dims[0],$max_dims[1],$img_dims[0],$img_dims[1]); calculate scaling percentage |
- | $resize_scale = Calc_scalingfactor($width_largest,$height_largest,$img_width,$img_height); calculate scaling percentage | + | If $resize_scale < 50 Then |
- | If $resize_scale < 25 Then ; Resizing to less than 50 % is kind of silly. | + | |
; Remove previous orphans | ; Remove previous orphans | ||
For $i = 1 To $PdfPagesCount ; Delete all files we don't need anymore | For $i = 1 To $PdfPagesCount ; Delete all files we don't need anymore | ||
If FileExists(AddSlash(@TempDir) & $img_uniquename & Number($i) & " | If FileExists(AddSlash(@TempDir) & $img_uniquename & Number($i) & " | ||
Next | Next | ||
- | ShowError ($_ERROR_PdfImageSizeTooLarge) | + | ShowError($_ERROR_PdfImageSizeTooLarge) |
EndIf | EndIf | ||
- | |||
GUICtrlSetData($nEdit, | GUICtrlSetData($nEdit, | ||
- | + | For $i = 1 To $PdfPagesCount | |
- | ; Resize all tiff images. | + | |
- | for $i = 1 To $PdfPagesCount | + | |
GUICtrlSetData($nEdit, | GUICtrlSetData($nEdit, | ||
$oIMG.Mogrify(" | $oIMG.Mogrify(" | ||
Next | Next | ||
EndIf | EndIf | ||
- | |||
- | ; # If one of the previous operations changed the image, it's necessary to merge these images into a pdf file. | ||
If $img_greyconverted or $img_scale Then | If $img_greyconverted or $img_scale Then | ||
Line 270: | Line 303: | ||
$FHandle = FileOpen($Pdf_ListOfFiles2Proces, | $FHandle = FileOpen($Pdf_ListOfFiles2Proces, | ||
- | $oIMG.Convert(""," | ||
for $i = 1 To $PdfPagesCount | for $i = 1 To $PdfPagesCount | ||
+ | $oIMG.Convert(""," | ||
GUICtrlSetData($nEdit, | GUICtrlSetData($nEdit, | ||
$SourceFile = AddSlash(@TempDir) & $img_uniquename & Number($i) | $SourceFile = AddSlash(@TempDir) & $img_uniquename & Number($i) | ||
- | ; Note that the Composite command generates a black and white canvas, therefore the resulting image will lose also any bit depth. Not a problem here, but it's just important to realise this. | + | ; Note that the Composite command generates a black and white canvas, therefore the resulting image may lose also any bit depth. Not a problem here, but it's just important to realise this. |
- | $oIMG.Composite($SourceFile & " | + | $oIMG.Composite($SourceFile & " |
- | $oIMG.Convert(" | + | $oIMG.Convert(" |
- | _RunDos(" | + | _RunDos(" |
FileWriteLine($FHandle, | FileWriteLine($FHandle, | ||
FileDelete($SourceFile & " | FileDelete($SourceFile & " | ||
- | FileDelete($SourceFile & "_temp.ps") | + | FileDelete($SourceFile & " |
FileDelete($SourceFile & " | FileDelete($SourceFile & " | ||
Next | Next | ||
FileDelete($img_empty_name) | FileDelete($img_empty_name) | ||
FileClose($FHandle) | FileClose($FHandle) | ||
- | GUICtrlSetData($nEdit, | + | GUICtrlSetData($nEdit, |
; # Merge all pdf files into one pdf file | ; # Merge all pdf files into one pdf file | ||
MergePDF($Pdf_tmp_FileName, | MergePDF($Pdf_tmp_FileName, | ||
Line 302: | Line 336: | ||
; Overwrite Preferences with custom values | ; Overwrite Preferences with custom values | ||
SetNeuratronPrefs() | SetNeuratronPrefs() | ||
- | RemoveSomeTempFiles() | + | RemoveSomeTempFiles() |
; Neuratron 6 specific details like its Window Name. Execute the program as well. | ; Neuratron 6 specific details like its Window Name. Execute the program as well. | ||
Line 310: | Line 344: | ||
Const $programRunName = " | Const $programRunName = " | ||
; run the application | ; run the application | ||
- | GUICtrlSetData($nEdit, | + | GUICtrlSetData($nEdit, |
run($programRunName) | run($programRunName) | ||
- | sleep(3000) ; wait for Neuratron to become initialized | + | WinWaitNotActive |
+ | sleep(250) | ||
; wait until the window is showing, time out in 3 secs | ; wait until the window is showing, time out in 3 secs | ||
WinWaitActive($parentWindowName,"", | WinWaitActive($parentWindowName,"", | ||
Line 321: | Line 356: | ||
GUICtrlSetData($nEdit, | GUICtrlSetData($nEdit, | ||
Send(" | Send(" | ||
- | WinWaitActive($parentWindowName,"", | + | WinWaitActive($parentWindowName,"", |
Send(" | Send(" | ||
- | WinWaitActive($parentWindowName,"", | + | WinWaitActive(" |
; # If there had been no processing before, we can send the original file, otherwise send the processed file. | ; # If there had been no processing before, we can send the original file, otherwise send the processed file. | ||
If $img_greyconverted or $img_scale Then | If $img_greyconverted or $img_scale Then | ||
- | Send($Pdf_tmp_FileName) | + | Const $Pdf2Open = $Pdf_tmp_FileName |
Else | Else | ||
- | Send($Pdf_InputFile) | + | Const $Pdf2Open = $Pdf_InputFile |
EndIf | EndIf | ||
+ | Send($Pdf2Open) | ||
+ | Send(" | ||
+ | WinWaitNotActive(" | ||
- | WinWaitActive($parentWindowName,"", | + | ;WinWaitActive($parentWindowName,"", |
- | Send("{ENTER}") | + | _PathSplit($Pdf2Open, |
- | WinWaitActive($parentWindowName,"", | + | ; |
+ | WinWaitActive(" | ||
; ... and confirm 300 dpi resolution | ; ... and confirm 300 dpi resolution | ||
Send(" | Send(" | ||
- | |||
- | WinWaitActive($parentWindowName,"", | ||
- | |||
; Now wait for Progress Report window to get finished | ; Now wait for Progress Report window to get finished | ||
- | While Not WinActive($parentWindowName) | + | WinWaitNotActive(" |
- | WEnd | + | |
- | + | GUICtrlSetData($nEdit, | |
- | for $i=1 to $PdfPagesCount | + | ; Check whether Windowfocus is stable: Count timer, reset if window is not active and exitloop if timer exceeds $NeuratronDelay. |
- | GUICtrlSetData($nEdit, | + | ; |
- | $begin = TimerInit() | + | $begin = TimerInit() |
- | While WinActive($parentWindowName) | + | While 1 |
- | if TimerDiff($begin)/ | + | If Not WinActive($parentWindowName) Then $begin = TimerInit() |
- | ExitLoop | + | If TimerDiff($begin)/ |
- | EndIf | + | |
- | WEnd | + | |
- | $begin = TimerInit() | + | |
- | While Not WinActive($parentWindowName) | + | |
- | if TimerDiff($begin)/ | + | |
- | ExitLoop | + | |
- | EndIf | + | |
- | WEnd | + | |
- | Next | + | |
- | + | ||
- | Sleep(1000) | + | |
- | ; Now wait for Progress Report window to get finished | + | |
- | While Not WinActive($parentWindowName) | + | |
WEnd | WEnd | ||
+ | WinWaitActive($parentWindowName,"", | ||
; move slider to the top. | ; move slider to the top. | ||
Opt(" | Opt(" | ||
Line 385: | Line 406: | ||
Sleep(1000) | Sleep(1000) | ||
- | |||
; save from all pdf pages, each image as tiff ... | ; save from all pdf pages, each image as tiff ... | ||
for $i = 1 To $PdfPagesCount | for $i = 1 To $PdfPagesCount | ||
Line 396: | Line 416: | ||
Send(" | Send(" | ||
sleep(400) | sleep(400) | ||
- | |||
If $i < $PdfPagesCount Then ; last time clicking is not needed | If $i < $PdfPagesCount Then ; last time clicking is not needed | ||
MouseClick(" | MouseClick(" | ||
Line 405: | Line 424: | ||
EndIf | EndIf | ||
WEnd | WEnd | ||
+ | WinWaitActive($parentWindowName, | ||
MouseClick(" | MouseClick(" | ||
EndIf | EndIf | ||
Line 417: | Line 437: | ||
GUICtrlSetData($nEdit, | GUICtrlSetData($nEdit, | ||
MouseClick(" | MouseClick(" | ||
- | sleep(1200) | + | sleep(800) |
MouseClick(" | MouseClick(" | ||
Send(" | Send(" | ||
- | sleep(600) | + | sleep(300) |
Next | Next | ||
- | GUICtrlSetData($nEdit, | + | GUICtrlSetData($nEdit, |
Send(" | Send(" | ||
sleep(400) | sleep(400) | ||
Line 432: | Line 452: | ||
; # Finished with Neuratron | ; # Finished with Neuratron | ||
; ################################################################################################################# | ; ################################################################################################################# | ||
- | ; Convert each tiff page to an pdf page. | + | ; Below is for portrait paper orientation: |
+ | ; Convert each tiff page to a pdf page. | ||
; Convert -size 2480x3508 xc:white miff: | ; Convert -size 2480x3508 xc:white miff: | ||
; composite -density 300 -units PixelsPerInch -compose atop -gravity Center / | ; composite -density 300 -units PixelsPerInch -compose atop -gravity Center / | ||
; convert -monochrome -density 300 -units PixelsPerInch - ps:- | ; convert -monochrome -density 300 -units PixelsPerInch - ps:- | ||
; ps2pdf13 -sPAPERSIZE=a4 - "/ | ; ps2pdf13 -sPAPERSIZE=a4 - "/ | ||
+ | ; | ||
+ | ; There is a problem with ImageMagick writing directly to pdf, not outputting in the proper colorspace (grey instead of black and white). A solution is to write first to ps and then use ps2pdf. | ||
+ | ; The solution to specify the page size is done with the following example: | ||
+ | ; gswin32c.exe -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=outgsr.pdf -dDEVICEWIDTHPOINTS=842 -dDEVICEHEIGHTPOINTS=595 outr.ps | ||
+ | ; See: http:// | ||
If FileExists($Pdf_ListOfFiles2Proces) Then | If FileExists($Pdf_ListOfFiles2Proces) Then | ||
FileDelete($Pdf_ListOfFiles2Proces) | FileDelete($Pdf_ListOfFiles2Proces) | ||
Line 443: | Line 468: | ||
$FHandle = FileOpen($Pdf_ListOfFiles2Proces, | $FHandle = FileOpen($Pdf_ListOfFiles2Proces, | ||
GUICtrlSetData($nEdit, | GUICtrlSetData($nEdit, | ||
- | $oIMG.Convert(""," | ||
for $i = 1 To $PdfPagesCount | for $i = 1 To $PdfPagesCount | ||
+ | $oIMG.Convert(""," | ||
GUICtrlSetData($nEdit, | GUICtrlSetData($nEdit, | ||
$SourceFile = AddSlash(@TempDir) & $img_uniquename & Number($i) | $SourceFile = AddSlash(@TempDir) & $img_uniquename & Number($i) | ||
- | $oIMG.Composite($SourceFile & " | + | $oIMG.Composite($SourceFile & " |
- | $oIMG.Convert(" | + | $oIMG.Convert(" |
- | _RunDos(" | + | _RunDos(" |
FileWriteLine($FHandle, | FileWriteLine($FHandle, | ||
- | FileDelete($SourceFile & " | ||
FileDelete($SourceFile & " | FileDelete($SourceFile & " | ||
+ | FileDelete($SourceFile & " | ||
FileDelete($SourceFile & " | FileDelete($SourceFile & " | ||
+ | |||
Next | Next | ||
FileDelete($img_empty_name) | FileDelete($img_empty_name) | ||
If $img_greyconverted or $img_scale Then FileDelete($Pdf_tmp_FileName) | If $img_greyconverted or $img_scale Then FileDelete($Pdf_tmp_FileName) | ||
FileClose($FHandle) | FileClose($FHandle) | ||
- | GUICtrlSetData($nEdit, | + | GUICtrlSetData($nEdit, |
- | MergePDF($Pdf_OutputFile , | + | MergePDF(UniqueFileName($Pdf_OutputFile) , |
Sleep(1500) | Sleep(1500) | ||
GUIDelete() | GUIDelete() | ||
Line 468: | Line 494: | ||
; # | ; # | ||
; ############################################################################################################## | ; ############################################################################################################## | ||
- | ; Capture console output into string | + | |
- | Func DOSResult($DR_LINE) | + | Func DOSResult(Const $DR_LINE) |
_RunDOS($DR_LINE & " > " & @TempDir & " | _RunDOS($DR_LINE & " > " & @TempDir & " | ||
- | $DR_FILE = FileOpen(@TempDir & " | + | Local $DR_FILE = FileOpen(@TempDir & " |
- | $DR_RESULT = FileRead($DR_FILE) | + | Local $DR_RESULT = FileRead($DR_FILE) |
FileDelete(@TempDir & " | FileDelete(@TempDir & " | ||
FileClose($DR_FILE) | FileClose($DR_FILE) | ||
Line 480: | Line 506: | ||
; merge pdf pages into one pdf page and deletes intermediate files | ; merge pdf pages into one pdf page and deletes intermediate files | ||
Func MergePDF(Const $PDFFILE, Const $PDFFILE_list) | Func MergePDF(Const $PDFFILE, Const $PDFFILE_list) | ||
- | _RunDos(" | + | _RunDos(" |
FileDelete(@TempDir & " | FileDelete(@TempDir & " | ||
FileDelete($PDFFILE_list) | FileDelete($PDFFILE_list) | ||
Line 486: | Line 512: | ||
; Opens a file and returns a line which contains a specified keyword | ; Opens a file and returns a line which contains a specified keyword | ||
- | Func OpenFileAndGrep($OFAG_path, | + | Func OpenFileAndGrep(Const $OFAG_path,Const $OFAG_query) |
- | $OFAG_file = FileOpen($OFAG_path, | + | Local $OFAG_file = FileOpen($OFAG_path, |
- | $OFAG_result = FileRead($OFAG_file) | + | Local $OFAG_result = FileRead($OFAG_file) |
FileClose($OFAG_file) | FileClose($OFAG_file) | ||
Line 494: | Line 520: | ||
Return | Return | ||
Else | Else | ||
- | $OFAG_q = "" | + | Local $OFAG_q = "" |
- | $OFAG_stdinArray = StringSplit($OFAG_result, | + | Local $OFAG_stdinArray = StringSplit($OFAG_result, |
+ | Local $OFAG_i | ||
For $OFAG_i In $OFAG_stdinArray | For $OFAG_i In $OFAG_stdinArray | ||
If StringInStr($OFAG_i, | If StringInStr($OFAG_i, | ||
Line 715: | Line 742: | ||
; | ; | ||
RegWrite(" | RegWrite(" | ||
- | RegWrite(" | + | RegWrite(" |
RegWrite(" | RegWrite(" | ||
RegWrite(" | RegWrite(" | ||
Line 972: | Line 999: | ||
Func RemoveSlash(Const $var) | Func RemoveSlash(Const $var) | ||
Return StringRegExpReplace($var, | Return StringRegExpReplace($var, | ||
+ | EndFunc | ||
+ | |||
+ | ; This function will remove a trailing slash to a windows file path | ||
+ | Func RemoveDoubleQuotes(Const $var) | ||
+ | Return StringRegExpReplace($var, | ||
EndFunc | EndFunc | ||
Line 1018: | Line 1050: | ||
Func RemoveSomeTempFiles() | Func RemoveSomeTempFiles() | ||
If FileExists(AddSlash(@TempDir) & $img_uniquename & " | If FileExists(AddSlash(@TempDir) & $img_uniquename & " | ||
+ | EndFunc | ||
+ | |||
+ | ; Prevent overwriting a file, when it already exists. This function will find the ' | ||
+ | Func UniqueFileName(Const $Pdf_OutputFile) | ||
+ | If FileExists(RemoveDoubleQuotes($Pdf_OutputFile)) Then | ||
+ | Local $i = 1 | ||
+ | Local $szDrive, $szDir, $szFName, $szExt | ||
+ | _PathSplit(RemoveDoubleQuotes($Pdf_OutputFile), | ||
+ | While FileExists($szDrive & $szDir & $szFName & " | ||
+ | $i += 1 | ||
+ | WEnd | ||
+ | Return $QQ & $szDrive & $szDir & $szFName & " | ||
+ | Else | ||
+ | Return $Pdf_OutputFile | ||
+ | EndIf | ||
EndFunc | EndFunc | ||