/**
* Use built-in WriteFile() function to present a PDF for download or display
* depending on what the user's browser is set to do.
* @param {String} pdflocation
* @param {String} prefix
* @properties={typeid:24,uuid:"8211D1E0-2E74-422B-9762-B1EF363C8772"}
*/
function downloadPDF(pdflocation, prefix)
{
var attachmentFile = plugins.file.convertToJSFile(pdflocation);
// -- Attempt to present the file to the browser.
if (attachmentFile.exists())
{
var fbytes = plugins.file.readFile(pdflocation);
plugins.file.writeFile(utils.stringTrim(prefix) + '.pdf', fbytes, 'application/pdf');
plugins.Log.info('Presented ' + pdflocation + ' for download.');
}
else
{
plugins.Log.warn('Download requested but ' + pdflocation + ' does not exist.');
}
}
D:\servoy\
D:\myapplication\pdf\a\testuser\
function downloadPDF(pdflocation, prefix) {
var attachmentFile = plugins.file.convertToJSFile(pdflocation);
// -- Attempt to present the file to the browser.
if (attachmentFile.exists()) {
var fbytes = plugins.file.readFile(pdflocation);
var _oFile = plugins.file.createTempFile(utils.stringTrim(prefix), '.pdf');
_oFile = plugins.file.convertToRemoteJSFile(_oFile.getAbsolutePath());
if (_oFile) {
// this will trigger the download
if (!plugins.file.writeFile(_oFile, fbytes, 'application/pdf')) {
throw new Error("Error during writing of the pdf");
}
// clean up after us
_oFile.deleteFile();
}
plugins.Log.info('Presented ' + pdflocation + ' for download.');
} else {
plugins.Log.warn('Download requested but ' + pdflocation + ' does not exist.');
}
}
_oFile = plugins.file.convertToRemoteJSFile(_oFile.getAbsolutePath());
C:\Users\abourke\AppData\Local\Temp\ref 14890999597871051031.pdf
Exception Object: java.lang.IllegalArgumentException: Remote path should start with '/'
MSG: Remote path should start with '/'
Remote path should start with '/'
Wrapped java.lang.IllegalArgumentException: Remote path should start with '/'
Users browsing this forum: No registered users and 4 guests