Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
d86a83d515 | |||
8dd9bea8bb | |||
1ddb442661 | |||
871f152f2d | |||
215273b44d | |||
aa915b2a61 | |||
7e169b4972 | |||
f5d1becf03 | |||
14618e7f8e | |||
45ea0ff83f | |||
ae65fcdcb5 | |||
8e63e01840 | |||
84efa9d89c | |||
0d1b76ad8a | |||
b1c8b4f490 | |||
992b248839 | |||
c0b67ba82c | |||
ab8d5bfc1b | |||
f88c75e3bc | |||
75ef50d072 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
name: Default (not tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags-ignore:
|
||||
- '**'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Install pnpm and npmci
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
|
||||
- name: Run npm prepare
|
||||
run: npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
||||
name: Default (tags)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
env:
|
||||
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||
|
||||
jobs:
|
||||
security:
|
||||
runs-on: ubuntu-latest
|
||||
continue-on-error: true
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Audit production dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --prod
|
||||
continue-on-error: true
|
||||
|
||||
- name: Audit development dependencies
|
||||
run: |
|
||||
npmci command npm config set registry https://registry.npmjs.org
|
||||
npmci command pnpm audit --audit-level=high --dev
|
||||
continue-on-error: true
|
||||
|
||||
test:
|
||||
if: ${{ always() }}
|
||||
needs: security
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Test stable
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm test
|
||||
|
||||
- name: Test build
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
npmci npm build
|
||||
|
||||
release:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Release
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm publish
|
||||
|
||||
metadata:
|
||||
needs: test
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ env.IMAGE }}
|
||||
continue-on-error: true
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Prepare
|
||||
run: |
|
||||
pnpm install -g pnpm
|
||||
pnpm install -g @shipzone/npmci
|
||||
npmci npm prepare
|
||||
|
||||
- name: Code quality
|
||||
run: |
|
||||
npmci command npm install -g typescript
|
||||
npmci npm install
|
||||
|
||||
- name: Trigger
|
||||
run: npmci trigger
|
||||
|
||||
- name: Build docs and upload artifacts
|
||||
run: |
|
||||
npmci node install stable
|
||||
npmci npm install
|
||||
pnpm install -g @git.zone/tsdoc
|
||||
npmci command tsdoc
|
||||
continue-on-error: true
|
@ -13,6 +13,7 @@ stages:
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- apt-get update && apt-get install -y ocrmypdf
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
@ -124,7 +125,7 @@ pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci command npm install -g @git.zone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
|
@ -2,17 +2,31 @@
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartocr",
|
||||
"shortDescription": "an ocr module using ocrmypdf",
|
||||
"npmPackagename": "@pushrocks/smartocr",
|
||||
"npmPackagename": "@push.rocks/smartocr",
|
||||
"license": "MIT",
|
||||
"projectDomain": "push.rocks"
|
||||
"projectDomain": "push.rocks",
|
||||
"description": "A module that performs optical character recognition (OCR) using ocrmypdf.",
|
||||
"keywords": [
|
||||
"OCR",
|
||||
"optical character recognition",
|
||||
"ocrmypdf",
|
||||
"text extraction",
|
||||
"PDF processing",
|
||||
"machine learning",
|
||||
"document analysis",
|
||||
"text recognition"
|
||||
]
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
27192
package-lock.json
generated
27192
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
53
package.json
53
package.json
@ -1,26 +1,32 @@
|
||||
{
|
||||
"name": "@pushrocks/smartocr",
|
||||
"version": "1.0.2",
|
||||
"name": "@push.rocks/smartocr",
|
||||
"version": "1.0.9",
|
||||
"private": false,
|
||||
"description": "an ocr module using ocrmypdf",
|
||||
"description": "A module that performs optical character recognition (OCR) using ocrmypdf.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)"
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tsbundle": "^1.0.78",
|
||||
"@gitzone/tstest": "^1.0.44",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^14.11.2",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
"@git.zone/tsbuild": "^2.1.66",
|
||||
"@git.zone/tsbundle": "^2.0.8",
|
||||
"@git.zone/tsrun": "^1.2.46",
|
||||
"@git.zone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.8",
|
||||
"@types/node": "^20.12.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"@push.rocks/smartfile": "^11.0.14",
|
||||
"@push.rocks/smartpath": "^5.0.14",
|
||||
"@push.rocks/smartpromise": "^4.0.2",
|
||||
"@push.rocks/smartshell": "^3.0.3",
|
||||
"@push.rocks/smartunique": "^3.0.3"
|
||||
},
|
||||
"dependencies": {},
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
@ -35,5 +41,24 @@
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"OCR",
|
||||
"optical character recognition",
|
||||
"ocrmypdf",
|
||||
"text extraction",
|
||||
"PDF processing",
|
||||
"machine learning",
|
||||
"document analysis",
|
||||
"text recognition"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smartocr.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://code.foss.global/push.rocks/smartocr/issues"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/smartocr",
|
||||
"type": "module"
|
||||
}
|
4671
pnpm-lock.yaml
generated
Normal file
4671
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
105
readme.md
105
readme.md
@ -1,39 +1,90 @@
|
||||
# @pushrocks/smartocr
|
||||
# @push.rocks/smartocr
|
||||
an ocr module using ocrmypdf
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartocr)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartocr)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartocr)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartocr/)
|
||||
## Install
|
||||
To install `@push.rocks/smartocr`, use the following command with npm:
|
||||
|
||||
## Status for master
|
||||
```bash
|
||||
npm install @push.rocks/smartocr --save
|
||||
```
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
This module depends on a few external utilities like `ocrmypdf`, so make sure you have these installed and available in your system's PATH. Consult the `ocrmypdf` documentation for installation instructions suitable for your operating system.
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class intellisense
|
||||
This module provides a TypeScript interface for OCR processing of PDF documents using `ocrmypdf`, encapsulated in the `SmartOcr` class. Here's how to leverage it in your TypeScript project.
|
||||
|
||||
## Contribution
|
||||
### Preparing Your Project
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
First, ensure your TypeScript configuration is set up to handle ESModule syntax. You will also need to have Node.js and the external `ocrmypdf` tool installed on your system.
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
### Basic Setup
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
```typescript
|
||||
import { SmartOcr } from '@push.rocks/smartocr';
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
async function runOcrOnPdf(pdfFilePath: string): Promise<Buffer> {
|
||||
// Initialize the SmartOcr instance
|
||||
const smartOcrInstance = await SmartOcr.createAndInit();
|
||||
|
||||
// Load your PDF file into a Buffer, this can be from a file or even a remote source
|
||||
const pdfBuffer = await fs.promises.readFile(pdfFilePath);
|
||||
|
||||
// Process the PDF Buffer through SmartOcr
|
||||
const processedBuffer = await smartOcrInstance.processPdfBuffer(pdfBuffer);
|
||||
|
||||
return processedBuffer;
|
||||
}
|
||||
|
||||
// Replace './path/to/your/document.pdf' with the actual path to the PDF document you want to OCR
|
||||
const ocredPdfBuffer = await runOcrOnPdf('./path/to/your/document.pdf');
|
||||
|
||||
// You can now save this buffer to a file, or use it as needed in your application
|
||||
await fs.promises.writeFile('./path/to/output/document_ocr.pdf', ocredPdfBuffer);
|
||||
```
|
||||
|
||||
In the example above, we import the `SmartOcr` class and use it to process a PDF by passing a `Buffer` of the PDF file to the `processPdfBuffer` method. The method returns a `Buffer` of the processed PDF which includes a text layer added by OCR.
|
||||
|
||||
### Advanced Usage
|
||||
|
||||
The `SmartOcr` class maintains an internal `smartshell` instance to interface with the `ocrmypdf` command. This setup is abstracted away, ensuring you don't need to manage or understand the underlying shell commands to use OCR functionality in your application.
|
||||
|
||||
### Handling OCR Result
|
||||
|
||||
The result of the `processPdfBuffer` is a `Buffer` that contains the OCR-processed PDF. This buffer can be directly written to a file system or further manipulated in memory, depending on your application's needs.
|
||||
|
||||
### Error Handling
|
||||
|
||||
It's important to handle errors that may arise from reading files or the OCR process. The OCR process depends on the external `ocrmypdf` utility, so errors can occur if the utility encounters unsupported PDF structures or if there are issues with the installation of `ocrmypdf`.
|
||||
|
||||
```typescript
|
||||
try {
|
||||
const ocredPdfBuffer = await runOcrOnPdf('./path/to/your/document.pdf');
|
||||
await fs.promises.writeFile('./path/to/output/document_ocr.pdf', ocredPdfBuffer);
|
||||
} catch (error) {
|
||||
console.error('Failed to OCR the document:', error);
|
||||
}
|
||||
```
|
||||
|
||||
### Conclusion
|
||||
|
||||
The `@push.rocks/smartocr` library simplifies adding OCR capabilities to your TypeScript applications by abstracting away the complexity of interfacing with `ocrmypdf`. With minimal setup, you can start processing PDF documents to add searchable text layers, making this library a valuable tool for any project that requires OCR functionality.
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
BIN
test/demo_without_textlayer.pdf
Normal file
BIN
test/demo_without_textlayer.pdf
Normal file
Binary file not shown.
19
test/test.ts
19
test/test.ts
@ -1,8 +1,19 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartocr from '../ts/index';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import * as smartocr from '../ts/index.js';
|
||||
|
||||
tap.test('first test', async () => {
|
||||
console.log(smartocr.standardExport);
|
||||
let testOcrInstance: smartocr.SmartOcr;
|
||||
|
||||
tap.test('should create a valid instance of Smartocr', async () => {
|
||||
testOcrInstance = await smartocr.SmartOcr.createAndInit();
|
||||
expect(testOcrInstance).toBeInstanceOf(smartocr.SmartOcr);
|
||||
});
|
||||
|
||||
tap.test('should ocr a pdfBuffer', async () => {
|
||||
const smartfile = await import('@push.rocks/smartfile');
|
||||
const pdfBuffer = (await smartfile.SmartFile.fromFilePath('./test/demo_without_textlayer.pdf'))
|
||||
.contentBuffer;
|
||||
const resultBuffer = await testOcrInstance.processPdfBuffer(pdfBuffer);
|
||||
console.log(resultBuffer);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartocr',
|
||||
version: '1.0.9',
|
||||
description: 'A module that performs optical character recognition (OCR) using ocrmypdf.'
|
||||
}
|
@ -1,3 +1 @@
|
||||
import * as plugins from './smartocr.plugins';
|
||||
|
||||
export let standardExport = 'Hi there! :) This is an exported string';
|
||||
export * from './smartocr.classes.smartocr.js';
|
||||
|
40
ts/smartocr.classes.smartocr.ts
Normal file
40
ts/smartocr.classes.smartocr.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import * as plugins from './smartocr.plugins.js';
|
||||
import * as paths from './smartocr.paths.js';
|
||||
|
||||
export class SmartOcr {
|
||||
// STATIC
|
||||
public static async createAndInit() {
|
||||
const smartocrInstance = new SmartOcr();
|
||||
await smartocrInstance.init();
|
||||
return smartocrInstance;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
|
||||
public readyDeferred = plugins.smartpromise.defer();
|
||||
public smartshellInstance: plugins.smartshell.Smartshell;
|
||||
|
||||
public async processPdfBuffer (pdfBufferArg: Buffer): Promise<Buffer> {
|
||||
const uniqueString = plugins.smartunique.uni('doc_');
|
||||
const originalPath = plugins.path.join(paths.noGitDir, `${uniqueString}.pdf`);
|
||||
const processedPath = plugins.path.join(paths.noGitDir, `${uniqueString}_processed.pdf`);
|
||||
const originalSmartfile = await plugins.smartfile.SmartFile.fromBuffer(originalPath, pdfBufferArg);
|
||||
await originalSmartfile.write();
|
||||
await this.smartshellInstance.exec(`ocrmypdf --rotate-pages ${originalPath} ${processedPath}`);
|
||||
const processedSmartfile = await plugins.smartfile.SmartFile.fromFilePath(processedPath);
|
||||
await originalSmartfile.delete();
|
||||
await processedSmartfile.delete();
|
||||
return processedSmartfile.contentBuffer;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash'
|
||||
});
|
||||
}
|
||||
|
||||
public async init() {
|
||||
await plugins.smartfile.fs.ensureDir(paths.noGitDir);
|
||||
const result = await plugins.smartshell.which('ocrmypdf');
|
||||
}
|
||||
}
|
4
ts/smartocr.paths.ts
Normal file
4
ts/smartocr.paths.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import * as plugins from './smartocr.plugins.js';
|
||||
|
||||
export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../');
|
||||
export const noGitDir = plugins.path.join(packageDir, './.nogit');
|
@ -1,2 +1,21 @@
|
||||
const removeme = {};
|
||||
export { removeme };
|
||||
// node native
|
||||
import * as path from 'path';
|
||||
|
||||
export {
|
||||
path
|
||||
}
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
import * as smartunique from '@push.rocks/smartunique';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
export {
|
||||
smartfile,
|
||||
smartshell,
|
||||
smartunique,
|
||||
smartpath,
|
||||
smartpromise
|
||||
}
|
||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user