pub struct PdfString(pub Vec<u8>);Expand description
PDF String object - Text data in PDF files.
PDF strings can contain arbitrary binary data and use various encodings.
They can be written as literal strings (text) or hexadecimal strings <48656C6C6F>.
§Encoding
String encoding depends on context:
- Text strings: Usually PDFDocEncoding or UTF-16BE
- Font strings: Encoding specified by the font
- Binary data: No encoding, raw bytes
§Example
use oxidize_pdf::parser::objects::PdfString;
// Create from UTF-8
let string = PdfString::new(b"Hello World".to_vec());
// Try to decode as UTF-8
if let Ok(text) = string.as_str() {
println!("Text: {}", text);
}Tuple Fields§
§0: Vec<u8>Implementations§
Source§impl PdfString
impl PdfString
Sourcepub fn as_str(&self) -> Result<&str, Utf8Error>
pub fn as_str(&self) -> Result<&str, Utf8Error>
Get as UTF-8 string if possible.
Attempts to decode the string bytes as UTF-8. Note that PDF strings may use other encodings.
§Returns
Ok(&str) if valid UTF-8, Err otherwise.
§Example
use oxidize_pdf::parser::objects::PdfString;
let string = PdfString::new(b"Hello".to_vec());
assert_eq!(string.as_str(), Ok("Hello"));
let binary = PdfString::new(vec![0xFF, 0xFE]);
assert!(binary.as_str().is_err());Trait Implementations§
impl StructuralPartialEq for PdfString
Auto Trait Implementations§
impl Freeze for PdfString
impl RefUnwindSafe for PdfString
impl Send for PdfString
impl Sync for PdfString
impl Unpin for PdfString
impl UnwindSafe for PdfString
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more