You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to add a bookmark in Unicode (Russian and Polish text in my case) but i only get some silly signs, not the letters i would like to have. Is there a way to use Unicode Bookmarks?
use printpdf::*;
use std::fs::File;
use std::io::{BufWriter, Seek};
fn main() {
test_unicode_bookmark();
}
fn test_unicode_bookmark() {
// Create a new PDF document
let (doc, page1, layer1) = PdfDocument::new("PDF with Bookmarks", Mm(210.0), Mm(297.0), "Layer 1");
// Create a new layer
let layer = doc.get_page(page1).get_layer(layer1);
// Add some text to the first page
let font = doc.add_external_font(File::open("src/assets/fonts/RobotoMedium.ttf").unwrap()).unwrap();
let hello = String::from("Здравствуйте");
layer.use_text(&hello, 48.0, Mm(10.0), Mm(280.0), &font);
// Add a bookmark with Unicode text
let bookmark_title = "Unicode Bookmark: Здравствуйте"; // Example Unicode text
doc.add_bookmark(bookmark_title, page1);
// Save the document
doc.save(&mut BufWriter::new(File::create("output.pdf").unwrap())).unwrap();
}
The text was updated successfully, but these errors were encountered:
Literal encoding means Windows-ANSI, it should be switched to Hexadecimal like this:
let bytes = text
.chars().flat_map(|x| {let[b0, b1] = x.to_be_bytes();
std::iter::once(b0).chain(std::iter::once(b1))}).collect::<Vec<u8>>();("Title",String(bytes,Hexadecimal)),
I am trying to add a bookmark in Unicode (Russian and Polish text in my case) but i only get some silly signs, not the letters i would like to have. Is there a way to use Unicode Bookmarks?
The text was updated successfully, but these errors were encountered: