Skip to main content

pdfkit/
action_url.rs

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