Skip to content

Optimization: PDF Compression & Size Reduction on Export#12

Open
Votienduong2208 wants to merge 2 commits into
YurMil:mainfrom
Votienduong2208:feat/pdf-compression-issue-10
Open

Optimization: PDF Compression & Size Reduction on Export#12
Votienduong2208 wants to merge 2 commits into
YurMil:mainfrom
Votienduong2208:feat/pdf-compression-issue-10

Conversation

@Votienduong2208

Copy link
Copy Markdown

Summary

Adds PDF compression and size reduction option on export with two profiles:

  • Lossless (default): Preserves full quality, no compression
  • Low size: Uses PDF object streams and compression to reduce file size

Changes

  • Add type (lossless | low-size) to domain/types
  • Add exportProfile to UiState and setExportProfile action to pdfStore
  • Pass exportProfile through export worker request chain
  • Implement PDF compression in PdfLibWriter with saveWithProfile method
    • 'low-size' profile uses useObjectStreams, objectsPerStream for smaller output
  • Add export profile selector (Lossless vs Low Size) to ExportDialog UI
  • Wire up profile selection in App.tsx handleExport

Closes #10

- Add ExportProfile type (lossless | low-size) to domain/types
- Add exportProfile to UiState and setExportProfile action to pdfStore
- Pass exportProfile through export worker request (protocols.ts, exportPdf.ts, export.worker.ts)
- Implement PDF compression in PdfLibWriter with saveWithProfile method
  - 'low-size' profile uses useObjectStreams, objectsPerStream for smaller output
- Add export profile selector (Lossless vs Low Size) to ExportDialog UI
- Wire up profile selection in App.tsx handleExport

Closes YurMil#10

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an "Export profile" feature, allowing users to choose between "Lossless" (best quality) and "Low size" (compressed) options when exporting PDFs. This involves updating the PdfLibWriter adapter, the UI components (ExportDialog, App), the state store, and the background export worker to pass and handle the selected ExportProfile. Feedback highlights a critical issue in App.tsx where a second call to runExport inside handleOpenViewer was missed during the signature update, which will lead to a runtime crash. Additionally, a style improvement was suggested in protocols.ts to move the inline import of ExportProfile to the top of the file.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

snapshot.setJob('export', { status: 'running', progress: 5, message: 'Preparing export...' });
try {
const files = await runExport(snapshot, mode, snapshot.ui.exportFileName, (progress, message) => {
const files = await runExport(snapshot, mode, snapshot.ui.exportFileName, snapshot.ui.exportProfile, (progress, message) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

While this call to runExport has been correctly updated to include snapshot.ui.exportProfile, the other call to runExport inside handleOpenViewer (around line 408) was missed. It still passes only 4 arguments:

const files = await runExport(snapshot, { kind: 'workspace' }, snapshot.ui.exportFileName || 'pdf-master-viewer', (progress, message) => { ... })

Because the signature of runExport was changed to require exportProfile as the 4th argument, passing the progress callback as the 4th argument will cause onProgress to be undefined inside runExport. This will result in a runtime crash (TypeError: onProgress is not a function) when the worker sends progress updates.

Please update the call in handleOpenViewer to pass the export profile (e.g., snapshot.ui.exportProfile or 'lossless').

name: string;
}

import type { ExportProfile } from '@/domain/types';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The import of ExportProfile is placed in the middle of the file. According to standard TypeScript style guides (such as ESLint's import/first rule), all import statements should be at the top of the file. Please remove this inline import and add ExportProfile to the existing group import from @/domain/types at the top of the file (line 1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimization: PDF Compression & Size Reduction on Export

1 participant