Skip to content

Commit

Permalink
Rename Master Branch DocTo (#131)
Browse files Browse the repository at this point in the history
* rename inputfilesexcel to inputfilesxl

* update testfiles

* Output file list

* debug log info and standardise logging of file conversion

* Fix bug where XL files are not converted to pdf because of from and to not specified.

* new test file
  • Loading branch information
tobya authored Jun 21, 2020
1 parent 2ccfb7e commit 9025f82
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 8 deletions.
19 changes: 17 additions & 2 deletions src/ExcelUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function TExcelXLSConverter.DestroyOfficeApp: boolean;
function TExcelXLSConverter.ExecuteConversion(fileToConvert: String; OutputFilename: String; OutputFileFormat : Integer): TConversionInfo;
var
NonsensePassword :OleVariant;
FromPage, ToPage : OleVariant;
ExitAction :TExitAction;
begin
//Excel is particuarily sensitive to having \\ at end of filename, eg it won't create file.
Expand Down Expand Up @@ -153,17 +154,31 @@ function TExcelXLSConverter.ExecuteConversion(fileToConvert: String; OutputFilen
end;
aSave: // Go ahead and save
begin

logdebug('PrintFromPage: ' + inttostr(pdfPrintFromPage),debug);
logdebug('PrintFromPage: ' + inttostr(pdfPrintToPage),debug);
//Unlike Word, in Excel you must call a different function to save a pdf and XPS.
if OutputFileFormat = xlTypePDF then
begin

if pdfPrintToPage > 0 then
begin
FromPage := pdfPrintFromPage;
ToPage := pdfPrintToPage;
end else
begin
FromPage := EmptyParam;
ToPage := EmptyParam;
end ;

ExcelApp.Application.DisplayAlerts := False ;
ExcelApp.activeWorkbook.ExportAsFixedFormat(XlFixedFormatType_xlTypePDF,
OutputFilename,
EmptyParam, //Quality
EmptyParam, // IncludeDocProperties,
False,// IgnorePrintAreas,
pdfPrintFromPage, // From,
pdfPrintToPage, // To,
FromPage , // From,
ToPage, // To,
pdfOpenAfterExport, // OpenAfterPublish, (default false);
EmptyParam// FixedFormatExtClassPtr
) ;
Expand Down
9 changes: 7 additions & 2 deletions src/MainUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,8 @@ function TDocumentConverter.Execute: string;
if ConversionInfo.Successful then
begin

logInfo('File Converted: ' + ConversionInfo.OutputFile);

// Check if file needs to be deleted.
if RemoveFileOnConvert then
begin
Expand Down Expand Up @@ -1133,8 +1135,11 @@ procedure TDocumentConverter.LoadConfig(Params: TStrings);
DoSubDirs := true;

ListFiles(finputfile, '*' + InputExtension,true,FInputFiles);

log('File List', FInputFiles,verbose);
if FInputFiles.Count = 0 then
begin
HaltWithError(204, 'No File Matches in Input Directory: ' + finputfile + '*' + InputExtension );
end;
log('File List', FInputFiles,STANDARD);
end
else
begin
Expand Down
1 change: 1 addition & 0 deletions src/PowerPointUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function TPowerPointConverter.ExecuteConversion(
OutputFilename: String;
OutputFileFormat: Integer): TConversionInfo;
begin
logDebug('Trying to Convert: ' + fileToConvert, Debug);

Result.Successful := false;
Result.InputFile := fileToConvert;
Expand Down
2 changes: 1 addition & 1 deletion src/WordUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function TWordDocConverter.ExecuteConversion(fileToConvert: String; OutputFilena
Result.Successful := true;
Result.OutputFile := OutputFilename;
Result.Error := '';
loginfo('FileCreated: ' + OutputFilename, STANDARD);
// loginfo('FileCreated: ' + OutputFilename, STANDARD);
finally
// Close the document - do not save changes if doc has changed in any way.
Wordapp.activedocument.Close(wdDoNotSaveChanges);
Expand Down
Binary file removed test/inputfilesexcel/Week 1 Test.xls
Binary file not shown.
Binary file modified test/inputfilespp/Presentation1.ppt
Binary file not shown.
Binary file modified test/inputfilespp/Presentation2.ppt
Binary file not shown.
Binary file removed test/inputfilespp/Presentation3.pptx
Binary file not shown.
Binary file added test/inputfilespp/campus map tower room.pptx
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file added test/inputfilesxl/Week 2 xlsx Test.xlsx
Binary file not shown.
33 changes: 33 additions & 0 deletions test/testDocTo_basic.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
REM Explanation
REM Test runs to check docto scenarios
REM execute docto inserting variables
REM %~d0 and %~p0 together give the full directory this batch file is executing in.


REM Remove all generated files from output directory that may exist.
del GeneratedFiles\*.* /q


REM Output Help Text
"../exe/docto.exe" -h


REM Try on Single
"../exe/docto.exe" -wd -f "%~d0%~p0Inputfiles\pie3.doc" -o "%~d0%~p0GeneratedFiles\Pie3Single.pdf" -T wdFormatPDF

REM Try on Single no output file with Verbose Logging
"../exe/docto.exe" -WD -f "%~d0%~p0Inputfiles\pie3.doc" -o "%~d0%~p0GeneratedFiles\SingleDir\" -T wdFormatText


REM try xl
"../exe/docto.exe" -XL -f "%~d0%~p0Inputfilesxl\Week 1 Test.xls" -o "%~d0%~p0GeneratedFiles\Week1.pdf" -T XLPDF

REM try xl
"../exe/docto.exe" -XL -f "%~d0%~p0Inputfilesxl\Week 1 Test.xls" -o "%~d0%~p0GeneratedFiles\Week1.csv" -T XLcsv

REM try xl
"../exe/docto.exe" -PP -f "%~d0%~p0Inputfilespp\Presentation1.ppt" -o "%~d0%~p0GeneratedFiles\pres1.pdf" -T ppSaveasPDF

REM try xl
"../exe/docto.exe" -PP -f "%~d0%~p0Inputfilespp\Presentation1.ppt" -o "%~d0%~p0GeneratedFiles\pres1.rtf" -T ppSaveasRTF

2 changes: 1 addition & 1 deletion test/testxls_relative.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REM Load xls from a relative path and convert to csv
"../exe/docto.exe" -XL -f "inputfilesexcel\Week 1 Test.xls" -o "GeneratedFiles\Week1.csv" -T xlCSV -l 10
"../exe/docto.exe" -XL -f "inputfilesxl\Week 1 Test.xls" -o "GeneratedFiles\Week1.csv" -T xlCSV -l 10
2 changes: 1 addition & 1 deletion test/testxlsfile.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REM Load csv files convert to xls
"../exe/docto.exe" -XL -f "C:\dev\github\docto\test\inputfilesexcel\Week 1 Test.xls" -o "C:\dev\github\docto\test\GeneratedFiles" -T xlPDF -l 10
"../exe/docto.exe" -XL -f "C:\dev\github\docto\test\inputfilesxl\Week 1 Test.xls" -o "C:\dev\github\docto\test\GeneratedFiles" -T xlPDF -l 10
2 changes: 1 addition & 1 deletion test/testxlspass.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REM Load csv files convert to xls
"../exe/docto.exe" -XL -f "C:\dev\github\docto\test\inputfilesexcel\Book1 with password.xls" -o "C:\dev\github\docto\test\GeneratedFiles" -T xlpdf -l 10
"../exe/docto.exe" -XL -f "C:\dev\github\docto\test\inputfilesxl\Book1 with password.xls" -o "C:\dev\github\docto\test\GeneratedFiles" -T xlpdf -l 10

0 comments on commit 9025f82

Please sign in to comment.