mirror of
https://github.com/jzillmann/pdf-to-markdown.git
synced 2025-02-09 06:19:39 +01:00
Add font info to pdf page view
This commit is contained in:
parent
ab5705cd27
commit
92a4337387
@ -55,6 +55,17 @@ export default class LoadingView extends React.Component {
|
|||||||
pdfDocument.getPage(j).then(function(page) {
|
pdfDocument.getPage(j).then(function(page) {
|
||||||
var scale = 1.0;
|
var scale = 1.0;
|
||||||
var viewport = page.getViewport(scale);
|
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) {
|
page.getTextContent().then(function(textContent) {
|
||||||
const textItems = textContent.items.map(function(item) {
|
const textItems = textContent.items.map(function(item) {
|
||||||
const tx = PDFJS.Util.transform( // eslint-disable-line no-undef
|
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 fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
|
||||||
const dividedHeight = item.height / fontHeight;
|
const dividedHeight = item.height / fontHeight;
|
||||||
|
|
||||||
|
const style = textContent.styles[item.fontName];
|
||||||
return new TextItem({
|
return new TextItem({
|
||||||
x: item.transform[4],
|
x: item.transform[4],
|
||||||
y: item.transform[5],
|
y: item.transform[5],
|
||||||
width: item.width,
|
width: item.width,
|
||||||
height: dividedHeight <= 1 ? item.height : dividedHeight,
|
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);
|
anouncePageParsedFunction(page.pageIndex, textItems);
|
||||||
@ -79,9 +95,6 @@ export default class LoadingView extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {parsedPages, pdfPages} = this.state;
|
const {parsedPages, pdfPages} = this.state;
|
||||||
var percentDone = 0;
|
var percentDone = 0;
|
||||||
|
@ -41,6 +41,10 @@ export default class PdfPageView extends React.Component {
|
|||||||
<th>
|
<th>
|
||||||
Height
|
Height
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
Font
|
||||||
|
<br/>(asc/desc)
|
||||||
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -75,6 +79,11 @@ export default class PdfPageView extends React.Component {
|
|||||||
<td>
|
<td>
|
||||||
{ textItem.height }
|
{ textItem.height }
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
{ textItem.font }
|
||||||
|
<br/>
|
||||||
|
{ textItem.fontAscent + ' / ' + textItem.fontDescent }
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
) }
|
) }
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -7,6 +7,9 @@ export default class TextItem {
|
|||||||
this.width = options.width;
|
this.width = options.width;
|
||||||
this.height = options.height;
|
this.height = options.height;
|
||||||
this.text = options.text;
|
this.text = options.text;
|
||||||
|
this.font = options.font;
|
||||||
|
this.fontAscent = options.fontAscent;
|
||||||
|
this.fontDescent = options.fontDescent;
|
||||||
this.annotation = options.annotation;
|
this.annotation = options.annotation;
|
||||||
this.markdownElement = options.markdownElement;
|
this.markdownElement = options.markdownElement;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user