{"record":{"id":"016ce29d089a269a","repo":"flxzt/rnote","slug":"creating-pdf-instance-failed-err-err-016ce2","errorCode":null,"errorMessage":"Creating Pdf instance failed, Err: {err:?}","messagePattern":"Creating Pdf instance failed, Err: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/rnote-ui/src/dialogs/import.rs","lineNumber":411,"sourceCode":"    ));\n\n    pdf_import_adjust_document_row.connect_active_notify(clone!(\n        #[weak]\n        appwindow,\n        move |row| {\n            appwindow\n                .engine_config()\n                .write()\n                .import_prefs\n                .pdf_import_prefs\n                .adjust_document = row.is_active();\n        }\n    ));\n\n    let pdf_data = Arc::new(input_file.load_bytes_future().await?.0.to_vec());\n    let pdf = if let Some(password) = password.as_ref() {\n        hayro_syntax::Pdf::new_with_password(pdf_data, password)\n            .map_err(|err| anyhow!(\"Creating Pdf instance failed, Err: {err:?}\"))?\n    } else {\n        hayro_syntax::Pdf::new(pdf_data)\n            .map_err(|err| anyhow!(\"Creating Pdf instance failed, Err: {err:?}\"))?\n    };\n    let pdf_metadata = pdf.metadata();\n\n    let file_name = input_file.basename().map_or_else(\n        || gettext(\"- no file name -\"),\n        |s| s.to_string_lossy().to_string(),\n    );\n    let title = pdf_metadata\n        .title\n        .to_owned()\n        .and_then(|s| String::from_utf8(s).ok())\n        .unwrap_or_else(|| gettext(\"- no title -\"));\n    let author = pdf_metadata\n        .author\n        .to_owned()","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-ui/src/dialogs/import.rs#L393-L429","documentation":"Thrown when `hayro_syntax::Pdf::new_with_password` fails to construct a Pdf instance from the loaded bytes with the provided password. This means the bytes are not a parsable PDF or the password is wrong, so the import is aborted with a debug-formatted error from the hayro parser.","triggerScenarios":"Calling `dialog_import_pdf_w_prefs` with a password-protected PDF where the supplied password is incorrect, or with a corrupted/non-PDF file that hayro's parser rejects during `new_with_password`.","commonSituations":"User typed a wrong password into the PDF password prompt; file truncated during download/transfer; the 'PDF' is actually a renamed image or HTML file; PDF encrypted with an algorithm hayro does not support.","solutions":["Re-enter the correct PDF password (verify with the document owner).","Check `file` is a valid PDF: `file.query_info(\"standard::content-type\")` should be `application/pdf` before import.","Open the PDF in another viewer to confirm the file is not corrupted; re-obtain or repair the file.","Try opening without a password if the PDF may not be encrypted; use `Pdf::new` and inspect the encryption error."],"exampleFix":"// before\nlet pdf = hayro_syntax::Pdf::new_with_password(pdf_data, password)\n    .map_err(|err| anyhow!(\"Creating Pdf instance failed, Err: {err:?}\"))?;\n// after\nlet pdf = match hayro_syntax::Pdf::new_with_password(pdf_data, password) {\n    Ok(pdf) => pdf,\n    Err(err) => {\n        appwindow.overlays().dispatch_toast_error(&gettext(\"Wrong password or unreadable PDF\"));\n        return Err(anyhow!(\"PDF open with password failed: {err:?}\"));\n    }\n};","handlingStrategy":"try-catch","validationCode":"let ctype = input_file.query_info(\"standard::content-type\", gio::FileQueryInfoFlags::NONE, gio::Cancellable::NONE)?\n    .content_type();\nif ctype != Some(\"application/pdf\".into()) { bail!(\"not a PDF file\"); }","typeGuard":null,"tryCatchPattern":"match hayro_syntax::Pdf::new_with_password(data, pwd) {\n    Ok(pdf) => proceed(pdf),\n    Err(err) => show_toast(\"Wrong password or unreadable PDF\"),\n}","preventionTips":["Prompt clearly for the PDF password and allow retry on failure","Verify content-type is application/pdf before import","Keep the hayro dependency updated for newer encryption schemes"],"tags":["pdf","import","password","parsing"],"backgroundTag":"invalid-argument-value","analyzedSha":"bbc5354502ba2fc83eec2670b535348825e679a6","analyzedAt":"2026-09-08T13:20:33.747Z","contentChangedAt":"2026-09-08T13:20:33.747Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}