From 95a7e3e93bc53872e2041173e493ccd7e0b4912d Mon Sep 17 00:00:00 2001 From: Johannes Zillmann Date: Fri, 29 Jan 2021 14:13:50 +0100 Subject: [PATCH] Format values --- core/src/PdfParser.ts | 3 +- ui/src/App.svelte | 2 +- ui/src/Result.svelte | 14 ++-- ui/src/Table.svelte | 31 +++++++-- ui/src/Upload.svelte | 148 +++++++++++++++++++++--------------------- 5 files changed, 110 insertions(+), 88 deletions(-) diff --git a/core/src/PdfParser.ts b/core/src/PdfParser.ts index 89fa05d..8652815 100644 --- a/core/src/PdfParser.ts +++ b/core/src/PdfParser.ts @@ -11,7 +11,8 @@ import type TextItem from './TextItem'; */ export default class PdfParser { pdfjs: any; - columns = ['str', 'dir', 'width', 'height', 'transfom', 'fontName']; + columns = ['str', 'dir', 'width', 'height', 'transform', 'fontName']; + constructor(pdfjs: any) { this.pdfjs = pdfjs; } diff --git a/ui/src/App.svelte b/ui/src/App.svelte index f251674..14d2b9c 100644 --- a/ui/src/App.svelte +++ b/ui/src/App.svelte @@ -6,7 +6,7 @@
PDF to Markdown Converter
-
+
{#if $parseResult} {:else} diff --git a/ui/src/Result.svelte b/ui/src/Result.svelte index dda9d03..e4a8697 100644 --- a/ui/src/Result.svelte +++ b/ui/src/Result.svelte @@ -5,10 +5,12 @@ export let parseResult: ParseResult; -
-
Parsed {parseResult.pageCount()} pages with {parseResult.items.length} items
-
Title: {parseResult.metadata.title()}
-
Author: {parseResult.metadata.author()}
-
+
+
+
Parsed {parseResult.pageCount()} pages with {parseResult.items.length} items
+
Title: {parseResult.metadata.title()}
+
Author: {parseResult.metadata.author()}
+
- +
+ diff --git a/ui/src/Table.svelte b/ui/src/Table.svelte index 433fb6d..0d23cf4 100644 --- a/ui/src/Table.svelte +++ b/ui/src/Table.svelte @@ -27,10 +27,27 @@ openedPageIndex = false; focusedPage = undefined; } + + function format(value: object) { + const type = typeof value; + if (typeof value === 'number') { + return (value as number).toFixed(2); + } + if (typeof value === 'object' && typeof Array.isArray(value)) { + let array = value as Array; + if (array.length > 0 && typeof array[0] === 'number') { + array = (array.map((element) => + ((element as unknown) as number).toFixed(2) + ) as unknown) as Array; + } + return '[' + array.join(', ') + ']'; + } + return value; + } -
+
(openedPageIndex = !openedPageIndex)}> @@ -91,11 +108,11 @@
{#if !focused} focusOnPage(pageNumber)}> - + {:else} - + {/if}
@@ -103,9 +120,9 @@ {:else}
+ {#each columns as column} - + {/each} {/each} @@ -129,7 +146,7 @@ @apply whitespace-nowrap; position: -webkit-sticky; position: sticky; - top: 1.7em; + top: 2em; z-index: 2; } @@ -137,7 +154,7 @@ @apply px-1; position: -webkit-sticky; position: sticky; - top: 2.1em; + top: 2.4em; z-index: 2; } th:not(:first-child) { diff --git a/ui/src/Upload.svelte b/ui/src/Upload.svelte index 833b6ce..7cbfb10 100644 --- a/ui/src/Upload.svelte +++ b/ui/src/Upload.svelte @@ -41,83 +41,85 @@ } - -
-
- Load Example -
-
Debug
-
- - -
- (dragover = true)} - on:dragleave={() => (dragover = false)} - multiple={false} - noClick={false} - disableDefaultStyles={true}> -
- - - -
-
Drop your PDF file here...
-
Or click the box to select one...
-
Note: Your data stays locally in your browser.
-
- This tool converts a PDF file into a Markdown text format! Simply drag & drop your PDF file on the - upload area and go from there. Don't expect wonders, there are a lot of variances in generated PDF's - from different tools and different ages. No matter how good the parser works for your PDF, you will - have to invest a good amount of manuell work to complete it. -
-
+
+ +
+
+ Load Example
- -
+
Debug
+
- -
-
- {#if specifiedFileName} -
Parsing {specifiedFileName} ...
- {/if} - {#if parseProgress} -
- -
- {#each parseProgress.stages as stage, index} - {#if parseProgress.isProgressing(index)} -
-
- Parsing - {stage} - {parseProgress.stageDetails[index] ? parseProgress.stageDetails[index] : ''} -
-
- {:else if parseProgress.isComplete(index)} -
-
- Parsing - {stage} - {parseProgress.stageDetails[index] ? parseProgress.stageDetails[index] : ''} -
- -
- {/if} - {/each} + +
+ (dragover = true)} + on:dragleave={() => (dragover = false)} + multiple={false} + noClick={false} + disableDefaultStyles={true}> +
+ + + +
+
Drop your PDF file here...
+
Or click the box to select one...
+
Note: Your data stays locally in your browser.
+
+ This tool converts a PDF file into a Markdown text format! Simply drag & drop your PDF file on + the upload area and go from there. Don't expect wonders, there are a lot of variances in + generated PDF's from different tools and different ages. No matter how good the parser works for + your PDF, you will have to invest a good amount of manuell work to complete it. +
- {/if} - {#if rejectionError} -
{rejectionError}
- {/if} - {#await upload} - - {:catch error} -
Failed to parse '{specifiedFileName}': {error?.message}
- {/await} +
+
+ + +
+
+ {#if specifiedFileName} +
Parsing {specifiedFileName} ...
+ {/if} + {#if parseProgress} +
+ +
+ {#each parseProgress.stages as stage, index} + {#if parseProgress.isProgressing(index)} +
+
+ Parsing + {stage} + {parseProgress.stageDetails[index] ? parseProgress.stageDetails[index] : ''} +
+
+ {:else if parseProgress.isComplete(index)} +
+
+ Parsing + {stage} + {parseProgress.stageDetails[index] ? parseProgress.stageDetails[index] : ''} +
+ +
+ {/if} + {/each} +
+
+ {/if} + {#if rejectionError} +
{rejectionError}
+ {/if} + {#await upload} + + {:catch error} +
Failed to parse '{specifiedFileName}': {error?.message}
+ {/await} +
{/if} - {itemIdx}{itemIdx}{item.data[column]}{format(item.data[column])}