I have a pdf file that is available in the form of a Hexa string bytestream like:
"255044462D312E330D0A25E2E3CFD30D0A322030206F626A......"
(its a very long string, so I have just given the format)
which is in a string format available in the browser.
I need to convert this into its hexadecimal format so that I can render the pdf in the web browser by writing this output stream to the pdf file. I need to know if there is any inbuilt function or any way this can be achieved in Javascript.
I know implementing this functionality is simple with Java but I have an ABAP
backend that only fetches me this string and SAPUI5
front end that is a framework based on Javascript.
I checked the validity this bytestream by writing a simple java program that generated the PDF just for testing purpose if the data is coming right:
public static void main(String[] args) {
FileOutputStream fop = null;
File file;
file = new File("C:/Users/I074098/Desktop/Project Temps/test.pdf");
fop = new FileOutputStream(file);
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
//I manually added "(byte) 0x" in the above string and
//converted it to the following format, I skipped that conversion in this code
byte[] contentInBytes = new byte[]{
(byte) 0x25,(byte) 0x50,(byte) 0x44,(byte) 0x46, .....
}
fop.write(contentInBytes);
fop.flush();
fop.close();
}
This generates the pdf. But I know it is very inefficient and I am not sure all this can be done in javascript.
I have done a lot of search and it was not fruitful. I will be thankful any and every help.
Regards,
Riswan
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…