mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-19 22:19:36 +02:00
feat: compression level
This commit is contained in:
48
.idea/workspace.xml
generated
48
.idea/workspace.xml
generated
@@ -4,13 +4,11 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="refactor: compress pdf">
|
||||
<list default="true" id="b30e2810-c4c1-4aad-b134-794e52cc1c7d" name="Changes" comment="fix: path">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/lib/background-worker.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/ghostscript/background-worker.js" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/lib/gs-worker.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/ghostscript/gs-worker.js" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/lib/worker-init.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/ghostscript/worker-init.js" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/lib/ghostscript/background-worker.js" beforeDir="false" afterPath="$PROJECT_DIR$/src/lib/ghostscript/background-worker.js" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/index.tsx" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/service.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/tools/pdf/compress-pdf/service.ts" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/tsconfig.json" beforeDir="false" afterPath="$PROJECT_DIR$/tsconfig.json" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -411,22 +409,6 @@
|
||||
<workItem from="1743397561176" duration="25000" />
|
||||
<workItem from="1743458576265" duration="13083000" />
|
||||
</task>
|
||||
<task id="LOCAL-00135" summary="feat: jakarta font">
|
||||
<option name="closed" value="true" />
|
||||
<created>1740665609483</created>
|
||||
<option name="number" value="00135" />
|
||||
<option name="presentableId" value="LOCAL-00135" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1740665609483</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00136" summary="chore: img">
|
||||
<option name="closed" value="true" />
|
||||
<created>1740680778110</created>
|
||||
<option name="number" value="00136" />
|
||||
<option name="presentableId" value="LOCAL-00136" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1740680778110</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00137" summary="docs: readme">
|
||||
<option name="closed" value="true" />
|
||||
<created>1740788899030</created>
|
||||
@@ -803,7 +785,23 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1743644703042</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="184" />
|
||||
<task id="LOCAL-00184" summary="refactor: lib">
|
||||
<option name="closed" value="true" />
|
||||
<created>1743644942488</created>
|
||||
<option name="number" value="00184" />
|
||||
<option name="presentableId" value="LOCAL-00184" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1743644942488</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00185" summary="fix: path">
|
||||
<option name="closed" value="true" />
|
||||
<created>1743645074051</created>
|
||||
<option name="number" value="00185" />
|
||||
<option name="presentableId" value="LOCAL-00185" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1743645074051</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="186" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -850,8 +848,6 @@
|
||||
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
|
||||
<option name="CHECK_NEW_TODO" value="false" />
|
||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
||||
<MESSAGE value="fix: prettify json" />
|
||||
<MESSAGE value="refactor: sum" />
|
||||
<MESSAGE value="fix: tools by category scroll" />
|
||||
<MESSAGE value="fix: missing meta" />
|
||||
<MESSAGE value="feat: trim video" />
|
||||
@@ -875,7 +871,9 @@
|
||||
<MESSAGE value="fix: stars button width for 1k+ " />
|
||||
<MESSAGE value="feat: compress pdf" />
|
||||
<MESSAGE value="refactor: compress pdf" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="refactor: compress pdf" />
|
||||
<MESSAGE value="refactor: lib" />
|
||||
<MESSAGE value="fix: path" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="fix: path" />
|
||||
</component>
|
||||
<component name="XSLT-Support.FileAssociations.UIState">
|
||||
<expand />
|
||||
|
@@ -5,6 +5,23 @@ function loadScript() {
|
||||
var Module;
|
||||
|
||||
function _GSPS2PDF(dataStruct, responseCallback) {
|
||||
const compressionLevel = dataStruct.compressionLevel || 'medium';
|
||||
|
||||
// Set PDF settings based on compression level
|
||||
let pdfSettings;
|
||||
switch (compressionLevel) {
|
||||
case 'low':
|
||||
pdfSettings = '/printer'; // Higher quality, less compression
|
||||
break;
|
||||
case 'medium':
|
||||
pdfSettings = '/ebook'; // Medium quality and compression
|
||||
break;
|
||||
case 'high':
|
||||
pdfSettings = '/screen'; // Lower quality, higher compression
|
||||
break;
|
||||
default:
|
||||
pdfSettings = '/ebook'; // Default to medium
|
||||
}
|
||||
// first download the ps data
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', dataStruct.psDataURL);
|
||||
@@ -33,7 +50,7 @@ function _GSPS2PDF(dataStruct, responseCallback) {
|
||||
arguments: [
|
||||
'-sDEVICE=pdfwrite',
|
||||
'-dCompatibilityLevel=1.4',
|
||||
'-dPDFSETTINGS=/ebook',
|
||||
`-dPDFSETTINGS=${pdfSettings}`,
|
||||
'-DNOPAUSE',
|
||||
'-dQUIET',
|
||||
'-dBATCH',
|
||||
|
@@ -152,7 +152,6 @@ export default function CompressPdf({
|
||||
setInput={setInput}
|
||||
initialValues={initialValues}
|
||||
compute={compute}
|
||||
exampleCards={exampleCards}
|
||||
inputComponent={
|
||||
<ToolPdfInput
|
||||
value={input}
|
||||
@@ -175,22 +174,23 @@ export default function CompressPdf({
|
||||
title: 'Compression Settings',
|
||||
component: (
|
||||
<Box>
|
||||
<Typography variant="subtitle2" sx={{ mb: 1 }}>
|
||||
Compression Level
|
||||
</Typography>
|
||||
|
||||
{compressionOptions.map((option) => (
|
||||
<SimpleRadio
|
||||
key={option.value}
|
||||
title={option.label}
|
||||
description={option.description}
|
||||
checked={values.compressionLevel === option.value}
|
||||
onClick={() => {
|
||||
updateField('compressionLevel', option.value);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
<Box>
|
||||
<Typography variant="subtitle2" sx={{ mb: 1 }}>
|
||||
Compression Level
|
||||
</Typography>
|
||||
|
||||
{compressionOptions.map((option) => (
|
||||
<SimpleRadio
|
||||
key={option.value}
|
||||
title={option.label}
|
||||
description={option.description}
|
||||
checked={values.compressionLevel === option.value}
|
||||
onClick={() => {
|
||||
updateField('compressionLevel', option.value);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</Box>
|
||||
{fileInfo && (
|
||||
<Box
|
||||
sx={{
|
||||
@@ -217,27 +217,6 @@ export default function CompressPdf({
|
||||
)
|
||||
}
|
||||
]}
|
||||
toolInfo={{
|
||||
title: 'How to Use the Compress PDF Tool',
|
||||
description: `This tool allows you to compress PDF files securely in your browser using Ghostscript, a powerful PDF processing engine. Your files never leave your device, ensuring complete privacy and security.
|
||||
|
||||
Choose a compression level:
|
||||
- Low Compression: Slightly reduces file size with minimal quality loss (72 dpi images)
|
||||
- Medium Compression: Balances between file size and quality (150 dpi images) - Recommended for most cases
|
||||
- High Compression: Maximum file size reduction with some quality loss (300 dpi images)
|
||||
|
||||
How it works:
|
||||
1. Upload your PDF file
|
||||
2. Select your desired compression level
|
||||
3. Click "Compress" and wait for processing
|
||||
4. Download your compressed PDF
|
||||
|
||||
The tool uses WebAssembly to run Ghostscript directly in your browser, which is why the first compression might take a moment to load the necessary components (about 18MB).
|
||||
|
||||
Note: The compression results may vary depending on the content of your PDF. Documents with many images will typically see greater size reduction than text-only documents.
|
||||
|
||||
${longDescription}`
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@@ -18,7 +18,10 @@ export async function compressPdf(
|
||||
throw new Error('The provided file is not a PDF');
|
||||
}
|
||||
|
||||
const dataObject = { psDataURL: URL.createObjectURL(pdfFile) };
|
||||
const dataObject = {
|
||||
psDataURL: URL.createObjectURL(pdfFile),
|
||||
compressionLevel: options.compressionLevel
|
||||
};
|
||||
const compressedFileUrl: string = await compressWithGhostScript(dataObject);
|
||||
return await loadPDFData(compressedFileUrl, pdfFile.name);
|
||||
}
|
||||
|
Reference in New Issue
Block a user