UZIP.js: Range Error on freshly generated and valid PDF
Hey!
First of all thanks for your amazing gits! Love using theme.
Today i encountered a problem with freshly generated and valid PDFs (InDesign / Affinity Publisher, Adobe Acrobat or even self generated with qpdf).
Scenario:
Read the File with FileReader as BinaryString -> handover to a PDF Stream Extraction Function (Regex the FlateDecode Part) -> UZIP.inflate -> Put together the PDF File
FileReader:
var request = new XMLHttpRequest();
request.open('GET', file, true);
request.responseType = 'blob';
request.onload = function() {
var reader = new FileReader();
reader.readAsBinaryString(request.response);
reader.onload = function(e){
console.log(e.target.result);
stripPDFStream(e.target.result);
};
};
request.send();
Stream Extraction:
function stripPDFStream(input) {
var regex = /.*?FlateDecode.*?stream(.*?)endstream/gms;
function replaceDeflate() {
var result;
while ((result = regex.exec(input)) !== null) {
console.log(result[0]);
console.log(result[1]); // <---- Stream Data
var stripped = result[1].replace(/^\s+|\s+$/g, '');
var inflate = inflatePDF(stripped);
var output = input.replace(result[0], inflate);
}
}
replaceDeflate();
}
Inflate:
function inflatePDF(input) {
var enc = new TextEncoder(); // always utf-8
var uint8array = enc.encode(input);
var data = UZIP.inflateRaw(uint8array);
console.log(data);
}
UZip throws the error: Uncaught RangeError: Invalid type array lenght: length.
You said something over at pako.js git, that your uzip repository is capable of inflating a pdf flatedecode stream and in another issue here, that array lenght doesnt matter cause you copy over to a bigger array, if it will not fit into the output array.
Would be awesome, if you could help. Iām at a loss. š¦
Greetings, Dennis test.pdf
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (8 by maintainers)
Great š