flxzt/rnote · error

Creating Pdf instance failed, Err

Error message

Creating Pdf instance failed, Err: {err:?}

What it means

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.

Solutions

  1. Prompt the user again and retry with the correct password
  2. Detect encrypted PDFs up front and require a password before calling from_pdf_bytes
  3. Inspect the wrapped {err:?} detail to distinguish wrong-password from unsupported-encryption
  4. If the PDF is merely owner-locked (viewable without password), try passing None

Example fix

// before
let imgs = VectorImage::from_pdf_bytes(bytes, 0..n, zoom, Some(user_input))?;
// after
if !user_input.is_empty() {
    match VectorImage::from_pdf_bytes(bytes, 0..n, zoom, Some(user_input)) {
        Ok(imgs) => imgs,
        Err(e) => return Err(anyhow!("wrong PDF password, try again: {e}")),
    }
}
Defensive patterns

Strategy: retry

Validate before calling

// detect encryption before import; hayro exposes this via parse errors
let is_encrypted = std::str::from_utf8(&data[..data.len().min(2048)])
    .map(|s| s.contains("/Encrypt"))
    .unwrap_or(false);
if is_encrypted && password.is_none() { prompt_user_for_password()?; }

Try / catch

loop {
    match VectorImage::from_pdf_bytes(bytes, pages, zoom, password.as_deref()) {
        Ok(v) => break v,
        Err(e) if e.to_string().contains("Creating Pdf instance failed") => {
            password = prompt_retry_password();
            if password.is_none() { return Err(e); }
        }
        Err(e) => return Err(e),
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: Users importing password-protected PDFs (restricted documents) with a mistyped password; PDFs with legacy/unsupported encryption handlers.

Related errors


AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08). Data as JSON: /api/errors/7143b1b4ec31dd10. Report an issue: GitHub.

Appendix: source

Thrown at crates/rnote-engine/src/strokes/vectorimage.rs:220

            svg_data,
            intrinsic_size,
            rectangle,
        })
    }

    pub fn from_pdf_bytes(
        to_be_read: &[u8],
        pdf_import_prefs: PdfImportPrefs,
        insert_pos: Vector2,
        page_range: Option<Range<usize>>,
        format: &Format,
        password: Option<String>,
    ) -> Result<Vec<Self>, anyhow::Error> {
        // TODO: how to avoid this allocation without lifetime issues?
        let data = Arc::new(to_be_read.to_vec());
        let pdf = if let Some(password) = password {
            hayro_syntax::Pdf::new_with_password(data, &password)
                .map_err(|err| anyhow!("Creating Pdf instance failed, Err: {err:?}"))?
        } else {
            hayro_syntax::Pdf::new(data)
                .map_err(|err| anyhow!("Creating Pdf instance failed, Err: {err:?}"))?
        };
        let interpreter_settings = hayro_interpret::InterpreterSettings::default();
        let render_settings = hayro_svg::SvgRenderSettings {
            bg_color: [255, 255, 255, 255],
        };
        let pages = pdf.pages();
        let page_range = page_range.unwrap_or(0..pages.len());
        let page_width = if pdf_import_prefs.adjust_document {
            format.width()
        } else {
            format.width() * (pdf_import_prefs.page_width_perc / 100.0)
        };

        // calculate the page zoom based on the width of the first page.
        let page_zoom = if let Some(first_page) = pages.first() {

View on GitHub (pinned to bbc5354502)