Page 1 of 1

Write PDF from base64-String

Posted: Thu Oct 07, 2021 1:44 pm
by bkromer
I get a PDF as bases64 and just need to write a pdf from that.
How can I make this in a Legacy Script?

My code so far:

Code: Select all

function jobArrived( s : Switch, job : Job )
{
	const base64Label = "JVBERi0xLjQKJeLjz9MKMyAwIG9i............";
	const path = job.createPathWithName("DPDLabel.pdf");
	var ba = new ByteArray( base64Label, "UTF-8");
	File.writeByteArray(path, ba);
	job.sendToSingle(path);
}
The scripts just writes the string to the file. Which then of course cant be opened.

Re: Write PDF from base64-String

Posted: Thu Oct 07, 2021 1:48 pm
by bkromer
Okay that was dumb I just found the solution... I need to use "fromBase64" instead of "utf-8".

Code: Select all

var ba = new ByteArray( base64Label, "fromBase64");