Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable project changes should be documented here.
### Added

- Edit PDF: staged output is checked with `qpdf --check` and reopened for page boxes, per-page content identity, and catalog data before the destination file is replaced. A failed check leaves the original and any existing destination untouched. `qpdf --check` warnings (exit 3) still publish and appear on the completed job update.
- Edit PDF: add, edit, and remove URI (`https` / `http` / `mailto`) and in-document GoTo link annotations. Unsupported actions are left unchanged. The original file is never overwritten.

### Fixed

Expand Down
113 changes: 102 additions & 11 deletions src-tauri/src/commands/pdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
//! removed AFTER the worker joins.

use crate::error::AppError;
use crate::models::{JobRegistry, JobResult, JobUpdate, PageGroup, PagePick, RotateGroup, SplitMode};
use crate::models::{
JobRegistry, JobResult, JobUpdate, PageGroup, PagePick, RotateGroup, SplitMode,
};
use tauri::Emitter;

/// Helper: emit the final "completed" update and build the JobResult.
Expand Down Expand Up @@ -155,7 +157,15 @@ pub async fn watermark_pdf(
let app2 = app.clone();
let jid = job_id.clone();
let res = tauri::async_runtime::spawn_blocking(move || {
crate::pdf_engine::overlay::add_watermark(&app2, &handle, &jid, &groups, &output_path, &text, opacity)
crate::pdf_engine::overlay::add_watermark(
&app2,
&handle,
&jid,
&groups,
&output_path,
&text,
opacity,
)
})
.await
.map_err(|e| AppError::engine_failed(format!("worker join error: {e}")))?;
Expand All @@ -181,7 +191,17 @@ pub async fn crop_pdf(
let app2 = app.clone();
let jid = job_id.clone();
let res = tauri::async_runtime::spawn_blocking(move || {
crate::pdf_engine::crop::crop(&app2, &handle, &jid, &groups, &output_path, left, top, right, bottom)
crate::pdf_engine::crop::crop(
&app2,
&handle,
&jid,
&groups,
&output_path,
left,
top,
right,
bottom,
)
})
.await
.map_err(|e| AppError::engine_failed(format!("worker join error: {e}")))?;
Expand All @@ -198,12 +218,22 @@ pub async fn edit_pdf_overlays(
output_path: String,
groups: Vec<PageGroup>,
document: crate::pdf_engine::edit_overlay::EditDocumentIn,
links_complete: Option<bool>,
) -> Result<JobResult, AppError> {
let handle = registry.register(&job_id);
let app2 = app.clone();
let jid = job_id.clone();
let complete = links_complete.unwrap_or(true);
let res = tauri::async_runtime::spawn_blocking(move || {
crate::pdf_engine::edit_overlay::edit_pdf_overlays(&app2, &handle, &jid, &groups, &output_path, &document)
crate::pdf_engine::edit_overlay::edit_pdf_overlays(
&app2,
&handle,
&jid,
&groups,
&output_path,
&document,
complete,
)
})
.await
.map_err(|e| AppError::engine_failed(format!("worker join error: {e}")))?;
Expand Down Expand Up @@ -243,7 +273,18 @@ pub async fn stamp_pdf(
let app2 = app.clone();
let jid = job_id.clone();
let res = tauri::async_runtime::spawn_blocking(move || {
crate::pdf_engine::stamp::stamp_text(&app2, &handle, &jid, &groups, &output_path, page, &anchor, &text, color, size_pct)
crate::pdf_engine::stamp::stamp_text(
&app2,
&handle,
&jid,
&groups,
&output_path,
page,
&anchor,
&text,
color,
size_pct,
)
})
.await
.map_err(|e| AppError::engine_failed(format!("worker join error: {e}")))?;
Expand All @@ -270,7 +311,18 @@ pub async fn poster_pdf(
let app2 = app.clone();
let jid = job_id.clone();
let res = tauri::async_runtime::spawn_blocking(move || {
crate::pdf_engine::poster::poster(&app2, &handle, &jid, &groups, &output_path, page, tile_w, tile_h, overlap, marks)
crate::pdf_engine::poster::poster(
&app2,
&handle,
&jid,
&groups,
&output_path,
page,
tile_w,
tile_h,
overlap,
marks,
)
})
.await
.map_err(|e| AppError::engine_failed(format!("worker join error: {e}")))?;
Expand All @@ -295,7 +347,16 @@ pub async fn nup_pdf(
let app2 = app.clone();
let jid = job_id.clone();
let res = tauri::async_runtime::spawn_blocking(move || {
crate::pdf_engine::nup::nup(&app2, &handle, &jid, &groups, &output_path, &mode, sheet_w, sheet_h)
crate::pdf_engine::nup::nup(
&app2,
&handle,
&jid,
&groups,
&output_path,
&mode,
sheet_w,
sheet_h,
)
})
.await
.map_err(|e| AppError::engine_failed(format!("worker join error: {e}")))?;
Expand Down Expand Up @@ -333,7 +394,14 @@ pub async fn add_page_numbers(
None
};
crate::pdf_engine::overlay::add_page_numbers_formatted(
&app2, &handle, &jid, &groups, &output_path, &position, start, format,
&app2,
&handle,
&jid,
&groups,
&output_path,
&position,
start,
format,
)
})
.await
Expand All @@ -357,7 +425,15 @@ pub async fn protect_pdf(
let app2 = app.clone();
let jid = job_id.clone();
let res = tauri::async_runtime::spawn_blocking(move || {
crate::pdf_engine::protect(&app2, &handle, &jid, &groups, &user_password, &owner_password, &output_path)
crate::pdf_engine::protect(
&app2,
&handle,
&jid,
&groups,
&user_password,
&owner_password,
&output_path,
)
})
.await
.map_err(|e| AppError::engine_failed(format!("worker join error: {e}")))?;
Expand Down Expand Up @@ -424,7 +500,15 @@ pub async fn rotate_pages(
let app2 = app.clone();
let jid = job_id.clone();
let res = tauri::async_runtime::spawn_blocking(move || {
crate::pdf_engine::rotate(&app2, &handle, &jid, &groups, angle, &rotate_pages, &output_path)
crate::pdf_engine::rotate(
&app2,
&handle,
&jid,
&groups,
angle,
&rotate_pages,
&output_path,
)
})
.await
.map_err(|e| AppError::engine_failed(format!("worker join error: {e}")))?;
Expand Down Expand Up @@ -471,7 +555,14 @@ pub async fn compress_pdf(
let jid = job_id.clone();
let res = tauri::async_runtime::spawn_blocking(move || {
crate::pdf_engine::compress::compress(
&app2, &handle, &jid, &picks, &output_path, dpi, quality, target_bytes,
&app2,
&handle,
&jid,
&picks,
&output_path,
dpi,
quality,
target_bytes,
)
})
.await
Expand Down
14 changes: 14 additions & 0 deletions src-tauri/src/commands/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ pub async fn pdf_outline(input_path: String) -> Result<Vec<crate::models::Outlin
.map_err(|e| AppError::io("Could not read the outline.", e))?
}

/// Supported URI / in-document GoTo `/Link` annots. Paths in, JSON out; never
/// fetches a URI. Files over 400 MiB or with more than 5,000 supported links
/// return an actionable error (not a silent empty or truncated list).
#[tauri::command]
pub async fn list_pdf_links(
input_path: String,
) -> Result<Vec<crate::pdf_engine::edit_links::PdfLinkDto>, AppError> {
tauri::async_runtime::spawn_blocking(move || {
crate::pdf_engine::edit_links::list_pdf_links_cmd(&input_path)
})
.await
.map_err(|e| AppError::io("Could not read the links.", e))?
}

/// Visually compare two pages; returns a diff-overlay image + changed percent.
#[tauri::command]
pub async fn diff_pages(
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn run() {
commands::render::pdf_text,
commands::render::page_pdf,
commands::render::pdf_outline,
commands::render::list_pdf_links,
commands::render::diff_pages,
commands::render::office_available,
commands::render::office_to_pdf,
Expand Down
Loading
Loading