Skip to content

Commit

Permalink
Merge pull request #151 from mix5003/force-inline-style
Browse files Browse the repository at this point in the history
force inline style to prevent css override font-family and font-size
  • Loading branch information
VadimDez authored Sep 14, 2017
2 parents 5e86456 + e7dad5a commit 320d35a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/pdf-viewer/pdf-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,20 @@ export class PdfViewerComponent implements OnChanges {
this.removeAllChildNodes(container);
}

return (<any>page).getOperatorList().then(function (opList) {
return (<any>page).getOperatorList().then( (opList) => {
let svgGfx = new (<any>PDFJS).SVGGraphics((<any>page).commonObjs, (<any>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);
});
});
Expand All @@ -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)};`);
}
}
}

0 comments on commit 320d35a

Please sign in to comment.