Created end to end demo
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { useState } from "react";
|
||||
import reactLogo from "./assets/react.svg";
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
import { appendToFilename } from './utils/file-utils';
|
||||
import { openFiles, downloadFile } from './utils/tauri-wrapper'
|
||||
import { rotatePages } from './utils/pdf-operations';
|
||||
import "./App.css";
|
||||
|
||||
console.log(invoke)
|
||||
|
||||
function App() {
|
||||
const [greetMsg, setGreetMsg] = useState("");
|
||||
const [name, setName] = useState("");
|
||||
@@ -13,6 +13,33 @@ function App() {
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
setGreetMsg(`Hello, ${name}! You've been greeted from Tauri!`);
|
||||
}
|
||||
async function rotatePdf() {
|
||||
var selected = await openFiles({
|
||||
multiple: false,
|
||||
filters: [{
|
||||
name: 'PDF',
|
||||
extensions: ['pdf']
|
||||
}]
|
||||
})
|
||||
|
||||
if (!selected) return;
|
||||
selected
|
||||
|
||||
const rotated = await rotatePages(selected[0].data, 90);
|
||||
console.log(rotated);
|
||||
|
||||
const appendedPath = appendToFilename(selected[0].getPath(), "_rotated");
|
||||
console.log(appendedPath)
|
||||
|
||||
await downloadFile(rotated, {
|
||||
defaultPath: appendedPath,
|
||||
filters: [{
|
||||
name: "PDF",
|
||||
extensions: ['pdf']
|
||||
}]
|
||||
});
|
||||
console.log("done!")
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container">
|
||||
@@ -47,6 +74,8 @@ function App() {
|
||||
<button type="submit">Greet</button>
|
||||
</form>
|
||||
|
||||
<button onClick={rotatePdf}>Rotate 90</button>
|
||||
|
||||
<p>{greetMsg}</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
53
client-tauri/src/declarations/shared-operations.d.ts
vendored
Normal file
53
client-tauri/src/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>;
|
||||
}
|
||||
9
client-tauri/src/utils/file-utils.ts
Normal file
9
client-tauri/src/utils/file-utils.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
export function appendToFilename(inputPath: string, toAppend: string) {
|
||||
const parts = inputPath.split('.');
|
||||
if (parts.length > 1) {
|
||||
parts[parts.length-2] = parts[parts.length-2] + toAppend;
|
||||
}
|
||||
return parts.join(".");
|
||||
}
|
||||
53
client-tauri/src/utils/pdf-operations.ts
Normal file
53
client-tauri/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);
|
||||
}
|
||||
Reference in New Issue
Block a user