flxzt/rnote · error
Creating Pdf instance failed, Err
Error message
Creating Pdf instance failed, Err: {err:?} What it means
from_pdf_bytes could not construct a hayro_syntax::Pdf from the supplied bytes when a password was given: Pdf::new_with_password rejected the data, meaning the bytes are not a valid PDF or the password is wrong/unsupported. The library throws this before any page rendering can start.
Solutions
- Re-enter the correct password and retry the import.
- Verify the file is a complete, valid PDF (open it in another viewer); re-download or re-export it if corrupted.
- Try importing without a password if the document is not actually encrypted.
- Check the wrapped hayro error `{err:?}` for whether it is a parse error vs. a decryption failure.
Example fix
// before
let pdf = hayro_syntax::Pdf::new_with_password(data, &password).map_err(|err| anyhow!("Creating Pdf instance failed, Err: {err:?}"))?;
// after
let pdf = hayro_syntax::Pdf::new_with_password(data, &password)
.map_err(|err| anyhow!("Creating Pdf instance failed (wrong password or corrupt file?), Err: {err:?}"))
.context("check the password and that the PDF is not corrupted")?; Defensive patterns
Strategy: validation
Validate before calling
// Rust: verify the file starts with the PDF magic and is complete before import
fn looks_like_pdf(bytes: &[u8]) -> bool {
bytes.starts_with(b"%PDF-") && bytes.windows(5).any(|w| w == b"%%EOF")
} Type guard
fn is_nonempty_pdf_input(bytes: &[u8]) -> bool {
!bytes.is_empty() && bytes.starts_with(b"%PDF-")
} Try / catch
match BitmapImage::from_pdf_bytes(&bytes, &prefs, &format, Some(password), range) {
Ok(pages) => ...,
Err(e) => prompt_user("Import failed: check the password and that the PDF is not corrupted."),
} Prevention
- Prompt users for the password up front for encrypted PDFs instead of guessing.
- Check the %PDF- magic and %%EOF trailer before passing bytes to the importer.
- Avoid truncating large PDFs during file reads or transfers.
When it happens
Trigger: Calling the public `from_pdf_bytes` with `Some(password)` where the byte buffer is not a parseable PDF, is corrupted/truncated, or the provided password fails to decrypt the document.
Common situations: Importing an encrypted PDF into rnote with an incorrect password; importing a partially downloaded or otherwise corrupted PDF file; passing non-PDF bytes.
Related errors
- Creating Pdf instance failed, Err
- Layout from_string failed, invalid name
- no page at index
- Creating Pdf instance failed, Err
- on-conflict behaviour is still Ask after prompting the user.
AI-assisted analysis of flxzt/rnote@bbc5354502 (2026-09-08).
Data as JSON: /api/errors/609298bfa9bf96e9.
Report an issue: GitHub.
Appendix: source
Thrown at crates/rnote-engine/src/strokes/bitmapimage.rs:141
affine: transform,
};
Ok(Self { image, 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 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() {
page_width / first_page.render_dimensions().0 as f64
} else {
return Ok(vec![]);View on GitHub (pinned to bbc5354502)