I have been trying to use the CFC wrapper for wkhtmltopdf from AbramAdams with no luck in getting it to do anything. I think it may be a path issue but not sure. I am trying the example given.
<cfscript>
wkhtmltopdf = new menueditortestsite.menueditor.com.wkhtml.pdf();
results = wkhtmltopdf.create(
url = 'https://wikidocs.adobe.com/wiki/display/coldfusionen/Home', // uncomment to test with url
options = {
"viewport-size":"1200x1080" // default
,"image-quality":100
,"margin-bottom": 25
,"margin-left": "5mm"
,"margin-right": "5mm"
,"margin-top": 45
,"orientation": "portrait" //default
,"encoding": "utf-8"
,"header-html": "http://www.sydneytripslipfallcompensation.com/images/header.jpg"
,"footer-html": "<footer style='text-align:center;'>This, my friend, is a cool footer.</footer>"
},
writeToFile = false, // true will write the file and return a struct containing the path (and other info)
destination = "#expandPath('.')#\pdf\test.pdf"
);
// if you set writeToFile to true, uncomment the below and comment out the cfheader/cfcontent block below
/*
writeDump(results);
text = wkhtmltopdf.getText( results.file );
pagedText = wkhtmltopdf.getText( results.file );
writeDump({
"text":text,
"pagedText":pagedText
});*/
</cfscript>
<cfheader name="Content-Disposition" value="inline; filename=test.pdf">
<cfcontent type="application/pdf" file="#expandPath('.')#test.pdf">
I have wkhtmltopdf installed on windows and I have added this to the system path as C:\Program Files\wkhtmltopdf\bin\ .
I have tested wkhtmltopdf to make sure it is working with success but using the CFC wrapper nothing happens.
I have tried the following with no success. Can someone help me figure out if it is my path code or something else wrong with the developers code?
wkhtmltopdf = new menueditortestsite.menueditor.com.wkhtml.pdf();
wkhtmltopdf = new menueditortestsite.menueditor.com.wkhtml.pdf('C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe');
wkhtmltopdf = new menueditortestsite.menueditor.com.wkhtml.pdf('/usr/local/bin/wkhtmltopdf');
wkhtmltopdf = new menueditortestsite.menueditor.com.wkhtml.pdf(expandPath('../com/wkhtml/bin/wkhtmltopdf.exe'));
This is the code I ran with no errors reported.
wkhtmltopdf = new menueditortestsite.menueditor.com.wkhtml.pdf();
results = wkhtmltopdf.create(
url = 'https://wikidocs.adobe.com/wiki/display/coldfusionen/Home', // uncomment to test with url
options = {
"viewport-size":"1200x1080" // default
,"image-quality":100
,"margin-bottom": 25
,"margin-left": "5mm"
,"margin-right": "5mm"
,"margin-top": 45
,"orientation": "portrait" //default
,"encoding": "utf-8"
,"header-html": "http://www.sydneytripslipfallcompensation.com/images/header.jpg"
,"footer-html": "<footer style='text-align:center;'>This, my friend, is a cool footer.</footer>"
},
writeToFile = true, // true will write the file and return a struct containing the path (and other info)
destination = "#expandPath('.')#\pdf\test.pdf"
);
writeDump(results);abort;
text = wkhtmltopdf.getText( results.file );
pagedText = wkhtmltopdf.getText( results.file );
writeDump({
"text":text,
"pagedText":pagedText
});
Related
How to set load_system_dawg and load_freq_dawg to false ??
I need to disable the dictionary.. So I guess these are the two parameteres I need to set to false?
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
if(api->Init(NULL, "dan+eng")){
// error
}
api->SetImage(image);
api->Recognize(0);
tesseract 3.05.01
In your tessdata directory create a configs directory
Create a file config (you will pass name of config file later in code)
Fill your config file with following text
load_system_dawg F
load_freq_dawg F
Modify your code
auto numOfConfigs = 1;
auto **configs = new char *[numOfConfigs];
configs[i] = (char *) "name of your config file";
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
if(api->Init(NULL, "dan+eng", tesseract::OEM_DEFAULT, configs, numOfConfigs, nullptr, nullptr, false)){
// error
}
P.S. It is also possible to do with last couple of arguments of Init function, feel free to try them out yourself.
After reading the following link:
enter link description here
search for load_system_dawg in the document.
It says that a value of 1 will load the dictionaries, similarly for load_freq_dawg.
Using a value of 0 = false, we can disable frequency words and the dictionary as follows:
//pseudo code
api.setVariable("load_system_dawg","0");
api.setVariable("load_freq_dawg","0");
I am having a problem with the Barbecue Barcode Library. I am trying to create a simple code128 barcode, but the image I get is different from what I get from other online (i.e. http://barcode-generator.org) and desktop (i.e. Zing) Barcode generators.
Here is the ColdFusion code I am using:
<cfscript>
LOCAL.BarcodeData = "10047846";
LOCAL.BarcodeFactory = CreateObject("java", "net.sourceforge.barbecue.BarcodeFactory");
LOCAL.Barcode = LOCAL.BarCodeFactory.createCode128(LOCAL.BarcodeData);
LOCAL.BarcodeImageHandler = CreateObject("java", "net.sourceforge.barbecue.BarcodeImageHandler");
LOCAL.BarcodeBufferedImage = LOCAL.BarcodeImageHandler.getImage(LOCAL.Barcode);
LOCAL.BarcodeImage = ImageNew(LOCAL.BarcodeBufferedImage);
LOCAL.BarcodeImagePath =
"C:\temp_\barcode-" & LOCAL.BarcodeData & ".jpg";
ImageWrite(LOCAL.BarcodeImage, LOCAL.BarcodeImagePath, 1);
</cfscript>
<cfimage action="writeToBrowser" source="#LOCAL.BarcodeImagePath#" />
This outputs the following image:
Yet, here is what I get from the Zing desktop program:
And here is what I get from barcode-generator.org:
Now, I have no issue with the sizing, scaling, etc. But, you can easily tell that the Barbecue-generated image is much different - simply look at the first several bars.
Why is this happening? Is this a Barbecue bug or am I doing something wrong?
Not sure this is the "answer", per se, but, when I changed the code to use the Code128C format, the image came out as expected. I just had to do some resizing to get it exactly the size I needed:
Code:
<cfscript>
LOCAL.BarcodeData = "10047846";
LOCAL.BarcodeFactory = CreateObject("java", "net.sourceforge.barbecue.BarcodeFactory");
LOCAL.Barcode = LOCAL.BarCodeFactory.createCode128C(LOCAL.BarcodeData);
LOCAL.Barcode.setDrawingText(false);
LOCAL.Barcode.setDrawingQuietSection(false);
LOCAL.Barcode.setBarWidth(1);
LOCAL.Barcode.setBarHeight(30);
LOCAL.BarcodeImageHandler = CreateObject("java", "net.sourceforge.barbecue.BarcodeImageHandler");
LOCAL.BarcodeBufferedImage = LOCAL.BarcodeImageHandler.getImage(LOCAL.Barcode);
LOCAL.BarcodeImage = ImageNew(LOCAL.BarcodeBufferedImage);
LOCAL.BarcodeImagePath =
"C:\temp_\barcode-" & LOCAL.BarcodeData & ".jpg";
ImageWrite(LOCAL.BarcodeImage, LOCAL.BarcodeImagePath, 1);
</cfscript>
<cfimage action="writeToBrowser" source="#LOCAL.BarcodeImagePath#" />
It looks like the bar width of your image is larger then the examples. Set the bar width to 1 px. by adding LOCAL.Barcode.setBarWidth(1);before you generate the barcode.
<cfscript>
LOCAL.BarcodeData = "10047846";
LOCAL.BarcodeFactory = CreateObject("java", "net.sourceforge.barbecue.BarcodeFactory");
LOCAL.Barcode = LOCAL.BarCodeFactory.createCode128(LOCAL.BarcodeData);
LOCAL.Barcode.setBarWidth(1); // decrease the width of the bars
LOCAL.Barcode.setBarHeight(50); // if you want a taller barcode like the examples
LOCAL.BarcodeImageHandler = CreateObject("java", "net.sourceforge.barbecue.BarcodeImageHandler");
LOCAL.BarcodeBufferedImage = LOCAL.BarcodeImageHandler.getImage(LOCAL.Barcode);
LOCAL.BarcodeImage = ImageNew(LOCAL.BarcodeBufferedImage);
LOCAL.BarcodeImagePath = gettempDirectory()& "\barcode-" & LOCAL.BarcodeData & ".jpg";
ImageWrite(LOCAL.BarcodeImage, LOCAL.BarcodeImagePath, 1);
</cfscript>
I scanned it with a barcode scanner and all three images read the same string "10047846". For barcodes, I use CFBarbecue (http://cfbarbecue.riaforge.org/), a ColdFusion wrapper for Barbecue. Using the same string, below is the image I was able to generate using CFBarbecue.
I'm new to using the application.cfc file in our application and some of these don't seem to be working and I can't figure out why. I have tried to cfdump "application". I get Application.DSN, Application.USERNAME, Application.Password, but not Application.SYSTEMPATH or Application.ACCOUNT
<cffunction name="onApplicationStart">
<cfscript>
Application.availableResources=0;
Application.DSN = "XXX";
Application.USERNAME = "XXX" ;
Application.PASSWORD = "XXX";
Application.SYSTEMPATH = "http://example.com/"; // This doesn't work
Application.ACCOUNT = XXX; // This doesn't work.
Application.counter1=1;
Application.sessions=0;
</cfscript>
</cffunction>
I think you want this:
Application.SYSTEMPATH = GetDirectoryFromPath(GetCurrentTemplatePath());
This will work too:
Application.SYSTEMPATH = expandPath( './' );
Now this...
Application.ACCOUNT = XXX; // This doesn't work. (because it is assuming XXX is a variable).
You need this:
XXX = 'something'; or XXX = 1; or Remove it altogether because it serves no purpose.
Then when you call:
Application.ACCOUNT = XXX; it won't give you errors.
Or you can just skip it and do this:
Application.ACCOUNT = 'something'; (a string)
Application.ACCOUNT = 1; (a number)
Then it won't fall apart (Because XXX is a variable not a value and you can't call a variable that doesn't exist).
So, if you have a 'variable' it has to have a 'value' (variable/value pair) or at least set a placeholder like XXX=0; or XXX=''; if you must have it.
Have I killed this variable/value dead horse to death??? Lol... :D
Jokes aside let us know if you have another question about your Application variables because some seem unnecessary (can't judge for sure though).
I have a ColdFusion application that reads a list of files from a directory, and then converts each MSOffice document in the list to a PDF using the JODConverter library and OpenOffice.org 3.4.1.
I wrote this application and setup my development PC according the instructions in the two articles here:
http://cfsearching.blogspot.com/search/label/JODConverter
The only difference is that I installed the necessary JARs outside of cf_root.
<cffunction name="convertNonPDFFiles" returntype="Void" output="false">
<cfscript>
// CONSTANTs
var _NON_PDF_PATH = APPLICATION.PDFSource & "\NonPDFs";
var _PDF_PATH = APPLICATION.PDFSource & "\PDFs";
var _VALID_FILE_EXTENSIONS = "doc,docx,ppt,pptx";
// Set defaults for private variables
var _qNonPDFDir = QueryNew("");
var _fileName = "";
var _documentId = 0;
var _sourceFilePath = "";
var _destinationFilePath = "";
var _fileExtension = "";
var _isConversionSuccessful = true;
var _tempSourceFilePath = "";
var _tempImageFilePath = "";
// Initialize Open Office Conversion Manager
var _openOfficeManager =
CreateObject(
"java",
"org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration"
).setOfficeHome(
APPLICATION.OpenOfficeProgramPath // Location of the OpenOffice.org 3.4.1 application directory on the server
).setTaskExecutionTimeout(60000).buildOfficeManager();
_openOfficeManager.start();
</cfscript>
<!--- Retrieve a list of file names in the directory of unprocessed
non-PDF files --->
<cfdirectory
action="list"
directory="#_NON_PDF_PATH#"
name="_qNonPDFDir"
type="file"
listinfo="name"
sort="datelastmodified DESC" />
<cfoutput query="_qNonPDFDir">
<cfscript>
_fileName = _qNonPDFDir.name;
_fileExtension =
REQUEST.UDFLib.File.getFileExtension(_fileName);
_sourceFilePath = _NON_PDF_PATH & "\" & _fileName;
// File is a valid format for conversion
if (ListFindNoCase(_VALID_FILE_EXTENSIONS, _fileExtension)) {
_documentId =
REQUEST.UDFLib.File.getFileNameWithoutExtension(
_fileName
);
_destinationFilePath =
_PDF_PATH
& "\"
& REQUEST.UDFLib.File.getFileNameWithoutExtension(
_fileName
)
& ".pdf";
_isConversionSuccessful = true;
_tempSourceFilePath =
APPLICATION.TempDir
& "\"
& _documentId
& "." & _fileExtension;
/*
Create of the copy of the original file in the temp
directory
*/
FileCopy(
APPLICATION.of_aprimo_root & "\" & _documentId & ".dat",
_tempSourceFilePath
);
// Attempt to convert the file to PDF
try {
// See convertFile() method below
convertFile(
openOfficeManager = _openOfficeManager,
inputFilePath = _tempSourceFilePath,
outputFilePath = _destinationFilePath
);
}
catch (any e) {
_isConversionSuccessful = false;
}
if (_isConversionSuccessful)
FileMove(
_sourceFilePath,
_NON_PDF_PATH & "\Processed\"
);
else
FileMove(
_sourceFilePath,
_NON_PDF_PATH & "\NonFunctioning\"
);
}
// File is not a valid format for conversion
else {
FileDelete(_sourceFilePath);
}
</cfscript>
</cfoutput>
<cfscript>
_openOfficeManager.stop();
return;
</cfscript>
</cffunction>
<cfscript>
function convertFile(openOfficeManager, inputFilePath, outputFilePath) {
CreateObject(
"java",
"org.artofsolving.jodconverter.OfficeDocumentConverter"
).init(ARGUMENTS.OpenOfficeManager).convert(
CreateObject(
"java",
"java.io.File"
).init(ARGUMENTS.inputFilePath),
CreateObject(
"java",
"java.io.File"
).init(ARGUMENTS.outputFilePath)
);
return;
}
</cfscript>
This application works perfectly on my development machine, but as soon as I move it to one of my web servers, it doesn't work there.
Dev PC Setup:
OS: Windows 7 Professional SP1
IIS: 7
ColdFusion: 8.0.1
Server Setup:
OS: Windows 2003 R2 Standard Edition SP2
IIS: 6.0
ColdFusion: 8.0.1
When I attempt to run the application on the server - either directly in a browser or via Scheduled Tasks, it throws no exceptions. It simply appears to run until it times out after 60 minutes. In Task Manager, I can see soffice.bin start running when the application starts, but after a few seconds, soffice.bin simply disappears from the Task Manager.
Any ideas what might be the problem?
After some troubleshooting, I was finally able to get this to work with a few minor changes to the programming (all credit to cfSearching - I found the answer to my problem in the comments at http://cfsearching.blogspot.com/search/label/JODConverter).
Original code that configured and started the OpenOfficeManager instance:
CreateObject(
"java",
"org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration"
).setOfficeHome(
APPLICATION.OpenOfficeProgramPath
).setTaskExecutionTimeout(60000).buildOfficeManager();
Updated (fixed) to add setConnectionProtocol() and setPortNumber():
CreateObject(
"java",
"org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration"
).setOfficeHome(
APPLICATION.OpenOfficeProgramPath
).setConnectionProtocol(
CreateObject(
"java",
"org.artofsolving.jodconverter.office.OfficeConnectionProtocol"
).SOCKET
).setPortNumber(
8100
).setTaskExecutionTimeout(
60000
).buildOfficeManager();
It may be as simple as OpenOffice needing to be re-installed on the server where as it is on your dev machine.
We are using Coldfusion 9.
Is there a simple way to know if enablecfoutputonly has been set to true during a particular request?
I cannot test with CF9 right now, but in CF10 it is accessible from getPageContext() by checking the output object:
<cfscript>
out = getPageContext().getOut();
// Is the cfsetting enablecfoutputonly value currently true?
isSettingEnabled = out.getDisableCount() > 0;
WriteOutput("isSettingEnabled="& isSettingEnabled &"<br>");
// Is output currently allowed?
isOuputtingEnabled = out.getDisableCount() == 0 || out.getOutputCount() > 0;
WriteOutput("isOuputtingEnabled="& isOuputtingEnabled &"<br>");
</cfscript>
.. or using reflection:
<cfscript>
out = getPageContext().getOut();
internalMethod = out.getClass().getDeclaredMethod("isOutputEnabled", []);
internalMethod.setAccessible( true );
isOuputtingEnabled = internalMethod.invoke( out, [] );
// is output currently allowed?
WriteOutput("isOuputtingEnabled="& isOuputtingEnabled);
</cfscript>