Prevent run-time errors in Node.js versions with URL.createObjectURL
support (issue 14170)
Apparently Node.js has added *global* `URL.createObjectURL` support, but not done the same thing for `Blob`. Hence we also need to check for the availability of `Blob` in the `createObjectURL` helper function, and it's probably a good idea to also update `examples/node/pdf2svg.js` to work-around this until these changes reach an official PDF.js release.
This commit is contained in:
parent
7c9e5781fe
commit
ff9d2b2ab1
@ -110,7 +110,11 @@ const loadingTask = pdfjsLib.getDocument({
|
|||||||
console.log();
|
console.log();
|
||||||
|
|
||||||
const opList = await page.getOperatorList();
|
const opList = await page.getOperatorList();
|
||||||
const svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
|
const svgGfx = new pdfjsLib.SVGGraphics(
|
||||||
|
page.commonObjs,
|
||||||
|
page.objs,
|
||||||
|
/* forceDataSchema = */ true
|
||||||
|
);
|
||||||
svgGfx.embedFonts = true;
|
svgGfx.embedFonts = true;
|
||||||
const svg = await svgGfx.getSVG(opList, viewport);
|
const svg = await svgGfx.getSVG(opList, viewport);
|
||||||
await writeSvgToFile(svg, getFilePathForPage(pageNum));
|
await writeSvgToFile(svg, getFilePathForPage(pageNum));
|
||||||
|
@ -1030,7 +1030,7 @@ function createPromiseCapability() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createObjectURL(data, contentType = "", forceDataSchema = false) {
|
function createObjectURL(data, contentType = "", forceDataSchema = false) {
|
||||||
if (URL.createObjectURL && !forceDataSchema) {
|
if (URL.createObjectURL && typeof Blob !== "undefined" && !forceDataSchema) {
|
||||||
return URL.createObjectURL(new Blob([data], { type: contentType }));
|
return URL.createObjectURL(new Blob([data], { type: contentType }));
|
||||||
}
|
}
|
||||||
// Blob/createObjectURL is not available, falling back to data schema.
|
// Blob/createObjectURL is not available, falling back to data schema.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user