Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.87 KB | None | 0 0
  1. // example.rs
  2.  
  3. fn main() {
  4.     let doc = pdfdoc::PDFDoc::new("examples/data/LargeTest_0000001.pdf").unwrap();
  5.     doc.merge_xfdf_and_redact("examples/data/LargeTest_0000001.xfdf");
  6.     println!("merged");
  7. }
  8.  
  9. // pdfdoc.rs
  10. pub struct PDFDoc {
  11.     doc: ffi::TRN_PDFDoc,
  12. }
  13.  
  14. impl PDFDoc {
  15.     ...
  16.     pub fn merge_xfdf_and_redact(self, xfdf: &str) -> Self {
  17.         let mut fdf: ffi::TRN_FDFDoc = std::ptr::null_mut();
  18.         let xfdf = Ustring::new(xfdf);
  19.  
  20.         unsafe {
  21.             ffi::TRN_FDFDocCreateFromXFDF(xfdf.to_ustring(), &mut fdf);
  22.             ffi::TRN_PDFDocFDFMerge(self.doc, fdf);
  23.         }
  24.  
  25.         self
  26.     }
  27. }
  28.  
  29. impl Drop for PDFDoc {
  30.     fn drop(&mut self) {
  31.         println!("dropped");
  32.         if self.doc != std::ptr::null_mut() {
  33.             unsafe {
  34.                 ffi::TRN_PDFDocDestroy(self.doc);
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement