Merge pull request #8540 from Rob--W/svg-oom
Reduce memory requirements of pdf2svg.js example to avoid OOM
This commit is contained in:
commit
9bed695ebd
@ -95,24 +95,27 @@ DOMElement.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
toString: function DOMElement_toString() {
|
toString: function DOMElement_toString() {
|
||||||
var attrList = [];
|
var buf = [];
|
||||||
for (i in this.attributes) {
|
buf.push('<' + this.nodeName);
|
||||||
attrList.push(i + '="' + xmlEncode(this.attributes[i]) + '"');
|
if (this.nodeName === 'svg:svg') {
|
||||||
|
buf.push(' xmlns:xlink="http://www.w3.org/1999/xlink"' +
|
||||||
|
' xmlns:svg="http://www.w3.org/2000/svg"');
|
||||||
|
}
|
||||||
|
for (var i in this.attributes) {
|
||||||
|
buf.push(' ' + i + '="' + xmlEncode(this.attributes[i]) + '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf.push('>');
|
||||||
|
|
||||||
if (this.nodeName === 'svg:tspan' || this.nodeName === 'svg:style') {
|
if (this.nodeName === 'svg:tspan' || this.nodeName === 'svg:style') {
|
||||||
var encText = xmlEncode(this.textContent);
|
buf.push(xmlEncode(this.textContent));
|
||||||
return '<' + this.nodeName + ' ' + attrList.join(' ') + '>' +
|
|
||||||
encText + '</' + this.nodeName + '>';
|
|
||||||
} else if (this.nodeName === 'svg:svg') {
|
|
||||||
var ns = 'xmlns:xlink="http://www.w3.org/1999/xlink" ' +
|
|
||||||
'xmlns:svg="http://www.w3.org/2000/svg"'
|
|
||||||
return '<' + this.nodeName + ' ' + ns + ' ' + attrList.join(' ') + '>' +
|
|
||||||
this.childNodes.join('') + '</' + this.nodeName + '>';
|
|
||||||
} else {
|
} else {
|
||||||
return '<' + this.nodeName + ' ' + attrList.join(' ') + '>' +
|
this.childNodes.forEach(function(childNode) {
|
||||||
this.childNodes.join('') + '</' + this.nodeName + '>';
|
buf.push(childNode.toString());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
buf.push('</' + this.nodeName + '>');
|
||||||
|
return buf.join('');
|
||||||
},
|
},
|
||||||
|
|
||||||
cloneNode: function DOMElement_cloneNode() {
|
cloneNode: function DOMElement_cloneNode() {
|
||||||
|
@ -18,7 +18,7 @@ var pdfPath = process.argv[2] || '../../web/compressed.tracemonkey-pldi-09.pdf';
|
|||||||
var data = new Uint8Array(fs.readFileSync(pdfPath));
|
var data = new Uint8Array(fs.readFileSync(pdfPath));
|
||||||
|
|
||||||
// Dumps svg outputs to a folder called svgdump
|
// Dumps svg outputs to a folder called svgdump
|
||||||
function writeToFile(svgdump, pageNum) {
|
function writeToFile(svgdump, pageNum, callback) {
|
||||||
var name = getFileNameFromPath(pdfPath);
|
var name = getFileNameFromPath(pdfPath);
|
||||||
fs.mkdir('./svgdump/', function(err) {
|
fs.mkdir('./svgdump/', function(err) {
|
||||||
if (!err || err.code === 'EEXIST') {
|
if (!err || err.code === 'EEXIST') {
|
||||||
@ -29,7 +29,10 @@ function writeToFile(svgdump, pageNum) {
|
|||||||
} else {
|
} else {
|
||||||
console.log('Page: ' + pageNum);
|
console.log('Page: ' + pageNum);
|
||||||
}
|
}
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -67,7 +70,9 @@ pdfjsLib.getDocument({
|
|||||||
svgGfx.embedFonts = true;
|
svgGfx.embedFonts = true;
|
||||||
return svgGfx.getSVG(opList, viewport).then(function (svg) {
|
return svgGfx.getSVG(opList, viewport).then(function (svg) {
|
||||||
var svgDump = svg.toString();
|
var svgDump = svg.toString();
|
||||||
writeToFile(svgDump, pageNum);
|
return new Promise(function(resolve) {
|
||||||
|
writeToFile(svgDump, pageNum, resolve);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user