Executing the FOP command line as batch from Perl - perl

I am converting XML to PDF using Apache. I am executing the FOP command line as batch file( since the input file will be vary) from Perl as like below:
Creating Batch file:
open (OUT2, '>', 'c:\test\fop-1.0\run.bat');
print OUT2 "cd\\\ncd c:\\test\\fop-1\.0\\\n C:\\test\\fop-1\.0\\fop\.bat -c C:\\test\\fop-1\.0\\conf\\fop-config\.xml -xsl C:\\test\\fop-1\.0\\test.xsl -xml c:\test\document2.xml -pdf c:\test\document2.pdf";
close (OUT2);
Executing batch file using system command:
$cmd2 ="c:\\test\\fop-1.0\\test.bat";
system("$cmd2");
I am embedding the svg files in the fop. I am getting the output when I run batch file manually, but by executing from perl I am getting the following error:
org.apache.fop.image.loader.batik.PreloaderSVG$Loader ge...
Can anyone help me to resolve this problem?

Try something like
system "cmd","/c","c:\\test\\fop-1.0\\test.bat";

Related

LibreOffice Command Line Convert CSV to DBF

I am working on a workflow where I need to be able to batch convert CSV files into DBF files. The data in the CSV files can all be output as TEXT fields and then saved as a DBF. I have tried to get any output possible using the command line in both Mac OS and Windows 7. While I was a little more successful in Windows, I was not able to get any conversion.
"C:\Program Files (x86)\LibreOffice 5\program\scalc.exe" --convert-to dbf --
infilter="csv:44,34,76,1,1/2/2/2/3/2/4/2/5/2/6/2/7/2/8/2/9/2/10/2/11/2/12/2/13/2/14/2/15/2/16/2/17/2/18/2/19/2/20/2/21/2/22/2/23/2/24/2/25/2/26/2/27/2/28/2/29/2/30/2/31/2/32/2
/33/2/34/2/35/2/36/2/37/2/38/2/39/2/40/2/41/2/42/2/43/2/44/2/45/2/46/2/47/2/48/2/49/2/50/2/51/2/52/2/53/2/54/2/55/2/56/2/57/2/58/2/59/2/60/2/61/2/62/2/63/2/64/2/65/2/66/2/67/2
/68/2/69/2/70/2/71/2,0,false,false" C:\Users\jdavidson\Desktop\DBFCONVERT\*.csv --outdir C:\Users\jdavidson\desktop\complete
So, I needed to have an --infilter on the command line to be able to do the conversion, but now it will only process 1 file and not batch file when using *.csv So, my next hurdle is to get over that.
The below helps to explain --infilters in more detail:
https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options#Filter_Options_for_Lotus.2C_dBase_and_DIF_Filters
Any easier way to find the filter sequence you need is by following the below listed steps:
Open the CSV Manually using LibreOffice and Specify Every Detail in the import Wizard
Run the below macro and it will show you the filter options in an input box, so you can copy the string in to your own code
Sub showFilterOptions
Dim args(),i%
args() = thisComponent.getArgs
for i = 0 to uBound(Args())
if args(i).Name = "FilterOptions" then inputbox "","",args(i).value
next
End Sub
Credit to code: https://forum.openoffice.org/en/forum/viewtopic.php?f=44&t=14018
The parameters need to be reversed. From https://ask.libreoffice.org/en/question/2641/convert-to-command-line-parameter/:
soffice --headless --convert-to <TargetFileExtension>:<NameOfFilter> file_to_convert.xxx
Using the old windows command prompt:
"C:\Program Files (x86)\LibreOffice 5\program\scalc.exe" --headless --convert-to dbf C:\Users\jdavidson\Desktop\DBFCONVERT\test.csv
This will create test.dbf in the current directory, which is perhaps C:\Users\jdavidson or, if running as administrator, C:\Windows\system32. To print the working directory, enter pwd, and then dir to see the file.
In powershell, add "& " in front to execute LibreOffice. Then enter gci or ls to see the file.
Be sure that a LibreOffice process is not already running in the background.
I was able to get this to work using the below code:
"C:\Program Files (x86)\LibreOffice 5\program\scalc.exe" --convert-to DBF --infilter="csv:44,34,76,1,1/2/2/2/3/2/4/2/5/2/6/2/7/2/8/2/9/2/10/2/11/2/12/2/13/2/14/2/15/2/16/2/17/2/18/2/19/2/20/2/21/2/22/2/23/2/24/2/25/2/26/2/27/2/28/2/29/2/30/2/31/2/32/2/33/2/34/2/35/2/36/2/37/2/38/2/39/2/40/2/41/2/42/2/43/2/44/2/45/2/46/2/47/2/48/2/49/2/50/2/51/2/52/2/53/2/54/2/55/2/56/2/57/2/58/2/59/2/60/2/61/2/62/2/63/2/64/2/65/2/66/2/67/2/68/2/69/2/70/2/71/2/72/2/73/2/74/2/75/2/76/2/77/2/78/2/79/2/80/2/81/2/82/2/83/2/84/2/85/2/86/2/87/2/88/2/89/2/90/2/91/2/92/2/93/2/94/2/95/2/96/2/97/2/98/2/99/2/100/2/101/2/102/2/103/2/104/2/105/2/106/2/107/2/108/2/109/2/110/2/111/2/112/2/113/2/114/2/115/2/116/2/117/2/118/2/119/2/120/2/121/2/122/2/123/2/124/2/125/2/126/2/127/2/128/2/129/2/130/2/131/2/132/2/133/2/134/2/135/2/136/2,0,false,false" C:\Users\jdavidson\Desktop\DBFCONVERT\57826001_JQSAMPLE.csv --outdir C:\Users\jdavidson\desktop\complete
Please note, that I needed to use DBF and include an --infilter parameter field
There are two websites in my original posting that shows helpful scripts and infilter information to help other users

Can we give two files as input while using JasperStarter

I am using JasperStarter to create pdf from several jrprint files and then print it using JasperStarter functtions.
I want to create one single pdf file with all the .jrprint files.
If I give command like:
jasperstarter pr a.jprint b.jprint -f pdf -o rep
It does not recognise the files after the first input file.
Can we create one single output file with many input jasper/jrprint files?
Please help.
Thanks,
Oshin
Looking at the documentation, this is not possible:
The command process (pr)
The command process is for processing a report.
In direct comparison to the command for compiling:
The command compile (cp)
The command compile is for compiling one report or all reports in a directory.

Encrypt a PDF file in the command line using pdftk command

i am tiring to perform PDF file encryption using pdftk and installed the dependency modules of PDF::Tk [Perl integration for the pdf toolkit (pdftk)] , but getting error as mentioned below. Can any one please help me in resolving the below issue.
Source code: test.pl
use PDF::Tk;
system(pdftk input.pdf output outPDF.pdf owner_pw foopass) or die "Error!!!!!!!!!!\n";
output:
Can't locate object method "pdftk" via package "input" (perhaps you forgot to load "input"?) at test.pl line 2.
use PDF::Tk module functions instead the system. PDF::Tk is a wrapper over the pdftk utility, so using system is the topic it avoids:
use PDF::Tk;
my $doc=PDF::Tk->new();
$doc->call_pdftk('input.pdf', 'outPDF.pdf', 'owner_pw', 'foopass');
Note: The PDF::Tk constructor could be used to set the pdftk binary. It defaults value is "/usr/bin/pdftk"
my $doc=PDF::Tk->new({pdftk=>'/other/path/to/bin/pdftk'});

Stanford Parser using command line

I am new to using the Stanford Parser. I would like to use the command line to receive the typed dependencies. I changed the directory in cmd to the file where the Stanford Parser- files are and then used the following command:
C:\...directory...\java -cp stanford-parser.jar edu.stanford.nlp.parser.lexparser.LexializedParser -outputFormat "typedDependencies" englishPCFG.ser.gz input.txt
input.txt is in the same Stanford-Parser file. But the I get the following exception:
Loading parser from serialized file englishPCFG.ser.gz...
java.io.IOException: Unable to resolve "englishPCFG.ser.gz" as either class path, filename or URL
I tries some Syntax-modifications like brackets but it didn't work. Does anybody have an idea?
SOLVED:
java -cp C:\stanford-parser.jar; stanford-parser-3.2.0-models.jar edu.stanford.nlp.parser.lexparser.LexicalizedParser -outputFormat "typedDependencies" edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz .txt

Perl script call from Windows Batch file

I have a perl script which needs to be called from Windows batch file. Batch file script reads text file and pass the parameters to perl script. Now one of the argument is "User Input". Now if i give double quotes in text file the following error comes
Could not open : No such file or directory at perl_script.pl at Line 10
code is (echo the input and its showing as User Input on command prompt)
echo %INPUT%
perl perl_script.pl %INPUT%
Now if i give single quotes then the perl_script gets only User (Input is truncated)
Please suggest the best way to handle this
echo %INPUT%
perl perl_script.pl "%INPUT%"