Add font info to pdf page view

This commit is contained in:
Johannes Zillmann 2017-02-14 20:28:01 +01:00
parent ab5705cd27
commit 92a4337387
3 changed files with 29 additions and 4 deletions

View File

@ -55,6 +55,17 @@ export default class LoadingView extends React.Component {
pdfDocument.getPage(j).then(function(page) {
var scale = 1.0;
var viewport = page.getViewport(scale);
// pdfDocument.getMetadata().then(function(data) {
// console.debug(data);
// });
// page.getOperatorList().then(function(opList) {
// console.debug(opList);
// // var svgGfx = new svgLib.SVGGraphics(page.commonObjs, page.objs);
// // return svgGfx.getSVG(opList, viewport).then(function (svg) {
// // container.appendChild(svg);
// // });
// });
page.getTextContent().then(function(textContent) {
const textItems = textContent.items.map(function(item) {
const tx = PDFJS.Util.transform( // eslint-disable-line no-undef
@ -64,12 +75,17 @@ export default class LoadingView extends React.Component {
const fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
const dividedHeight = item.height / fontHeight;
const style = textContent.styles[item.fontName];
return new TextItem({
x: item.transform[4],
y: item.transform[5],
width: item.width,
height: dividedHeight <= 1 ? item.height : dividedHeight,
text: item.str
text: item.str,
font: item.fontName,
fontAscent: style.ascent,
fontDescent: style.descent
});
});
anouncePageParsedFunction(page.pageIndex, textItems);
@ -79,9 +95,6 @@ export default class LoadingView extends React.Component {
});
}
render() {
const {parsedPages, pdfPages} = this.state;
var percentDone = 0;

View File

@ -41,6 +41,10 @@ export default class PdfPageView extends React.Component {
<th>
Height
</th>
<th>
Font
<br/>(asc/desc)
</th>
</tr>
</thead>
<tbody>
@ -75,6 +79,11 @@ export default class PdfPageView extends React.Component {
<td>
{ textItem.height }
</td>
<td>
{ textItem.font }
<br/>
{ textItem.fontAscent + ' / ' + textItem.fontDescent }
</td>
</tr>
) }
</tbody>

View File

@ -7,6 +7,9 @@ export default class TextItem {
this.width = options.width;
this.height = options.height;
this.text = options.text;
this.font = options.font;
this.fontAscent = options.fontAscent;
this.fontDescent = options.fontDescent;
this.annotation = options.annotation;
this.markdownElement = options.markdownElement;
}