Write PDF from base64-String

Post Reply
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

Write PDF from base64-String

Post 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.
Benjamin
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

Re: Write PDF from base64-String

Post 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");
Benjamin
Post Reply