Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

force inline style to prevent css override font-family and font-size #151

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)};`);
}
}
}