created a PoC for the client
This commit is contained in:
53
client-ionic/declarations/shared-operations.d.ts
vendored
Normal file
53
client-ionic/declarations/shared-operations.d.ts
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
declare module '@stirling-pdf/shared-operations/functions/editMetadata' {
|
||||
export type Metadata = {
|
||||
Title: string | null | undefined; // The title of the document.
|
||||
Author: string | null | undefined; // The author of the document.
|
||||
Subject: string | null | undefined; // The subject of the document.
|
||||
Keywords: string[] | null | undefined; // An array of keywords associated with the document.
|
||||
Producer: string | null | undefined; // The producer of the document.
|
||||
Creator: string | null | undefined; // The creator of the document.
|
||||
CreationDate: Date | null | undefined; // The date when the document was created.
|
||||
ModificationDate: Date | null | undefined; // The date when the document was last modified.
|
||||
}
|
||||
export async function editMetadata(snapshot: string | Uint8Array | ArrayBuffer, metadata: Metadata): Promise<Uint8Array>;
|
||||
}
|
||||
|
||||
declare module '@stirling-pdf/shared-operations/functions/extractPages' {
|
||||
export async function extractPages(snapshot: string | Uint8Array | ArrayBuffer, pagesToExtractArray: number[]): Promise<Uint8Array>;
|
||||
export async function createSubDocument(pdfDoc: typeof import("pdf-lib").PDFDocument, pagesToExtractArray: number[])
|
||||
}
|
||||
|
||||
declare module '@stirling-pdf/shared-operations/functions/mergePDFs' {
|
||||
export async function mergePDFs(snapshots: (string | Uint8Array | ArrayBuffer)[]): Promise<Uint8Array>;
|
||||
}
|
||||
|
||||
declare module '@stirling-pdf/shared-operations/functions/organizePages' {
|
||||
export async function organizePages(
|
||||
snapshot: string | Uint8Array | ArrayBuffer,
|
||||
operation: "CUSTOM_PAGE_ORDER" |
|
||||
"REVERSE_ORDER" |
|
||||
"DUPLEX_SORT" |
|
||||
"BOOKLET_SORT" |
|
||||
"ODD_EVEN_SPLIT" |
|
||||
"REMOVE_FIRST" |
|
||||
"REMOVE_LAST" |
|
||||
"REMOVE_FIRST_AND_LAST",
|
||||
customOrderString: string): Promise<Uint8Array>;
|
||||
}
|
||||
|
||||
declare module '@stirling-pdf/shared-operations/functions/rotatePages' {
|
||||
export async function rotatePages(snapshot: string | Uint8Array | ArrayBuffer, rotation: number): Promise<Uint8Array>;
|
||||
}
|
||||
|
||||
declare module '@stirling-pdf/shared-operations/functions/scaleContent' {
|
||||
export async function scaleContent(snapshot: string | Uint8Array | ArrayBuffer, scaleFactor: number): Promise<Uint8Array>;
|
||||
}
|
||||
|
||||
declare module '@stirling-pdf/shared-operations/functions/scalePage' {
|
||||
export async function scalePage(snapshot: string | Uint8Array | ArrayBuffer, pageSize: {width:number,height:number}): Promise<Uint8Array>;
|
||||
}
|
||||
|
||||
declare module '@stirling-pdf/shared-operations/functions/splitPDF' {
|
||||
export async function splitPDF(snapshot: string | Uint8Array | ArrayBuffer, splitAfterPageArray: number[]): Promise<Uint8Array>;
|
||||
}
|
||||
@@ -17,14 +17,15 @@
|
||||
"@capawesome/capacitor-file-picker": "^5.1.1",
|
||||
"@ionic/react": "^7.0.0",
|
||||
"@ionic/react-router": "^7.0.0",
|
||||
"@stirling-pdf/shared-operations": "*",
|
||||
"@types/react-router": "^5.1.20",
|
||||
"@types/react-router-dom": "^5.3.3",
|
||||
"ionicons": "^7.0.0",
|
||||
"pdf-lib": "^1.17.1",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router": "^5.3.4",
|
||||
"react-router-dom": "^5.3.4",
|
||||
"@stirling-pdf/shared-operations": "*"
|
||||
"react-router-dom": "^5.3.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonButton } from '@ionic/react';
|
||||
import ExploreContainer from '../components/ExploreContainer';
|
||||
import './Home.css';
|
||||
import "../../../server-node/public/wasm/pdfcpu-wrapper-browser.js"
|
||||
import { splitPDF } from '../utils/pdf-operations.js';
|
||||
import { rotatePages } from '../utils/pdf-operations.js';
|
||||
|
||||
import { FilePicker } from '@capawesome/capacitor-file-picker';
|
||||
|
||||
async function testFunction() {
|
||||
console.log("Test Function for Button Click");
|
||||
console.log(splitPDF);
|
||||
console.log(rotatePages);
|
||||
async function rotate90() {
|
||||
console.log("Test rotate 90 with Button Click");
|
||||
|
||||
const result = await FilePicker.pickFiles({
|
||||
types: ['application/pdf'],
|
||||
multiple: true,
|
||||
});
|
||||
const pickedFiles = await FilePicker.pickFiles({
|
||||
types: ['application/pdf'],
|
||||
multiple: false,
|
||||
});
|
||||
const file = pickedFiles.files[0];
|
||||
|
||||
const buffer = await file.blob?.arrayBuffer();
|
||||
if (!buffer) return;
|
||||
|
||||
const rotated = await rotatePages(buffer, 90)
|
||||
|
||||
console.log(result);
|
||||
console.log(rotated);
|
||||
}
|
||||
|
||||
|
||||
const Home: React.FC = () => {
|
||||
return (
|
||||
<IonPage>
|
||||
@@ -32,7 +37,7 @@ const Home: React.FC = () => {
|
||||
<IonTitle size="large">Blank</IonTitle>
|
||||
</IonToolbar>
|
||||
</IonHeader>
|
||||
<IonButton onClick={testFunction}>Default</IonButton>
|
||||
<IonButton onClick={rotate90}>Rotate 90</IonButton>
|
||||
</IonContent>
|
||||
</IonPage>
|
||||
);
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
// PDFLib gets importet via index.html script-tag
|
||||
import * as pdfcpuWraopper from "../../../server-node/public/wasm/pdfcpu-wrapper-browser.js";
|
||||
|
||||
import { editMetadata as dependantEditMetadata} from "@stirling-pdf/shared-operations/functions/editMetadata.js";
|
||||
import { extractPages as dependantExtractPages } from "@stirling-pdf/shared-operations/functions/extractPages.js";
|
||||
import { impose as dependantImpose } from '@stirling-pdf/shared-operations/functions/impose.js';
|
||||
import { mergePDFs as dependantMergePDFs } from '@stirling-pdf/shared-operations/functions/mergePDFs.js';
|
||||
import { organizePages as dependantOrganizePages } from '@stirling-pdf/shared-operations/functions/organizePages.js';
|
||||
import { rotatePages as dependantRotatePages } from '@stirling-pdf/shared-operations/functions/rotatePages.js';
|
||||
import { scaleContent as dependantScaleContent} from '@stirling-pdf/shared-operations/functions/scaleContent.js';
|
||||
import { scalePage as dependantScalePage } from '@stirling-pdf/shared-operations/functions/scalePage.js';
|
||||
import { splitPDF as dependantSplitPDF } from '@stirling-pdf/shared-operations/functions/splitPDF.js';
|
||||
|
||||
export async function editMetadata(snapshot, metadata) {
|
||||
return dependantEditMetadata(snapshot, metadata, PDFLib);
|
||||
}
|
||||
|
||||
export async function extractPages(snapshot, pagesToExtractArray) {
|
||||
return dependantExtractPages(snapshot, pagesToExtractArray, PDFLib);
|
||||
}
|
||||
|
||||
export async function impose(snapshot, nup, format) {
|
||||
return dependantImpose(snapshot, nup, format, pdfcpuWraopper);
|
||||
}
|
||||
|
||||
export async function mergePDFs(snapshots) {
|
||||
return dependantMergePDFs(snapshots, PDFLib);
|
||||
}
|
||||
|
||||
export async function organizePages(snapshot, operation, customOrderString) {
|
||||
return dependantOrganizePages(snapshot, operation, customOrderString, PDFLib);
|
||||
}
|
||||
|
||||
export async function rotatePages(snapshot, rotation) {
|
||||
return dependantRotatePages(snapshot, rotation, PDFLib);
|
||||
}
|
||||
|
||||
export async function scaleContent(snapshot, scaleFactor) {
|
||||
return dependantScaleContent(snapshot, scaleFactor, PDFLib);
|
||||
}
|
||||
|
||||
export async function scalePage(snapshot, pageSize) {
|
||||
return dependantScalePage(snapshot, pageSize, PDFLib);
|
||||
}
|
||||
|
||||
export async function splitPDF(snapshot, splitAfterPageArray) {
|
||||
return dependantSplitPDF(snapshot, splitAfterPageArray, PDFLib);
|
||||
}
|
||||
53
client-ionic/src/utils/pdf-operations.ts
Normal file
53
client-ionic/src/utils/pdf-operations.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
// Import injected libraries here!
|
||||
|
||||
import { Metadata, editMetadata as dependantEditMetadata} from "@stirling-pdf/shared-operations/functions/editMetadata";
|
||||
import { extractPages as dependantExtractPages } from "@stirling-pdf/shared-operations/functions/extractPages";
|
||||
import { mergePDFs as dependantMergePDFs } from '@stirling-pdf/shared-operations/functions/mergePDFs';
|
||||
import { organizePages as dependantOrganizePages } from '@stirling-pdf/shared-operations/functions/organizePages';
|
||||
import { rotatePages as dependantRotatePages } from '@stirling-pdf/shared-operations/functions/rotatePages';
|
||||
import { scaleContent as dependantScaleContent} from '@stirling-pdf/shared-operations/functions/scaleContent';
|
||||
import { scalePage as dependantScalePage } from '@stirling-pdf/shared-operations/functions/scalePage';
|
||||
import { splitPDF as dependantSplitPDF } from '@stirling-pdf/shared-operations/functions/splitPDF';
|
||||
|
||||
export async function editMetadata(snapshot: string | Uint8Array | ArrayBuffer, metadata: Metadata) {
|
||||
return dependantEditMetadata(snapshot, metadata);
|
||||
}
|
||||
|
||||
export async function extractPages(snapshot: string | Uint8Array | ArrayBuffer, pagesToExtractArray: number[]) {
|
||||
return dependantExtractPages(snapshot, pagesToExtractArray);
|
||||
}
|
||||
|
||||
export async function mergePDFs(snapshots: (string | Uint8Array | ArrayBuffer)[]) {
|
||||
return dependantMergePDFs(snapshots);
|
||||
}
|
||||
|
||||
export async function organizePages(
|
||||
snapshot: string | Uint8Array | ArrayBuffer,
|
||||
operation: "CUSTOM_PAGE_ORDER" |
|
||||
"REVERSE_ORDER" |
|
||||
"DUPLEX_SORT" |
|
||||
"BOOKLET_SORT" |
|
||||
"ODD_EVEN_SPLIT" |
|
||||
"REMOVE_FIRST" |
|
||||
"REMOVE_LAST" |
|
||||
"REMOVE_FIRST_AND_LAST",
|
||||
customOrderString: string) {
|
||||
return dependantOrganizePages(snapshot, operation, customOrderString);
|
||||
}
|
||||
|
||||
export async function rotatePages(snapshot: string | Uint8Array | ArrayBuffer, rotation: number) {
|
||||
return dependantRotatePages(snapshot, rotation);
|
||||
}
|
||||
|
||||
export async function scaleContent(snapshot: string | Uint8Array | ArrayBuffer, scaleFactor: number) {
|
||||
return dependantScaleContent(snapshot, scaleFactor);
|
||||
}
|
||||
|
||||
export async function scalePage(snapshot: string | Uint8Array | ArrayBuffer, pageSize: { width: number; height: number; }) {
|
||||
return dependantScalePage(snapshot, pageSize);
|
||||
}
|
||||
|
||||
export async function splitPDF(snapshot: string | Uint8Array | ArrayBuffer, splitAfterPageArray: number[]) {
|
||||
return dependantSplitPDF(snapshot, splitAfterPageArray);
|
||||
}
|
||||
@@ -16,6 +16,9 @@
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src", "../shared-operations/packages/wasm", "../server-node/public/utils/pdfcpu-wrapper-node.js"],
|
||||
"include": [
|
||||
"src",
|
||||
"declarations/*.d.ts"
|
||||
],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user