Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect extracted text from annotation #77

Closed
reyjexter opened this issue Mar 17, 2023 · 4 comments
Closed

Incorrect extracted text from annotation #77

reyjexter opened this issue Mar 17, 2023 · 4 comments
Assignees

Comments

@reyjexter
Copy link

reyjexter commented Mar 17, 2023

Hi again! We have an example PDF document which when using for_annotation to get the text, it returns weird characters. However when showing logs of page objects text, this doesn't happen.

Here's the PDF affected:

https://github.com/reyjexter/pdfium-render-wasm/blob/master/www/dynamic-template.pdf

And the example:

https://github.com/reyjexter/pdfium-render-wasm

Here's how the console log on Chrome looks like:

image

Thanks and appreciate any help with this issue.

@ajrcarey ajrcarey self-assigned this Mar 17, 2023
@ajrcarey
Copy link
Owner

ajrcarey commented Mar 17, 2023

Hi @reyjexter , thank you for reporting the issue.

I can reproduce the problem, but only when compiling to WASM; when running the following reproduction snippet from the console, the annotation text is returned correctly. This suggests the problem is in the WASM implementation of FPDFText_GetBoundedText. Checking now.

let pdfium = Pdfium::new(Pdfium::bind_to_library(
    Pdfium::pdfium_platform_library_name_at_path("./"),
)?);

let document = pdfium.load_pdf_from_file("./dynamic-template.pdf", None)?;

for page in document.pages().iter() {
    let text = page.text()?;

    for annotation in page.annotations().iter() {
        println!(
            "Text: {:?}, bounds: {:?}",
            text.for_annotation(&annotation),
            annotation.bounds()?
        );
    }
}

ajrcarey pushed a commit that referenced this issue Mar 17, 2023
@ajrcarey
Copy link
Owner

ajrcarey commented Mar 17, 2023

Yes, the WASM implementation of FPDFText_GetBoundedText was the problem; the return value of FPDFText_GetBoundedText is the number of characters (in UTF16-LE format) copied into a byte buffer, not the number of bytes. (This is rare difference from the usual Pdfium pattern, which is to return the number of bytes.) This difference was not accounted for in the WASM implementation of this function. I have pushed a fix for the problem and it will be included in crate release 0.8.0.

There will be a delay before the release of 0.8.0, so in the meantime you may want to set pdfium-render as a git dependency in your project.

@reyjexter
Copy link
Author

I can confirm that the change on master works correctly on document I sent. Thanks again and we shouldn't have any issue using pdfium-render as a git repository.

@ajrcarey
Copy link
Owner

Good to hear, closing as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants