{"record":{"id":"7143b1b4ec31dd10","repo":"flxzt/rnote","slug":"creating-pdf-instance-failed-err-err-7143b1","errorCode":null,"errorMessage":"Creating Pdf instance failed, Err: {err:?}","messagePattern":"Creating Pdf instance failed, Err: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rnote-engine/src/strokes/vectorimage.rs","lineNumber":220,"sourceCode":"            svg_data,\n            intrinsic_size,\n            rectangle,\n        })\n    }\n\n    pub fn from_pdf_bytes(\n        to_be_read: &[u8],\n        pdf_import_prefs: PdfImportPrefs,\n        insert_pos: Vector2,\n        page_range: Option<Range<usize>>,\n        format: &Format,\n        password: Option<String>,\n    ) -> Result<Vec<Self>, anyhow::Error> {\n        // TODO: how to avoid this allocation without lifetime issues?\n        let data = Arc::new(to_be_read.to_vec());\n        let pdf = if let Some(password) = password {\n            hayro_syntax::Pdf::new_with_password(data, &password)\n                .map_err(|err| anyhow!(\"Creating Pdf instance failed, Err: {err:?}\"))?\n        } else {\n            hayro_syntax::Pdf::new(data)\n                .map_err(|err| anyhow!(\"Creating Pdf instance failed, Err: {err:?}\"))?\n        };\n        let interpreter_settings = hayro_interpret::InterpreterSettings::default();\n        let render_settings = hayro_svg::SvgRenderSettings {\n            bg_color: [255, 255, 255, 255],\n        };\n        let pages = pdf.pages();\n        let page_range = page_range.unwrap_or(0..pages.len());\n        let page_width = if pdf_import_prefs.adjust_document {\n            format.width()\n        } else {\n            format.width() * (pdf_import_prefs.page_width_perc / 100.0)\n        };\n\n        // calculate the page zoom based on the width of the first page.\n        let page_zoom = if let Some(first_page) = pages.first() {","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/flxzt/rnote/blob/bbc5354502ba2fc83eec2670b535348825e679a6/crates/rnote-engine/src/strokes/vectorimage.rs#L202-L238","documentation":"from_pdf_bytes wraps hayro_syntax::Pdf::new_with_password; when a password is supplied but does not decrypt the document (or is wrong for any encrypted/invalid PDF), hayro returns an error which is wrapped in this message. It means the PDF could not be opened with the given password.","triggerScenarios":"Calling VectorImage::from_pdf_bytes with Some(password) on an encrypted PDF whose password is wrong, or on a file whose encryption scheme hayro does not support.","commonSituations":"Users importing password-protected PDFs (restricted documents) with a mistyped password; PDFs with legacy/unsupported encryption handlers.","solutions":["Prompt the user again and retry with the correct password","Detect encrypted PDFs up front and require a password before calling from_pdf_bytes","Inspect the wrapped {err:?} detail to distinguish wrong-password from unsupported-encryption","If the PDF is merely owner-locked (viewable without password), try passing None"],"exampleFix":"// before\nlet imgs = VectorImage::from_pdf_bytes(bytes, 0..n, zoom, Some(user_input))?;\n// after\nif !user_input.is_empty() {\n    match VectorImage::from_pdf_bytes(bytes, 0..n, zoom, Some(user_input)) {\n        Ok(imgs) => imgs,\n        Err(e) => return Err(anyhow!(\"wrong PDF password, try again: {e}\")),\n    }\n}","handlingStrategy":"retry","validationCode":"// detect encryption before import; hayro exposes this via parse errors\nlet is_encrypted = std::str::from_utf8(&data[..data.len().min(2048)])\n    .map(|s| s.contains(\"/Encrypt\"))\n    .unwrap_or(false);\nif is_encrypted && password.is_none() { prompt_user_for_password()?; }","typeGuard":null,"tryCatchPattern":"loop {\n    match VectorImage::from_pdf_bytes(bytes, pages, zoom, password.as_deref()) {\n        Ok(v) => break v,\n        Err(e) if e.to_string().contains(\"Creating Pdf instance failed\") => {\n            password = prompt_retry_password();\n            if password.is_none() { return Err(e); }\n        }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Detect encrypted PDFs and prompt for a password before import","Validate the password by attempting a cheap parse first","Retry with an empty/None password for owner-locked documents","Surface a clear 'wrong password' UI message distinct from 'corrupt file'"],"tags":["pdf","encryption","password","import"],"backgroundTag":"authentication-required","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"}