use crate::defs::{Margins, PaperSize, ScreenshotFormat, Timeout, WindowSize};
use headless_chrome::protocol::cdp::Page::CaptureScreenshotFormatOption;
use headless_chrome::types::PrintToPdfOptions;
#[derive(Clone)]
pub struct PdfPrintingOptions {
pub landscape: bool,
pub print_header_footer: bool,
pub print_background: bool,
pub scale: Option<f64>,
pub paper_size: PaperSize,
pub margins: Margins,
pub page_ranges: Option<String>,
pub header: Option<String>,
pub footer: Option<String>,
pub verbose: bool,
pub no_crash_reports: bool,
pub page_load_timeout: Timeout,
}
impl From<PdfPrintingOptions> for PrintToPdfOptions {
fn from(value: PdfPrintingOptions) -> Self {
Self {
landscape: Some(value.landscape),
display_header_footer: Some(value.print_header_footer),
print_background: Some(value.print_background),
scale: value.scale,
paper_width: value.paper_size.0,
paper_height: value.paper_size.1,
margin_top: value.margins.0,
margin_bottom: value.margins.2,
margin_left: value.margins.3,
margin_right: value.margins.1,
page_ranges: value.page_ranges,
ignore_invalid_page_ranges: None,
header_template: value.header,
footer_template: value.footer,
prefer_css_page_size: None,
transfer_mode: None,
generate_document_outline: None,
generate_tagged_pdf: None,
}
}
}
#[derive(Clone)]
pub struct ScreenshotTakingOptions {
pub screenshot_format: Option<ScreenshotFormat>,
pub window_size: WindowSize,
pub verbose: bool,
pub no_crash_reports: bool,
pub page_load_timeout: Option<u64>,
}
impl From<ScreenshotFormat> for CaptureScreenshotFormatOption {
fn from(screenshot_format: ScreenshotFormat) -> Self {
match screenshot_format {
ScreenshotFormat::Jpeg => CaptureScreenshotFormatOption::Jpeg,
ScreenshotFormat::Png => CaptureScreenshotFormatOption::Png,
ScreenshotFormat::Webp => CaptureScreenshotFormatOption::Webp,
}
}
}