From e7dad5a95cf87fc036f6e95a65c27924421783fc Mon Sep 17 00:00:00 2001 From: mix5003 Date: Mon, 4 Sep 2017 14:38:41 +0700 Subject: [PATCH] convert to attribute to inline style --- src/pdf-viewer/pdf-viewer.component.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pdf-viewer/pdf-viewer.component.ts b/src/pdf-viewer/pdf-viewer.component.ts index 549da7576..57b62f1ff 100644 --- a/src/pdf-viewer/pdf-viewer.component.ts +++ b/src/pdf-viewer/pdf-viewer.component.ts @@ -188,16 +188,20 @@ export class PdfViewerComponent implements OnChanges { this.removeAllChildNodes(container); } - return (page).getOperatorList().then(function (opList) { + return (page).getOperatorList().then( (opList) => { let svgGfx = new (PDFJS).SVGGraphics((page).commonObjs, (page).objs); - return svgGfx.getSVG(opList, viewport).then(function (svg) { + return svgGfx.getSVG(opList, viewport).then( (svg) => { let $div = document.createElement('div'); $div.classList.add('page'); $div.setAttribute('data-page-number', `${ page.pageNumber }`); $div.appendChild(svg); + + this.convertAttributeToInlineStyle($div, 'font-family'); + this.convertAttributeToInlineStyle($div, 'font-size'); + container.appendChild($div); }); }); @@ -209,4 +213,13 @@ export class PdfViewerComponent implements OnChanges { element.removeChild(element.firstChild); } } + + private convertAttributeToInlineStyle(parent: HTMLElement, attribute: string) { + const matchElements = parent.querySelectorAll(`[${attribute}]`); + for (let i = 0, l = matchElements.length; i < l; i++) { + const element = matchElements[i]; + const oldStyle = element.getAttribute('style') || ''; + element.setAttribute('style', `${oldStyle} ${attribute}: ${element.getAttribute(attribute)};`); + } + } }