Merge branch 'feat/pdf-fastweb' into chore/all-my-stuffs

# Conflicts:
#	components.d.ts
#	package.json
#	pnpm-lock.yaml
#	src/tools/index.ts
This commit is contained in:
ShareVB committed 2024-11-03 21:15:45 +01:00
commit 79b3961159
4 files changed
+104 -1

No files matched your search

+1 -1
View File
@@ -5299,7 +5299,7 @@ packages:
/@vueuse/shared@10.0.0(vue@3.3.4):
resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==}
dependencies:
vue-demi: 0.14.5(vue@3.3.4)
vue-demi: 0.14.10(vue@3.3.4)
transitivePeerDependencies:
- '@vue/composition-api'
- vue
+4
View File
@@ -146,6 +146,7 @@ import { tool as macAddressLookup } from './mac-address-lookup';
import { tool as xmlFormatter } from './xml-formatter';
import { tool as dockerComposeToDockerRunConverter } from './docker-compose-to-docker-run-converter';
import { tool as pdfEncrypt } from './pdf-encrypt';
import { tool as pdfLinearize } from './pdf-linearize';
import { tool as yamlViewer } from './yaml-viewer';
import { tool as barcodeReader } from './barcode-reader';
import { tool as barcodeGenerator } from './barcode-generator';
@@ -174,6 +175,9 @@ export const toolsByCategory: ToolCategory[] = [
passwordStrengthAnalyser,
pdfSignatureChecker,
pdfEncrypt,
passwordStrengthAnalyser,
pdfSignatureChecker,
pdfLinearize,
],
},
{
+12
View File
@@ -0,0 +1,12 @@
import { FileLike } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Pdf Linearize/FastWeb',
path: '/pdf-linearize',
description: 'Create a Linearized version of a PDF (turn to FastWeb)',
keywords: ['pdf', 'linearize', 'fastweb'],
component: () => import('./pdf-linearize.vue'),
icon: FileLike,
createdAt: new Date('2024-01-09'),
});
+87
View File
@@ -0,0 +1,87 @@
<script setup lang="ts">
import { Base64 } from 'js-base64';
import createQPDFModule from 'qpdf-wasm-esm-embedded';
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle');
const file = ref<File | null>(null);
const base64OutputPDF = ref('');
const logs = ref<string[]>([]);
const fileName = ref('');
const fileExtension = ref('pdf');
const { download } = useDownloadFileFromBase64(
{
source: base64OutputPDF,
filename: fileName,
extension: fileExtension,
});
async function onFileUploaded(uploadedFile: File) {
file.value = uploadedFile;
const fileBuffer = await uploadedFile.arrayBuffer();
fileName.value = `linearized_${uploadedFile.name}`;
status.value = 'processing';
try {
const outPdfBuffer = await callMainWithInOutPdf(fileBuffer,
[
'--linearize',
'--warning-exit-0',
'--verbose',
'in.pdf',
'out.pdf',
],
0);
base64OutputPDF.value = `data:application/pdf;base64,${Base64.fromUint8Array(outPdfBuffer)}`;
status.value = 'done';
download();
}
catch (e) {
status.value = 'error';
}
}
async function callMainWithInOutPdf(data: ArrayBuffer, args: string[], expected_exitcode: number) {
logs.value = [];
const mod = await createQPDFModule({
print(text: string) {
logs.value.push(text);
},
printErr(text: string) {
logs.value.push(text);
},
});
mod.FS.writeFile('in.pdf', new Uint8Array(data));
const ret = mod.callMain(args);
if (expected_exitcode !== ret) {
throw new Error('Process run failed');
}
return mod.FS.readFile('out.pdf');
}
</script>
<template>
<div>
<div style="flex: 0 0 100%">
<div mx-auto max-w-600px>
<c-file-upload title="Drag and drop a PDF file here, or click to select a file" accept=".pdf" @file-upload="onFileUploaded" />
</div>
</div>
<div mt-3 flex justify-center>
<c-alert v-if="status === 'error'" type="error">
An error occured processing {{ fileName }}
</c-alert>
<n-spin
v-if="status === 'processing'"
size="small"
/>
</div>
<c-card title="Logs">
<pre>{{ logs.join('\n') }}</pre>
</c-card>
</div>
</template>