Can someone provide information of how to convert a byte stream into a PDF object in Servoy?
We’re trying to display a PDF report generated by another application written in FoxPro, the data comes as a byte stream.
Thank you.
Can someone provide information of how to convert a byte stream into a PDF object in Servoy?
We’re trying to display a PDF report generated by another application written in FoxPro, the data comes as a byte stream.
Thank you.
You can take your byte and use plugins.file.writeFile() to write it to a file.
Sorry for the naive question but how do I store the byte stream to get it to the plugin?
The string data types will not work.
Is there a different data type I need to use to store the byte stream before providing it into the plugin?
Cheers
David Younger
VFP programmer (but not Java).
What exactly are you receiving? And what do you want to do with it.
We have VFP9 application that is using a fileToSTR (file to string) function to read a PDF file into a memory variable. A subsequent call to our application API from Servoy receives this string data. I then have the following code which I’m using to convert the data back to a PDF file.
I do correctly get a PDF file, but it is not readable as a PDF. Upon comparing the original PDF with the resultant PDF they are very close but there are minor character differences.
Here is my code:
// Call the API and store the return value to a string variable called path
path = globals.oGlobal.call("TSM_WebReports", cond, null, "JOB CARDS", true, 10).getString();
// To write the contents of the path variable to an output file.
plugins.file.writeTXTFile("c:/temp/out.pdf", path, "Windows-1252");
I also tried this without the charset Windows-1252 and still didn’t work.
put the file into a media field like so:
document = plugins.file.readFile(pathname);
write the file to desktop like so:
var homedir = plugins.file.getHomeDirectory();
var desktopPath = plugins.file.getDesktopFolder();
var tempFile = plugins.file.createTempFile(“tForm”, “.pdf”);
var success = plugins.file.writeFile(tempFile, forms.LogSearchName.document);
if (success) {
//copies a the sourcefile to the destination file, returns true if success
plugins.file.copyFile(tempFile, desktopPath + “/” + forms.LogSearchName.consumer_lname + forms.LogSearchName.doc_year + “_” + forms.LogSearchName.doc_month + “.pdf”);
forms.Main.onClear();
//show dialog
var thePressedButton = plugins.dialogs.showInfoDialog(“Please check Desktop”, “for the PDF file that you requested”, “OK”);
}
I’m sorry, but I think your solution doesn’t fit in our scenario. I hope I’m wrong…
We are receiving a String representation of PDF file, that’s all we have to start. The data comes from another application written in FoxPro, but that’s another story…
How do we convert back that String to a PDF file so we can launch it and show to the client?
Thank you.
I am a bit surprised that you say you receive a String. Isn’t PDF a binary format? If it is purely a String, your method of writing it to a (txt) file should be just fine. If it is not a String what you get there but a byte, then you should use writeFile() instead of writeTXTFile().
PDF is a binary format but the API that returns the file from the FoxPro application returns the data as String type.
We tried to use the function writeTXTFile() specifying different foundset but still didn’t work.
Cheers,
Binary code CANNOT be contained in a String unless encoded (in base64 for example), otherwise you will have bytes that would not be correct in a String, like x00 or EOF, that must be why your PDF if returned as a String is not readable as such, and why
juliaaano:
Upon comparing the original PDF with the resultant PDF they are very close but there are minor character differences.
So before using plugins.file.writeFile() from which is the correct method to use on byte, you will first have to fix your FoxPro method so that you get a byte array! Your fileToSTR in FoxPro is the one breaking the pdf, and Servoy will not be able to fix it after that.
Or, put another way, if someone actually does something like byteToString he hopefully knows what he is doing and encodes the data (with Base64, UUEncode, …). So if you really receive a String from the application you should find out first, what kind of a String it is. Then you can convert it back to a byte and use plugins.file.writeFile() to write those bytes to disk. writeTXTFile() will never give you a PDF.