Skip to main content

pdfkit/
action_url.rs

1use std::ptr;
2
3use crate::error::Result;
4use crate::ffi;
5use crate::handle::ObjectHandle;
6use crate::util::{c_string, take_string};
7
8#[derive(Debug, Clone)]
9pub struct PdfActionUrl {
10    handle: ObjectHandle,
11}
12
13impl PdfActionUrl {
14    pub(crate) fn from_handle(handle: ObjectHandle) -> Self {
15        Self { handle }
16    }
17
18    pub fn new(url: &str) -> Result<Self> {
19        let url = c_string(url)?;
20        let mut out_action = ptr::null_mut();
21        let mut out_error = ptr::null_mut();
22        let status = unsafe { ffi::pdf_action_url_new(url.as_ptr(), &mut out_action, &mut out_error) };
23        crate::util::status_result(status, out_error)?;
24        Ok(Self::from_handle(crate::util::required_handle(
25            out_action,
26            "PDFActionURL",
27        )?))
28    }
29
30    #[must_use]
31    pub fn url(&self) -> Option<String> {
32        take_string(unsafe { ffi::pdf_action_url_string(self.handle.as_ptr()) })
33    }
34
35    pub fn set_url(&self, url: &str) -> Result<()> {
36        let url = c_string(url)?;
37        let mut out_error = ptr::null_mut();
38        let status = unsafe { ffi::pdf_action_url_set_url(self.handle.as_ptr(), url.as_ptr(), &mut out_error) };
39        crate::util::status_result(status, out_error)
40    }
41
42    #[must_use]
43    pub fn action_type(&self) -> Option<String> {
44        take_string(unsafe { ffi::pdf_action_url_type_string(self.handle.as_ptr()) })
45    }
46
47    pub(crate) fn as_handle_ptr(&self) -> *mut core::ffi::c_void {
48        self.handle.as_ptr()
49    }
50}