igumnoff / shiva

Shiva library: Implementation in Rust of a parser and generator for documents of any type
https://docs.rs/shiva
Apache License 2.0
167 stars 10 forks source link

Created PDF has content, but is displayed empty with all tested PDF viewers. #120

Open Michaelschnabel-DM opened 6 days ago

Michaelschnabel-DM commented 6 days ago

Hi I am using shiva e.g. to convert a Markdown File to a PDF file. The content of the PDF itself seems to be present, but when opened with any pdf viewer like adobe acrobat it displays only blank pages. I can even reproduce it with a very simple txt file.


fn prepare_license_pdf_binary(license_file_bytes: Vec<u8>) {
    let md_content = String::from_utf8(license_file_bytes).unwrap();
    let input_bytes = Bytes::from(md_content);
    let document = shiva::markdown::Transformer::parse(&input_bytes).unwrap();
    let output_bytes = shiva::pdf::Transformer::generate(&document)
        .unwrap()
        .to_vec();

    let mut file = File::create("payload/EULA.pdf").unwrap();
    file.write_all(output_bytes.as_slice()).unwrap();
}

I attached the simple text input file and below the resulting PDF. Test.txt

Test.pdf

Is this a known bug or am i doing something wrong?

evgenyigumnov commented 6 days ago

works for me


    #[test]
    fn simple_test() {
        let content = std::fs::read("test/data/test.txt").unwrap();
        let md_content = String::from_utf8(content).unwrap();
        let input_bytes = Bytes::from(md_content);
        let document = markdown::Transformer::parse(&input_bytes).unwrap();
        let output_bytes = pdf::Transformer::generate(&document)
            .unwrap()
            .to_vec();

        std::fs::write(
            "test/data/test.pdf",
            output_bytes,
        ).unwrap();
    }
}

https://github.com/igumnoff/shiva/raw/HEAD/lib/test/data/test.txt

https://github.com/igumnoff/shiva/raw/HEAD/lib/test/data/test.pdf

how to reproduce?

Michaelschnabel-DM commented 6 days ago

Initially the small example test above didnt work either. Then i noticed that the fonts folder was completely empty. After deleting it and running the test it properly filled the fonts folder with all the fonts and also the PDF was fine again. Not sure if I broke anything on my side that caused the fonts to not be downloaded anymore, but now it works again thanks!