Skip to main content

Tools

Struct Tools 

Source
pub struct Tools { /* private fields */ }
Expand description

Access to the document tools. Get it with Wellfriend::tools.

Each tool has a typed method (generated from the tool catalog) that uploads the input, starts the operation, waits for it and returns a ToolResult:

use wellfriend::{CompressPdfParams, CompressPdfProfile};

let params = CompressPdfParams { profile: Some(CompressPdfProfile::AggressiveLossless), ..Default::default() };
let result = wf.tools().compress_pdf("scan.pdf", Some(params)).await?;
result.save("scan.small.pdf").await?;

Implementations§

Source§

impl Tools

Source

pub fn with_options(self, options: RequestOptions) -> Self

The same handle with these options for every call made through it.

Source

pub async fn run( &self, tool: impl Into<ToolId>, input: impl Into<ToolInput>, params: Option<ToolParameters>, ) -> Result<ToolResult>

Runs any tool by id and waits for the result.

use wellfriend::{ToolId, ToolParameters};

let params = ToolParameters::new().set("profile", "medium");
wf.tools().run(ToolId::CompressPdf, "in.pdf", Some(params)).await?.save("out.pdf").await?;
Source

pub async fn start( &self, tool: impl Into<ToolId>, input: impl Into<ToolInput>, params: Option<ToolParameters>, ) -> Result<Operation>

Starts a tool and returns the operation without waiting for it. Resume later with DocumentOperations::wait.

Source

pub fn request(&self, tool: impl Into<ToolId>) -> ToolRequest

A request builder, for tools that read named asset files.

Source§

impl Tools

Source

pub async fn add_page_numbers( &self, input: impl Into<FileInput>, params: Option<AddPageNumbersParams>, ) -> Result<ToolResult>

Add Page Numbers: Insert numbered headers or footers.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn add_watermark( &self, input: impl Into<FileInput>, params: Option<AddWatermarkParams>, ) -> Result<ToolResult>

Add Watermark: Stamp text or image onto pages.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn edit_metadata( &self, input: impl Into<FileInput>, params: Option<EditMetadataParams>, ) -> Result<ToolResult>

Check & Edit Metadata: Review and update document information.

Accepts .pdf. Returns PDF document (application/pdf), or a ZIP of PDFs in batch mode (application/zip).

Source

pub async fn check_pdf( &self, input: impl Into<FileInput>, params: Option<CheckPdfParams>, ) -> Result<ToolResult>

Check PDF: One report on PDF/A conformance, PDF/UA accessibility and digital signatures.

Accepts .pdf. Returns JSON report (application/json): PDF/A conformance, PDF/UA accessibility and digital signatures, each with a pass, warn or fail summary and its details.

Source

pub async fn compress_pdf( &self, input: impl Into<FileInput>, params: Option<CompressPdfParams>, ) -> Result<ToolResult>

Compress: Make PDFs and images smaller without changing how they look.

Accepts .avif, .bmp, .gif, .jpeg, .jpg, .pdf, .png, .tif, .tiff, .webp. Returns The PDF, compressed (application/pdf); an image comes back in its own format (JPEG, PNG, WebP, GIF, TIFF, BMP or AVIF) at the same pixel size, never larger than the input.

Source

pub async fn crop_pdf( &self, input: impl Into<FileInput>, params: Option<CropPdfParams>, ) -> Result<ToolResult>

Crop PDF: Trim the margins of every page or the pages you pick.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn flatten_pdf( &self, input: impl Into<FileInput>, params: Option<FlattenPdfParams>, ) -> Result<ToolResult>

Flatten PDF: Merge form fields into static pages.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn merge_pdf( &self, input: impl IntoIterator<Item = impl Into<FileInput>>, params: Option<MergePdfParams>, ) -> Result<ToolResult>

Merge PDF: Combine multiple PDFs into one file.

Accepts .pdf (2 to 30 files, in order). Returns PDF document (application/pdf).

Source

pub async fn n_up_pdf( &self, input: impl Into<FileInput>, params: Option<NUpPdfParams>, ) -> Result<ToolResult>

N-up PDF: Put several pages on each sheet.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn ocr_pdf( &self, input: impl Into<FileInput>, params: Option<OcrPdfParams>, ) -> Result<ToolResult>

OCR PDF: Recognise the text of a scanned PDF or an image (PNG, JPEG, TIFF or WebP).

Accepts .avif, .bmp, .csv, .docx, .eml, .gif, .jpeg, .jpg, .msg, .pdf, .png, .pptx, .tif, .tiff, .tsv, .webp, .xlsx, .zip. Returns Searchable PDF (application/pdf), or the recognised text as plain text, Markdown, JSON, DOCX, HTML, XLSX, CSV, hOCR, ALTO XML, block JSON or annotation JSON, as chosen by outputMode; further formats (outputs) are listed in the result metadata.

Source

pub async fn organize_pdf( &self, input: impl Into<FileInput>, params: OrganizePdfParams, ) -> Result<ToolResult>

Organize PDF: Reorder pages and remove the ones you leave out.

Accepts .pdf. Returns PDF document (application/pdf). Required: order.

Source

pub async fn pdf_table_extraction( &self, input: impl Into<FileInput>, params: Option<PdfTableExtractionParams>, ) -> Result<ToolResult>

PDF Table Extraction: Extract table-like content from PDF text.

Accepts .pdf. Returns ZIP of CSV files, one per detected table (application/zip).

Source

pub async fn protect_pdf( &self, input: impl Into<FileInput>, params: ProtectPdfParams, ) -> Result<ToolResult>

Protect PDF: Lock a file with a password.

Accepts .pdf. Returns PDF document (application/pdf). Required: password.

Source

pub async fn redact_pdf( &self, input: impl Into<FileInput>, params: Option<RedactPdfParams>, ) -> Result<ToolResult>

Redact PDF: Permanently remove text, images and areas you choose.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn repair_pdf( &self, input: impl Into<FileInput>, params: Option<RepairPdfParams>, ) -> Result<ToolResult>

Repair PDF: Fix corrupted or broken PDF files.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn rotate_pdf( &self, input: impl Into<FileInput>, params: Option<RotatePdfParams>, ) -> Result<ToolResult>

Rotate PDF: Rotate all or specific pages.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn sanitize_pdf( &self, input: impl Into<FileInput>, params: Option<SanitizePdfParams>, ) -> Result<ToolResult>

Sanitize PDF.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn scale_pdf( &self, input: impl Into<FileInput>, params: Option<ScalePdfParams>, ) -> Result<ToolResult>

Scale PDF: Resize pages and their content by a percentage.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn sign_pdf( &self, input: impl Into<FileInput>, params: Option<SignPdfParams>, ) -> Result<ToolResult>

Sign PDF: Add a visible signature to a PDF.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn split_pdf( &self, input: impl Into<FileInput>, params: Option<SplitPdfParams>, ) -> Result<ToolResult>

Split PDF: Separate pages into individual files.

Accepts .pdf. Returns One PDF (application/pdf), or a ZIP of PDFs when the split produces several parts (application/zip).

Source

pub async fn unlock_pdf( &self, input: impl Into<FileInput>, params: Option<UnlockPdfParams>, ) -> Result<ToolResult>

Unlock PDF: Remove password from a file you own.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn csv_to_pdf( &self, input: impl Into<FileInput>, params: Option<CsvToPdfParams>, ) -> Result<ToolResult>

CSV to PDF: Convert CSV tables into a readable PDF.

Accepts .csv, .txt. Returns PDF document (application/pdf).

Source

pub async fn excel_to_pdf( &self, input: impl Into<FileInput>, params: Option<ExcelToPdfParams>, ) -> Result<ToolResult>

Excel to PDF: Convert spreadsheet files to PDF.

Accepts .ods, .xlsx. Returns PDF document (application/pdf).

Source

pub async fn image_to_pdf( &self, input: impl IntoIterator<Item = impl Into<FileInput>>, params: Option<ImageToPdfParams>, ) -> Result<ToolResult>

Image to PDF: Combine supported image files into a single PDF.

Accepts .jpeg, .jpg, .png, .webp (1 to 50 files, in order). Returns PDF document (application/pdf).

Source

pub async fn json_to_pdf( &self, input: impl Into<FileInput>, params: Option<JsonToPdfParams>, ) -> Result<ToolResult>

JSON to PDF: Render structured JSON into a readable PDF.

Accepts .json, .txt. Returns PDF document (application/pdf).

Source

pub async fn markdown_to_pdf( &self, input: impl Into<FileInput>, params: Option<MarkdownToPdfParams>, ) -> Result<ToolResult>

Markdown to PDF: Convert Markdown content into a PDF document.

Accepts .markdown, .md, .txt. Returns PDF document (application/pdf).

Source

pub async fn pdf_to_chunks( &self, input: impl Into<FileInput>, params: Option<PdfToChunksParams>, ) -> Result<ToolResult>

PDF to Chunks: Split the text of a PDF into chunks for search and AI retrieval.

Accepts .pdf. Returns JSON chunks (application/json): text chunks with their page ranges, for retrieval.

Source

pub async fn pdf_to_epub( &self, input: impl Into<FileInput>, params: Option<PdfToEpubParams>, ) -> Result<ToolResult>

PDF to EPUB: Create a text-based EPUB from PDF content.

Accepts .pdf. Returns EPUB e-book (application/epub+zip).

Source

pub async fn pdf_to_excel( &self, input: impl Into<FileInput>, params: Option<PdfToExcelParams>, ) -> Result<ToolResult>

PDF to Excel: Export detected PDF tables into XLSX.

Accepts .pdf. Returns XLSX spreadsheet (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet).

Source

pub async fn pdf_to_html( &self, input: impl Into<FileInput>, params: Option<PdfToHtmlParams>, ) -> Result<ToolResult>

PDF to HTML: Convert the text of a PDF into a clean web page.

Accepts .pdf. Returns HTML document (text/html), one section per page, no scripts.

Source

pub async fn pdf_to_images( &self, input: impl Into<FileInput>, params: Option<PdfToImagesParams>, ) -> Result<ToolResult>

PDF to Images: Export pages or embedded images from a PDF.

Accepts .pdf. Returns ZIP of JPG images, one per page or extracted image (application/zip).

Source

pub async fn pdf_to_json( &self, input: impl Into<FileInput>, params: Option<PdfToJsonParams>, ) -> Result<ToolResult>

PDF to JSON: Export PDF text as structured JSON.

Accepts .pdf. Returns Structured JSON (application/json).

Source

pub async fn pdf_to_markdown( &self, input: impl Into<FileInput>, params: Option<PdfToMarkdownParams>, ) -> Result<ToolResult>

PDF to Markdown: Convert extracted PDF text into Markdown.

Accepts .pdf. Returns Markdown (text/markdown).

Source

pub async fn pdf_to_powerpoint( &self, input: impl Into<FileInput>, params: Option<PdfToPowerpointParams>, ) -> Result<ToolResult>

PDF to PowerPoint: Turn every page into a slide of a PowerPoint deck.

Accepts .pdf. Returns PowerPoint deck (application/vnd.openxmlformats-officedocument.presentationml.presentation), one slide per page with its text as the picture description.

Source

pub async fn pdf_to_text( &self, input: impl Into<FileInput>, params: Option<PdfToTextParams>, ) -> Result<ToolResult>

PDF to Text: Extract selectable or OCR text from a PDF.

Accepts .pdf. Returns Plain text (text/plain).

Source

pub async fn pdf_to_word( &self, input: impl Into<FileInput>, params: Option<PdfToWordParams>, ) -> Result<ToolResult>

PDF to Word: Convert extracted PDF text into editable DOCX.

Accepts .pdf. Returns DOCX document (application/vnd.openxmlformats-officedocument.wordprocessingml.document).

Source

pub async fn pdfa_conversion( &self, input: impl Into<FileInput>, params: Option<PdfaConversionParams>, ) -> Result<ToolResult>

PDF/A Conversion: Convert a PDF to PDF/A for long-term archiving.

Accepts .pdf. Returns PDF document (application/pdf).

Source

pub async fn powerpoint_to_pdf( &self, input: impl Into<FileInput>, params: Option<PowerpointToPdfParams>, ) -> Result<ToolResult>

PowerPoint to PDF: Convert presentation files to PDF.

Accepts .odp, .pptx. Returns PDF document (application/pdf).

Source

pub async fn svg_to_pdf( &self, input: impl Into<FileInput>, params: Option<SvgToPdfParams>, ) -> Result<ToolResult>

SVG to PDF: Convert safe SVG artwork into PDF format.

Accepts .svg. Returns PDF document (application/pdf).

Source

pub async fn text_to_pdf( &self, input: impl Into<FileInput>, params: Option<TextToPdfParams>, ) -> Result<ToolResult>

Text to PDF: Convert plain text into a PDF document.

Accepts .txt. Returns PDF document (application/pdf).

Source

pub async fn web_capture( &self, input: impl Into<FileInput>, params: Option<WebCaptureParams>, ) -> Result<ToolResult>

Web page to PDF or image: Capture a web address or pasted HTML as a PDF or a PNG, JPEG or WebP image.

Accepts .htm, .html, .txt, .url. Returns PDF document (application/pdf), or a PNG, JPEG or WebP image, as chosen by output.

Source

pub async fn word_to_pdf( &self, input: impl Into<FileInput>, params: Option<WordToPdfParams>, ) -> Result<ToolResult>

Word to PDF: Convert document files to PDF.

Accepts .docx, .odt. Returns PDF document (application/pdf).

Source

pub async fn convert_from_jpg( &self, input: impl Into<FileInput>, params: Option<ConvertFromJpgParams>, ) -> Result<ToolResult>

Convert from JPG: Export JPG files to another image format.

Accepts .jpeg, .jpg. Returns Image in targetFormat: PNG, WebP, AVIF, or TIFF.

Source

pub async fn convert_to_jpg( &self, input: impl Into<FileInput>, params: Option<ConvertToJpgParams>, ) -> Result<ToolResult>

Convert to JPG: Convert supported images to JPG.

Accepts .avif, .jpeg, .jpg, .png, .tiff, .webp. Returns JPG image (image/jpeg).

Source

pub async fn crop_image( &self, input: impl Into<FileInput>, params: CropImageParams, ) -> Result<ToolResult>

Crop Image: Crop an image to exact dimensions.

Accepts .avif, .jpeg, .jpg, .png, .tiff, .webp. Returns Processed image (same family as input). Required: x, y, width, height.

Source

pub async fn image_metadata( &self, input: impl Into<FileInput>, params: Option<ImageMetadataParams>, ) -> Result<ToolResult>

Image Metadata: Read an image’s format, size, colour mode, frames and EXIF facts.

Accepts .gif, .jpeg, .jpg, .png, .webp. Returns JSON metadata report: format, width, height, colour mode, frames and EXIF summary (application/json).

Source

pub async fn resize_image( &self, input: impl Into<FileInput>, params: Option<ResizeImageParams>, ) -> Result<ToolResult>

Resize Image: Change image dimensions precisely.

Accepts .avif, .jpeg, .jpg, .png, .tiff, .webp. Returns Processed image (same family as input).

Source

pub async fn rotate_image( &self, input: impl Into<FileInput>, params: Option<RotateImageParams>, ) -> Result<ToolResult>

Rotate Image: Correct image orientation.

Accepts .avif, .jpeg, .jpg, .png, .tiff, .webp. Returns Processed image (same family as input).

Source

pub async fn watermark_image( &self, input: impl Into<FileInput>, params: Option<WatermarkImageParams>, ) -> Result<ToolResult>

Watermark Image: Apply text or logo marks to an image.

Accepts .avif, .jpeg, .jpg, .png, .tiff, .webp. Returns Processed image (same family as input).

Trait Implementations§

Source§

impl Clone for Tools

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tools

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Tools

§

impl !UnwindSafe for Tools

§

impl Forget for Tools

§

impl Freeze for Tools

§

impl Move for Tools

§

impl Send for Tools

§

impl Sync for Tools

§

impl Unpin for Tools

§

impl UnsafeUnpin for Tools

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more