#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc = include_str!("../README.md")]
pub mod health;
mod client;
mod page_range;
mod paper_format;
#[cfg(feature = "stream")]
mod streaming_client;
#[cfg(feature = "blocking")]
mod blocking_client;
#[cfg(feature = "stream")]
#[cfg_attr(docsrs, doc(cfg(feature = "stream")))]
pub use crate::streaming_client::StreamingClient;
#[cfg(feature = "blocking")]
#[cfg_attr(docsrs, doc(cfg(feature = "blocking")))]
pub use crate::blocking_client::BlockingClient;
pub use crate::paper_format::*;
pub use bytes::Bytes;
pub use client::*;
pub use page_range::*;
use reqwest::multipart;
use reqwest::Error as ReqwestError;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fmt::{self, Debug};
use std::str::FromStr;
#[cfg(all(test, not(target_arch = "wasm32")))]
mod tests;
#[cfg(all(test, feature = "stream", not(target_arch = "wasm32")))]
mod streaming_tests;
#[cfg(all(test, feature = "blocking", not(target_arch = "wasm32")))]
mod blocking_tests;
#[cfg(all(test, target_arch = "wasm32"))]
mod wasm_tests;
#[derive(Debug)]
pub enum Error {
FilenameError(String),
CommunicationError(ReqwestError),
RenderingError(String),
ParseError(String, String, String),
}
impl Into<Error> for ReqwestError {
fn into(self) -> Error {
Error::CommunicationError(self)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::FilenameError(e) => write!(f, "gotenberg_pdf: Filename Error: {}", e),
Error::CommunicationError(e) => write!(
f,
"gotenberg_pdf: Error communicating with the guotenberg server: {}",
e
),
Error::RenderingError(e) => {
write!(f, "gotenberg_pdf: PDF / Image Rendering Error: {}", e)
}
Error::ParseError(t, s, e) => {
write!(f, "gotenberg_pdf: Error Parsing {} from `{}`: {}", t, s, e)
}
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::CommunicationError(e) => Some(e),
_ => None,
}
}
}
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WebOptions {
pub trace_id: Option<String>,
pub single_page: Option<bool>,
pub paper_width: Option<LinearDimention>,
pub paper_height: Option<LinearDimention>,
pub margin_top: Option<LinearDimention>,
pub margin_bottom: Option<LinearDimention>,
pub margin_left: Option<LinearDimention>,
pub margin_right: Option<LinearDimention>,
pub prefer_css_page_size: Option<bool>,
pub generate_document_outline: Option<bool>,
pub print_background: Option<bool>,
pub omit_background: Option<bool>,
pub landscape: Option<bool>,
pub scale: Option<f64>,
pub native_page_ranges: Option<PageRange>,
pub header_html: Option<String>,
pub footer_html: Option<String>,
pub wait_delay: Option<std::time::Duration>,
pub wait_for_expression: Option<String>,
pub emulated_media_type: Option<MediaType>,
pub cookies: Option<Vec<Cookie>>,
pub skip_network_idle_events: Option<bool>,
pub user_agent: Option<String>,
pub extra_http_headers: Option<HashMap<String, String>>,
pub pdfa: Option<PDFFormat>,
pub pdfua: Option<bool>,
pub metadata: Option<HashMap<String, serde_json::Value>>,
pub fail_on_http_status_codes: Option<Vec<u32>>,
pub fail_on_resource_http_status_codes: Option<Vec<u32>>,
pub fail_on_resource_loading_failed: Option<bool>,
pub fail_on_console_exceptions: Option<bool>,
}
impl WebOptions {
pub fn set_paper_format(&mut self, format: PaperFormat) {
self.paper_width = Some(format.width());
self.paper_height = Some(format.height());
}
fn fill_form(self, form: reqwest::multipart::Form) -> reqwest::multipart::Form {
let mut form = form;
if let Some(single_page) = self.single_page {
form = form.text("singlePage", single_page.to_string());
}
if let Some(paper_width) = self.paper_width {
form = form.text("paperWidth", format!("{}", paper_width));
}
if let Some(paper_height) = self.paper_height {
form = form.text("paperHeight", format!("{}", paper_height));
}
if let Some(margin_top) = self.margin_top {
form = form.text("marginTop", margin_top.to_string());
}
if let Some(margin_bottom) = self.margin_bottom {
form = form.text("marginBottom", margin_bottom.to_string());
}
if let Some(margin_left) = self.margin_left {
form = form.text("marginLeft", margin_left.to_string());
}
if let Some(margin_right) = self.margin_right {
form = form.text("marginRight", margin_right.to_string());
}
if let Some(prefer_css_page_size) = self.prefer_css_page_size {
form = form.text("preferCssPageSize", prefer_css_page_size.to_string());
}
if let Some(generate_document_outline) = self.generate_document_outline {
form = form.text(
"generateDocumentOutline",
generate_document_outline.to_string(),
);
}
if let Some(print_background) = self.print_background {
form = form.text("printBackground", print_background.to_string());
}
if let Some(omit_background) = self.omit_background {
form = form.text("omitBackground", omit_background.to_string());
}
if let Some(landscape) = self.landscape {
form = form.text("landscape", landscape.to_string());
}
if let Some(scale) = self.scale {
form = form.text("scale", scale.to_string());
}
if let Some(native_page_ranges) = self.native_page_ranges {
form = form.text("nativePageRanges", native_page_ranges.to_string());
}
if let Some(header_html) = self.header_html {
let file_bytes = header_html.into_bytes();
let part = multipart::Part::bytes(file_bytes)
.file_name("header.html")
.mime_str("text/html")
.unwrap();
form = form.part("header.html", part);
}
if let Some(footer_html) = self.footer_html {
let file_bytes = footer_html.into_bytes();
let part = multipart::Part::bytes(file_bytes)
.file_name("footer.html")
.mime_str("text/html")
.unwrap();
form = form.part("footer.html", part);
}
if let Some(wait_delay) = self.wait_delay {
form = form.text("waitDelay", format!("{}ms", wait_delay.as_millis()));
}
if let Some(wait_for_expression) = self.wait_for_expression {
form = form.text("waitForExpression", wait_for_expression);
}
if let Some(emulated_media_type) = self.emulated_media_type {
form = form.text("emulatedMediaType", emulated_media_type.to_string());
}
if let Some(cookies) = self.cookies {
form = form.text("cookies", serde_json::to_string(&cookies).unwrap());
}
if let Some(skip_network_idle_events) = self.skip_network_idle_events {
form = form.text(
"skipNetworkIdleEvents",
skip_network_idle_events.to_string(),
);
}
if let Some(user_agent) = self.user_agent {
form = form.text("userAgent", user_agent);
}
if let Some(extra_http_headers) = self.extra_http_headers {
form = form.text(
"extraHttpHeaders",
serde_json::to_string(&extra_http_headers).unwrap(),
);
}
if let Some(pdfa) = self.pdfa {
form = form.text("pdfa", pdfa.to_string());
}
if let Some(pdfua) = self.pdfua {
form = form.text("pdfua", pdfua.to_string());
}
if let Some(metadata) = self.metadata {
form = form.text("metadata", serde_json::to_string(&metadata).unwrap());
}
if let Some(fail_on_http_status_codes) = self.fail_on_http_status_codes {
form = form.text(
"failOnHttpStatusCodes",
serde_json::to_string(&fail_on_http_status_codes).unwrap(),
);
}
if let Some(fail_on_resource_http_status_codes) = self.fail_on_resource_http_status_codes {
form = form.text(
"failOnResourceHttpStatusCodes",
serde_json::to_string(&fail_on_resource_http_status_codes).unwrap(),
);
}
if let Some(fail_on_resource_loading_failed) = self.fail_on_resource_loading_failed {
form = form.text(
"failOnResourceLoadingFailed",
fail_on_resource_loading_failed.to_string(),
);
}
if let Some(fail_on_console_exceptions) = self.fail_on_console_exceptions {
form = form.text(
"failOnConsoleExceptions",
fail_on_console_exceptions.to_string(),
);
}
form
}
#[cfg(feature = "blocking")]
fn fill_form_blocking(
self,
form: reqwest::blocking::multipart::Form,
) -> reqwest::blocking::multipart::Form {
let mut form = form;
if let Some(single_page) = self.single_page {
form = form.text("singlePage", single_page.to_string());
}
if let Some(paper_width) = self.paper_width {
form = form.text("paperWidth", format!("{}", paper_width));
}
if let Some(paper_height) = self.paper_height {
form = form.text("paperHeight", format!("{}", paper_height));
}
if let Some(margin_top) = self.margin_top {
form = form.text("marginTop", margin_top.to_string());
}
if let Some(margin_bottom) = self.margin_bottom {
form = form.text("marginBottom", margin_bottom.to_string());
}
if let Some(margin_left) = self.margin_left {
form = form.text("marginLeft", margin_left.to_string());
}
if let Some(margin_right) = self.margin_right {
form = form.text("marginRight", margin_right.to_string());
}
if let Some(prefer_css_page_size) = self.prefer_css_page_size {
form = form.text("preferCssPageSize", prefer_css_page_size.to_string());
}
if let Some(generate_document_outline) = self.generate_document_outline {
form = form.text(
"generateDocumentOutline",
generate_document_outline.to_string(),
);
}
if let Some(print_background) = self.print_background {
form = form.text("printBackground", print_background.to_string());
}
if let Some(omit_background) = self.omit_background {
form = form.text("omitBackground", omit_background.to_string());
}
if let Some(landscape) = self.landscape {
form = form.text("landscape", landscape.to_string());
}
if let Some(scale) = self.scale {
form = form.text("scale", scale.to_string());
}
if let Some(native_page_ranges) = self.native_page_ranges {
form = form.text("nativePageRanges", native_page_ranges.to_string());
}
if let Some(header_html) = self.header_html {
let file_bytes = header_html.into_bytes();
let part = reqwest::blocking::multipart::Part::bytes(file_bytes)
.file_name("header.html")
.mime_str("text/html")
.unwrap();
form = form.part("header.html", part);
}
if let Some(footer_html) = self.footer_html {
let file_bytes = footer_html.into_bytes();
let part = reqwest::blocking::multipart::Part::bytes(file_bytes)
.file_name("footer.html")
.mime_str("text/html")
.unwrap();
form = form.part("footer.html", part);
}
if let Some(wait_delay) = self.wait_delay {
form = form.text("waitDelay", format!("{}ms", wait_delay.as_millis()));
}
if let Some(wait_for_expression) = self.wait_for_expression {
form = form.text("waitForExpression", wait_for_expression);
}
if let Some(emulated_media_type) = self.emulated_media_type {
form = form.text("emulatedMediaType", emulated_media_type.to_string());
}
if let Some(cookies) = self.cookies {
form = form.text("cookies", serde_json::to_string(&cookies).unwrap());
}
if let Some(skip_network_idle_events) = self.skip_network_idle_events {
form = form.text(
"skipNetworkIdleEvents",
skip_network_idle_events.to_string(),
);
}
if let Some(user_agent) = self.user_agent {
form = form.text("userAgent", user_agent);
}
if let Some(extra_http_headers) = self.extra_http_headers {
form = form.text(
"extraHttpHeaders",
serde_json::to_string(&extra_http_headers).unwrap(),
);
}
if let Some(pdfa) = self.pdfa {
form = form.text("pdfa", pdfa.to_string());
}
if let Some(pdfua) = self.pdfua {
form = form.text("pdfua", pdfua.to_string());
}
if let Some(metadata) = self.metadata {
form = form.text("metadata", serde_json::to_string(&metadata).unwrap());
}
if let Some(fail_on_http_status_codes) = self.fail_on_http_status_codes {
form = form.text(
"failOnHttpStatusCodes",
serde_json::to_string(&fail_on_http_status_codes).unwrap(),
);
}
if let Some(fail_on_resource_http_status_codes) = self.fail_on_resource_http_status_codes {
form = form.text(
"failOnResourceHttpStatusCodes",
serde_json::to_string(&fail_on_resource_http_status_codes).unwrap(),
);
}
if let Some(fail_on_resource_loading_failed) = self.fail_on_resource_loading_failed {
form = form.text(
"failOnResourceLoadingFailed",
fail_on_resource_loading_failed.to_string(),
);
}
if let Some(fail_on_console_exceptions) = self.fail_on_console_exceptions {
form = form.text(
"failOnConsoleExceptions",
fail_on_console_exceptions.to_string(),
);
}
form
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ScreenshotOptions {
pub trace_id: Option<String>,
pub width: Option<u32>,
pub height: Option<u32>,
pub clip: Option<bool>,
pub format: Option<ImageFormat>,
pub quality: Option<u8>,
pub omit_background: Option<bool>,
pub optimize_for_speed: Option<bool>,
pub wait_delay: Option<std::time::Duration>,
pub wait_for_expression: Option<String>,
pub emulated_media_type: Option<MediaType>,
pub cookies: Option<Vec<Cookie>>,
pub skip_network_idle_events: Option<bool>,
pub user_agent: Option<String>,
pub extra_http_headers: Option<HashMap<String, String>>,
pub fail_on_http_status_codes: Option<Vec<u32>>,
pub fail_on_resource_http_status_codes: Option<Vec<u32>>,
pub fail_on_resource_loading_failed: Option<bool>,
pub fail_on_console_exceptions: Option<bool>,
}
impl ScreenshotOptions {
fn fill_form(self, form: reqwest::multipart::Form) -> reqwest::multipart::Form {
let mut form = form;
if let Some(width) = self.width {
form = form.text("width", width.to_string());
}
if let Some(height) = self.height {
form = form.text("height", height.to_string());
}
if let Some(clip) = self.clip {
form = form.text("clip", clip.to_string());
}
if let Some(format) = self.format {
form = form.text("format", format.to_string());
}
if let Some(quality) = self.quality {
form = form.text("quality", quality.to_string());
}
if let Some(omit_background) = self.omit_background {
form = form.text("omitBackground", omit_background.to_string());
}
if let Some(optimize_for_speed) = self.optimize_for_speed {
form = form.text("optimizeForSpeed", optimize_for_speed.to_string());
}
if let Some(wait_delay) = self.wait_delay {
form = form.text("waitDelay", format!("{}ms", wait_delay.as_millis()));
}
if let Some(wait_for_expression) = self.wait_for_expression {
form = form.text("waitForExpression", wait_for_expression);
}
if let Some(emulated_media_type) = self.emulated_media_type {
form = form.text("emulatedMediaType", emulated_media_type.to_string());
}
if let Some(cookies) = self.cookies {
form = form.text("cookies", serde_json::to_string(&cookies).unwrap());
}
if let Some(skip_network_idle_events) = self.skip_network_idle_events {
form = form.text(
"skipNetworkIdleEvents",
skip_network_idle_events.to_string(),
);
}
if let Some(user_agent) = self.user_agent {
form = form.text("userAgent", user_agent);
}
if let Some(extra_http_headers) = self.extra_http_headers {
form = form.text(
"extraHttpHeaders",
serde_json::to_string(&extra_http_headers).unwrap(),
);
}
if let Some(fail_on_http_status_codes) = self.fail_on_http_status_codes {
form = form.text(
"failOnHttpStatusCodes",
serde_json::to_string(&fail_on_http_status_codes).unwrap(),
);
}
if let Some(fail_on_resource_http_status_codes) = self.fail_on_resource_http_status_codes {
form = form.text(
"failOnResourceHttpStatusCodes",
serde_json::to_string(&fail_on_resource_http_status_codes).unwrap(),
);
}
if let Some(fail_on_resource_loading_failed) = self.fail_on_resource_loading_failed {
form = form.text(
"failOnResourceLoadingFailed",
fail_on_resource_loading_failed.to_string(),
);
}
if let Some(fail_on_console_exceptions) = self.fail_on_console_exceptions {
form = form.text(
"failOnConsoleExceptions",
fail_on_console_exceptions.to_string(),
);
}
form
}
#[cfg(feature = "blocking")]
fn fill_form_blocking(
self,
form: reqwest::blocking::multipart::Form,
) -> reqwest::blocking::multipart::Form {
let mut form = form;
if let Some(width) = self.width {
form = form.text("width", width.to_string());
}
if let Some(height) = self.height {
form = form.text("height", height.to_string());
}
if let Some(clip) = self.clip {
form = form.text("clip", clip.to_string());
}
if let Some(format) = self.format {
form = form.text("format", format.to_string());
}
if let Some(quality) = self.quality {
form = form.text("quality", quality.to_string());
}
if let Some(omit_background) = self.omit_background {
form = form.text("omitBackground", omit_background.to_string());
}
if let Some(optimize_for_speed) = self.optimize_for_speed {
form = form.text("optimizeForSpeed", optimize_for_speed.to_string());
}
if let Some(wait_delay) = self.wait_delay {
form = form.text("waitDelay", format!("{}ms", wait_delay.as_millis()));
}
if let Some(wait_for_expression) = self.wait_for_expression {
form = form.text("waitForExpression", wait_for_expression);
}
if let Some(emulated_media_type) = self.emulated_media_type {
form = form.text("emulatedMediaType", emulated_media_type.to_string());
}
if let Some(cookies) = self.cookies {
form = form.text("cookies", serde_json::to_string(&cookies).unwrap());
}
if let Some(skip_network_idle_events) = self.skip_network_idle_events {
form = form.text(
"skipNetworkIdleEvents",
skip_network_idle_events.to_string(),
);
}
if let Some(user_agent) = self.user_agent {
form = form.text("userAgent", user_agent);
}
if let Some(extra_http_headers) = self.extra_http_headers {
form = form.text(
"extraHttpHeaders",
serde_json::to_string(&extra_http_headers).unwrap(),
);
}
if let Some(fail_on_http_status_codes) = self.fail_on_http_status_codes {
form = form.text(
"failOnHttpStatusCodes",
serde_json::to_string(&fail_on_http_status_codes).unwrap(),
);
}
if let Some(fail_on_resource_http_status_codes) = self.fail_on_resource_http_status_codes {
form = form.text(
"failOnResourceHttpStatusCodes",
serde_json::to_string(&fail_on_resource_http_status_codes).unwrap(),
);
}
if let Some(fail_on_resource_loading_failed) = self.fail_on_resource_loading_failed {
form = form.text(
"failOnResourceLoadingFailed",
fail_on_resource_loading_failed.to_string(),
);
}
if let Some(fail_on_console_exceptions) = self.fail_on_console_exceptions {
form = form.text(
"failOnConsoleExceptions",
fail_on_console_exceptions.to_string(),
);
}
form
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct DocumentOptions {
pub trace_id: Option<String>,
pub password: Option<String>,
pub landscape: Option<bool>,
pub native_page_ranges: Option<PageRange>,
pub export_form_fields: Option<bool>,
pub allow_duplicate_field_names: Option<bool>,
pub export_bookmarks: Option<bool>,
pub export_bookmarks_to_pdf_destination: Option<bool>,
pub export_placeholders: Option<bool>,
pub export_notes: Option<bool>,
pub export_notes_pages: Option<bool>,
pub export_only_notes_pages: Option<bool>,
pub export_notes_in_margin: Option<bool>,
pub convert_ooo_target_to_pdf_target: Option<bool>,
pub export_links_relative_fsys: Option<bool>,
pub export_hidden_slides: Option<bool>,
pub skip_empty_pages: Option<bool>,
pub add_original_document_as_stream: Option<bool>,
pub single_page_sheets: Option<bool>,
pub lossless_image_compression: Option<bool>,
pub quality: Option<u8>,
pub reduce_image_resolution: Option<bool>,
pub max_image_resolution: Option<u32>,
pub pdfa: Option<PDFFormat>,
pub pdfua: Option<bool>,
}
impl DocumentOptions {
fn fill_form(self, form: reqwest::multipart::Form) -> reqwest::multipart::Form {
let mut form = form;
if let Some(password) = self.password {
form = form.text("password", password);
}
if let Some(landscape) = self.landscape {
form = form.text("landscape", landscape.to_string());
}
if let Some(native_page_ranges) = self.native_page_ranges {
form = form.text("nativePageRanges", native_page_ranges.to_string());
}
if let Some(export_form_fields) = self.export_form_fields {
form = form.text("exportFormFields", export_form_fields.to_string());
}
if let Some(allow_duplicate_field_names) = self.allow_duplicate_field_names {
form = form.text(
"allowDuplicateFieldNames",
allow_duplicate_field_names.to_string(),
);
}
if let Some(export_bookmarks) = self.export_bookmarks {
form = form.text("exportBookmarks", export_bookmarks.to_string());
}
if let Some(export_bookmarks_to_pdf_destination) = self.export_bookmarks_to_pdf_destination
{
form = form.text(
"exportBookmarksToPdfDestination",
export_bookmarks_to_pdf_destination.to_string(),
);
}
if let Some(export_placeholders) = self.export_placeholders {
form = form.text("exportPlaceholders", export_placeholders.to_string());
}
if let Some(export_notes) = self.export_notes {
form = form.text("exportNotes", export_notes.to_string());
}
if let Some(export_notes_pages) = self.export_notes_pages {
form = form.text("exportNotesPages", export_notes_pages.to_string());
}
if let Some(export_only_notes_pages) = self.export_only_notes_pages {
form = form.text("exportOnlyNotesPages", export_only_notes_pages.to_string());
}
if let Some(export_notes_in_margin) = self.export_notes_in_margin {
form = form.text("exportNotesInMargin", export_notes_in_margin.to_string());
}
if let Some(convert_ooo_target_to_pdf_target) = self.convert_ooo_target_to_pdf_target {
form = form.text(
"convertOooTargetToPdfTarget",
convert_ooo_target_to_pdf_target.to_string(),
);
}
if let Some(export_links_relative_fsys) = self.export_links_relative_fsys {
form = form.text(
"exportLinksRelativeFsys",
export_links_relative_fsys.to_string(),
);
}
if let Some(export_hidden_slides) = self.export_hidden_slides {
form = form.text("exportHiddenSlides", export_hidden_slides.to_string());
}
if let Some(skip_empty_pages) = self.skip_empty_pages {
form = form.text("skipEmptyPages", skip_empty_pages.to_string());
}
if let Some(add_original_document_as_stream) = self.add_original_document_as_stream {
form = form.text(
"addOriginalDocumentAsStream",
add_original_document_as_stream.to_string(),
);
}
if let Some(single_page_sheets) = self.single_page_sheets {
form = form.text("singlePageSheets", single_page_sheets.to_string());
}
if let Some(lossless_image_compression) = self.lossless_image_compression {
form = form.text(
"losslessImageCompression",
lossless_image_compression.to_string(),
);
}
if let Some(quality) = self.quality {
form = form.text("quality", quality.to_string());
}
if let Some(reduce_image_resolution) = self.reduce_image_resolution {
form = form.text("reduceImageResolution", reduce_image_resolution.to_string());
}
if let Some(max_image_resolution) = self.max_image_resolution {
form = form.text("maxImageResolution", max_image_resolution.to_string());
}
if let Some(pdfa) = self.pdfa {
form = form.text("pdfa", pdfa.to_string());
}
if let Some(pdfua) = self.pdfua {
form = form.text("pdfua", pdfua.to_string());
}
form
}
#[cfg(feature = "blocking")]
fn fill_form_blocking(
self,
form: reqwest::blocking::multipart::Form,
) -> reqwest::blocking::multipart::Form {
let mut form = form;
if let Some(password) = self.password {
form = form.text("password", password);
}
if let Some(landscape) = self.landscape {
form = form.text("landscape", landscape.to_string());
}
if let Some(native_page_ranges) = self.native_page_ranges {
form = form.text("nativePageRanges", native_page_ranges.to_string());
}
if let Some(export_form_fields) = self.export_form_fields {
form = form.text("exportFormFields", export_form_fields.to_string());
}
if let Some(allow_duplicate_field_names) = self.allow_duplicate_field_names {
form = form.text(
"allowDuplicateFieldNames",
allow_duplicate_field_names.to_string(),
);
}
if let Some(export_bookmarks) = self.export_bookmarks {
form = form.text("exportBookmarks", export_bookmarks.to_string());
}
if let Some(export_bookmarks_to_pdf_destination) = self.export_bookmarks_to_pdf_destination
{
form = form.text(
"exportBookmarksToPdfDestination",
export_bookmarks_to_pdf_destination.to_string(),
);
}
if let Some(export_placeholders) = self.export_placeholders {
form = form.text("exportPlaceholders", export_placeholders.to_string());
}
if let Some(export_notes) = self.export_notes {
form = form.text("exportNotes", export_notes.to_string());
}
if let Some(export_notes_pages) = self.export_notes_pages {
form = form.text("exportNotesPages", export_notes_pages.to_string());
}
if let Some(export_only_notes_pages) = self.export_only_notes_pages {
form = form.text("exportOnlyNotesPages", export_only_notes_pages.to_string());
}
if let Some(export_notes_in_margin) = self.export_notes_in_margin {
form = form.text("exportNotesInMargin", export_notes_in_margin.to_string());
}
if let Some(convert_ooo_target_to_pdf_target) = self.convert_ooo_target_to_pdf_target {
form = form.text(
"convertOooTargetToPdfTarget",
convert_ooo_target_to_pdf_target.to_string(),
);
}
if let Some(export_links_relative_fsys) = self.export_links_relative_fsys {
form = form.text(
"exportLinksRelativeFsys",
export_links_relative_fsys.to_string(),
);
}
if let Some(export_hidden_slides) = self.export_hidden_slides {
form = form.text("exportHiddenSlides", export_hidden_slides.to_string());
}
if let Some(skip_empty_pages) = self.skip_empty_pages {
form = form.text("skipEmptyPages", skip_empty_pages.to_string());
}
if let Some(add_original_document_as_stream) = self.add_original_document_as_stream {
form = form.text(
"addOriginalDocumentAsStream",
add_original_document_as_stream.to_string(),
);
}
if let Some(single_page_sheets) = self.single_page_sheets {
form = form.text("singlePageSheets", single_page_sheets.to_string());
}
if let Some(lossless_image_compression) = self.lossless_image_compression {
form = form.text(
"losslessImageCompression",
lossless_image_compression.to_string(),
);
}
if let Some(quality) = self.quality {
form = form.text("quality", quality.to_string());
}
if let Some(reduce_image_resolution) = self.reduce_image_resolution {
form = form.text("reduceImageResolution", reduce_image_resolution.to_string());
}
if let Some(max_image_resolution) = self.max_image_resolution {
form = form.text("maxImageResolution", max_image_resolution.to_string());
}
if let Some(pdfa) = self.pdfa {
form = form.text("pdfa", pdfa.to_string());
}
if let Some(pdfua) = self.pdfua {
form = form.text("pdfua", pdfua.to_string());
}
form
}
}
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct Cookie {
pub name: String,
pub value: String,
pub domain: String,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub secure: Option<bool>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub http_only: Option<bool>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub same_site: Option<SameSite>,
}
impl Cookie {
pub fn new(name: &str, value: &str, domain: &str) -> Self {
Cookie {
name: name.to_string(),
value: value.to_string(),
domain: domain.to_string(),
..Default::default()
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub enum SameSite {
Strict,
Lax,
None,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum PDFFormat {
#[serde(rename = "PDF/A-1b")]
A1b,
#[serde(rename = "PDF/A-2b")]
A2b,
#[serde(rename = "PDF/A-3b")]
A3b,
}
impl PDFFormat {
pub fn to_string(&self) -> String {
match self {
PDFFormat::A1b => "PDF/A-1b".to_string(),
PDFFormat::A2b => "PDF/A-2b".to_string(),
PDFFormat::A3b => "PDF/A-3b".to_string(),
}
}
}
impl fmt::Display for PDFFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.to_string())
}
}
impl FromStr for PDFFormat {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"PDF/A-1b" => Ok(PDFFormat::A1b),
"PDF/A-2b" => Ok(PDFFormat::A2b),
"PDF/A-3b" => Ok(PDFFormat::A3b),
_ => Err(Error::ParseError(
"PDFFormat".to_string(),
s.to_string(),
"Invalid PDF format".to_string(),
)),
}
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum ImageFormat {
#[serde(rename = "png")]
Png,
#[serde(rename = "jpeg")]
Jpeg,
#[serde(rename = "webp")]
Webp,
}
impl ImageFormat {
pub fn to_string(&self) -> String {
match self {
ImageFormat::Png => "png".to_string(),
ImageFormat::Jpeg => "jpeg".to_string(),
ImageFormat::Webp => "webp".to_string(),
}
}
}
impl fmt::Display for ImageFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.to_string())
}
}
impl FromStr for ImageFormat {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"png" => Ok(ImageFormat::Png),
"jpeg" => Ok(ImageFormat::Jpeg),
"webp" => Ok(ImageFormat::Webp),
_ => Err(Error::ParseError(
"ImageFormat".to_string(),
s.to_string(),
"Invalid image format".to_string(),
)),
}
}
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum MediaType {
#[serde(rename = "screen")]
Screen,
#[serde(rename = "print")]
Print,
}
impl MediaType {
pub fn to_string(&self) -> String {
match self {
MediaType::Screen => "screen".to_string(),
MediaType::Print => "print".to_string(),
}
}
}
impl fmt::Display for MediaType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.to_string())
}
}
impl FromStr for MediaType {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"screen" => Ok(MediaType::Screen),
"print" => Ok(MediaType::Print),
_ => Err(Error::ParseError(
"MediaType".to_string(),
s.to_string(),
"Invalid media type".to_string(),
)),
}
}
}