Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return page.getOperatorList().then(opList => {
var svgGfx = new pdfjs.SVGGraphics(page.commonObjs, page.objs)
svgGfx.embedFonts = true
return svgGfx.getSVG(opList, viewport).then(svg => {
return svg.toString()
.replace('xmlns:svg', 'xmlns') // strip :svg to allow skipping namespace
.replace(/<(\/|)svg:/g, '<$1') // strip namespaces added by pdf.js
})
})
})
const previewAndIndexEachPage = async function(ctx, pagesDir, pageNum, doc) {
try {
const page = await doc.getPage(pageNum);
const viewport = page.getViewport({ scale: viewportScale });
ctx.addPreview(getFilePathForPage(pagesDir, pageNum, 'html'), 'html');
ctx.addPreview(getFilePathForPage(pagesDir, pageNum, 'svg'), 'svg');
const opList = await page.getOperatorList();
const svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
svgGfx.embedFonts = true;
const svg = await svgGfx.getSVG(opList, viewport);
await writeSvgToFile(svg, getFilePathForPage(pagesDir, pageNum, 'html'));
await writeSvgToFile(svg, getFilePathForPage(pagesDir, pageNum, 'svg'));
const content = await page.getTextContent();
// Content contains lots of information about the text layout and
// styles, but we need only strings at the moment
const pageContents = _.pluck(content.items, 'str').join(' ');
const pageName = util.format('page.%s.txt', pageNum);
const pagePath = util.format('%s/%s', pagesDir, pageName);
pdfContents.push(pageContents);
ctx.addPreview(pagePath, pageName);
return page.getOperatorList().then(opList => {
let svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
svgGfx.embedFonts = true;
for (let i = 0; i < opList.fnArray.length; i++) {
if (opList.fnArray[i] === pdfjsLib.OPS.paintJpegXObject) {
let imageInfo = page.objs.get(opList.argsArray[i][0]);
extractedImages.push(imageInfo._src.split('data:image/jpeg;base64,')[1]);
}
}
});
});
.then((operatorList) => {
const svgGfx = new pdfjs.SVGGraphics(page.commonObjs, page.objs);
this.renderer = svgGfx.getSVG(operatorList, this.viewport)
.then((svg) => {
this.setState({ svg }, this.onRenderSuccess);
})
.catch(this.onRenderError);
})
.catch(this.onRenderError);
const loadingTask = pdfjsLib.getDocument({
data,
nativeImageDecoderSupport: 'display',
CMapReaderFactory: NodeCMapReaderFactory
})
const doc = await loadingTask.promise
const page = await doc.getPage(options.pageNumber)
let viewport = page.getViewport({ scale: 1.0, })
const height = options.height
const width = options.width
const scale = Math.min(height/viewport.height, width/viewport.width, 1)
viewport = page.getViewport({ scale })
const opList = await page.getOperatorList()
const svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs)
svgGfx.embedFonts = true
const svg = await svgGfx.getSVG(opList, viewport)
return svg.toString()
}
return page.getOperatorList().then((opList) => {
let svgGfx = new pdfjsLib.SVGGraphics(page.commonObjs, page.objs);
svgGfx.embedFonts = true;
return svgGfx.getSVG(opList, viewport);
}).then((svgDomElement) => {
return this.svgWriter.writeSvgPage(page, svgDomElement);