Write PDF from base64-String

Post Reply
User avatar
bkromer
Member
Posts: 79
Joined: Thu Jul 11, 2019 10:41 am
Location: Germany

Write PDF from base64-String

Post by bkromer » Thu Oct 07, 2021 1:44 pm

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 Kromer

User avatar
bkromer
Member
Posts: 79
Joined: Thu Jul 11, 2019 10:41 am
Location: Germany

Re: Write PDF from base64-String

Post by bkromer » Thu Oct 07, 2021 1:48 pm

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 Kromer

Post Reply