### FPDF_RenderPageBitmap_Start Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/trait.PdfiumLibraryBindings.html?search= Starts rendering a page to a bitmap. ```APIDOC ## FPDF_RenderPageBitmap_Start ### Description Starts rendering a page to a bitmap. ### Method `unsafe fn FPDF_RenderPageBitmap_Start(&self, bitmap: FPDF_BITMAP, page: FPDF_PAGE, start_x: c_int, start_y: c_int, size_x: c_int, size_y: c_int, rotate: c_int, flags: c_int, pause: *mut IFSDK_PAUSE) -> c_int` ### Parameters - `bitmap` (FPDF_BITMAP) - The bitmap to render to. - `page` (FPDF_PAGE) - The page handle. - `start_x` (c_int) - The starting X coordinate for rendering. - `start_y` (c_int) - The starting Y coordinate for rendering. - `size_x` (c_int) - The width of the rendering area. - `size_y` (c_int) - The height of the rendering area. - `rotate` (c_int) - The rotation of the page. - `flags` (c_int) - Flags for rendering. - `pause` (*mut IFSDK_PAUSE) - Pointer to the pause handler. ``` -------------------------------- ### Initialize and Load PDF Document (C++) Source: https://docs.rs/pdfium-render/latest/pdfium_render/index.html Illustrates the basic steps to initialize the Pdfium library, load a document, and clean up resources in C++. ```cpp string test_doc = "test.pdf"; FPDF_InitLibrary(); FPDF_DOCUMENT doc = FPDF_LoadDocument(test_doc, NULL); // ... do something with doc FPDF_CloseDocument(doc); FPDF_DestroyLibrary(); ``` -------------------------------- ### FPDFAnnot_GetLine Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindgen/pdfium_7763.rs.html?search= Gets the starting and ending coordinates of a line annotation. This is an experimental API. ```APIDOC ## FPDFAnnot_GetLine ### Description Experimental API to get the starting and ending coordinates of a line annotation. ### Parameters * `annot` (FPDF_ANNOTATION) - Handle to the annotation. * `start` (*mut FS_POINTF) - Starting point. * `end` (*mut FS_POINTF) - Ending point. ### Returns `FPDF_BOOL` - True if the annotation is of type line and `start` and `end` are not NULL, false otherwise. ``` -------------------------------- ### Get Search Result Index - PDFium Bindings Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindings.rs.html Retrieves the starting character index of the most recent search result. ```rust unsafe fn FPDFText_GetSchResultIndex(&self, handle: FPDF_SCHHANDLE) -> c_int; ``` -------------------------------- ### Initialize PDFium Library with Configuration Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindings/dynamic_bindings.rs.html Initializes the PDFium library using a provided configuration. This is a core step before using other PDFium functions. ```rust extern_FPDF_InitLibraryWithConfig: *(Self::bind( &library, "FPDF_InitLibraryWithConfig", )?), ``` -------------------------------- ### Initialize PDFium with Bindings and Config Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdfium.rs.html Creates a new `Pdfium` instance with custom library configuration. It initializes the PDFium library using `FPDF_InitLibraryWithConfig` and asserts that bindings have not been previously set. This function should be called only once. ```rust pub fn new_with_config( bindings: Box, config: PdfiumLibraryConfig, ) -> Self { assert!(BINDINGS.get().is_none()); unsafe { bindings.FPDF_InitLibraryWithConfig(&config.as_pdfium()); } assert!(BINDINGS.set(bindings).is_ok()); Self { custom_font_provider: None, #[cfg(not(target_arch = "wasm32"))] platform_default_font_provider: None, } } ``` -------------------------------- ### Get Root Bookmark Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/struct.PdfBookmarks.html Retrieves the root PdfBookmark from the containing PdfDocument, if one exists. This is the starting point for traversing the bookmark tree. ```rust pub fn root(&self) -> Option> ``` -------------------------------- ### Initialize PDFium with Bindings Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdfium.rs.html Creates a new `Pdfium` instance using provided library bindings. It initializes the PDFium library and asserts that bindings have not been previously set. This function should be called only once. ```rust pub fn new(bindings: Box) -> Self { assert!(BINDINGS.get().is_none()); unsafe { bindings.FPDF_InitLibrary(); } assert!(BINDINGS.set(bindings).is_ok()); Self { custom_font_provider: None, #[cfg(not(target_arch = "wasm32"))] platform_default_font_provider: None, } } ``` -------------------------------- ### Get Inclusive Glyph Range Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/glyphs/struct.PdfFontGlyphs.html Provides an inclusive Range, starting from 0 and ending at the index of the last glyph (total glyphs - 1). ```rust pub fn as_range_inclusive(&self) -> RangeInclusive ``` -------------------------------- ### FPDFAvail_GetFirstPageNum Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/trait.PdfiumLibraryBindings.html?search= Gets the page number of the first available page in a linearized PDF document. This is useful for optimizing rendering by starting with the first accessible page. ```APIDOC ## unsafe fn FPDFAvail_GetFirstPageNum ### Description Gets the page number for the first available page in a linearized PDF. `doc` - document handle. Returns the zero-based index for the first available page. For most linearized PDFs, the first available page will be the first page, however, some PDFs might make another page the first available page. For non-linearized PDFs, this function will always return zero. ``` -------------------------------- ### Initialize PdfiumLibraryConfig Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/config.rs.html Creates a new `PdfiumLibraryConfig` with default values. This is the starting point for customizing Pdfium initialization. ```rust pub fn new() -> Self { PdfiumLibraryConfig { user_font_paths: Box::pin(vec![]), #[cfg(not(target_arch = "wasm32"))] v8_isolate_ptr: null_mut(), #[cfg(not(target_arch = "wasm32"))] v8_embedder_slot_idx: 0, #[cfg(not(target_arch = "wasm32"))] v8_platform_ptr: null_mut(), renderer_type: FPDF_RENDERER_TYPE_FPDF_RENDERERTYPE_SKIA, #[cfg(any(feature = "pdfium_future", feature = "pdfium_7763",))] font_library_type: FPDF_FONT_BACKEND_TYPE_FPDF_FONTBACKENDTYPE_FREETYPE, } } ``` -------------------------------- ### Get Dash Phase Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/page/object.rs.html Retrieves the dash phase for a PDF page object's line. The dash phase determines the starting point of a dash pattern. ```rust #[inline] fn dash_phase(&self) -> Result { let mut phase = 0.0; if self.bindings().is_true(unsafe { self.bindings() .FPDFPageObj_GetDashPhase(self.object_handle(), &mut phase) }) { Ok(PdfPoints::new(phase)) } else { Err(PdfiumError::PdfiumFunctionReturnValueIndicatedFailure) } } ``` -------------------------------- ### Pdfium Initialization Methods Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/struct.Pdfium.html Methods for binding to the Pdfium library, either statically linked, from system libraries, or from a specified file path. ```APIDOC ## pub fn bind_to_statically_linked_library() Binds to a Pdfium library that was statically linked into the currently running executable, returning a new PdfiumLibraryBindings object that contains bindings to the functions exposed by the library. The application will immediately crash if Pdfium was not correctly statically linked into the executable at compile time. This function is only available when this crate’s `static` feature is enabled. ### Returns - `Result, PdfiumError>`: A `PdfiumLibraryBindings` object on success, or a `PdfiumError` on failure. ``` ```APIDOC ## pub fn bind_to_system_library() Initializes the external Pdfium library, loading it from the system libraries. Returns a new PdfiumLibraryBindings object that contains bindings to the functions exposed by the library, or an error if the library could not be loaded. ### Returns - `Result, PdfiumError>`: A `PdfiumLibraryBindings` object on success, or a `PdfiumError` on failure. ``` ```APIDOC ## pub fn bind_to_library( path: impl AsRef ) Initializes the external pdfium library, loading it from the given path. Returns a new PdfiumLibraryBindings object that contains bindings to the functions exposed by the library, or an error if the library could not be loaded. ### Parameters - `path`: An object that can be converted into a `Path`, specifying the location of the Pdfium library. ### Returns - `Result, PdfiumError>`: A `PdfiumLibraryBindings` object on success, or a `PdfiumError` on failure. ``` -------------------------------- ### Get Default System Font Info Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindings/dynamic_bindings.rs.html Retrieves the default system font information used by PDFium. This can be used as a starting point for setting custom system font information. ```APIDOC ## extern_FPDF_GetDefaultSystemFontInfo ### Description Gets the default system font information. ### Signature ```rust extern_FPDF_GetDefaultSystemFontInfo: unsafe extern "C" fn() -> *mut FPDF_SYSFONTINFO ``` ### Returns Returns a pointer to the default `FPDF_SYSFONTINFO` structure. ``` -------------------------------- ### Initialize PdfiumCustomFontProviderExt Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/font/provider.rs.html Creates a new `PdfiumCustomFontProviderExt` instance, setting up the necessary callbacks for PDFium's system font information interface. The `EnumFonts` callback is intentionally left `None` for version 2. ```rust impl PdfiumCustomFontProviderExt { pub(crate) fn new(provider: Box) -> Self { PdfiumCustomFontProviderExt { version: 2, EnumFonts: None, // not used in interface version 2 Release: Some(fpdf_sys_font_info_release), MapFont: Some(fpdf_sys_font_info_map_font), GetFont: None, GetFontData: Some(fpdf_sys_font_info_get_font_data), GetFaceName: Some(fpdf_sys_font_info_get_face_name), GetFontCharset: Some(fpdf_sys_font_info_get_font_charset), DeleteFont: Some(fpdf_sys_font_info_delete_font), provider, cache: HashMap::new(), } } /// Returns an `FPDF_SYSFONTINFO` pointer suitable for passing to `FPDF_SetSystemFontInfo()`. #[inline] pub(crate) fn as_fpdf_sys_font_info_mut_ptr(&mut self) -> &mut FPDF_SYSFONTINFO { unsafe { &mut *(self as *mut PdfiumCustomFontProviderExt as *mut FPDF_SYSFONTINFO) } } } ``` -------------------------------- ### Create and Populate Cache for Second Document Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/page/index_cache.rs.html Demonstrates creating a new PDF document, adding pages, and then verifying that the page index cache is populated as page references are retrieved. This highlights the dynamic nature of the cache. ```rust let mut document_1 = pdfium.create_new_pdf()?; { // Create four blank pages. for _ in 1..=4 { document_1 .pages_mut() .create_page_at_end(PdfPagePaperSize::a4())?; } // Since we haven't retrieved any references to these pages, the index cache // should only contain the references to the pages from the first document. assert_eq!(PdfPageIndexCache::lock().pages_by_index.len(), 3); // Check that the cache gets populated as we retrieve references to pages. let document_1_page_0 = document_1.pages().get(0)?; assert_eq!(PdfPageIndexCache::lock().pages_by_index.len(), 4); let document_1_page_1 = document_1.pages().get(1)?; assert_eq!(PdfPageIndexCache::lock().pages_by_index.len(), 5); let document_1_page_2 = document_1.pages().get(2)?; assert_eq!(PdfPageIndexCache::lock().pages_by_index.len(), 6); let document_1_page_3 = document_1.pages().get(3)?; assert_eq!(PdfPageIndexCache::lock().pages_by_index.len(), 7); // Check the cached indices are correct. assert!(PdfPageIndexCache::lock() .get(document_1.handle(), document_1_page_0.page_handle()) .is_some()); assert_eq!( PdfPageIndexCache::lock() .get(document_1.handle(), document_1_page_0.page_handle()) .unwrap() .index, 0 ); assert!(PdfPageIndexCache::lock() .get(document_1.handle(), document_1_page_1.page_handle()) .is_some()); assert_eq!( PdfPageIndexCache::lock() .get(document_1.handle(), document_1_page_1.page_handle()) .unwrap() .index, 1 ); assert!(PdfPageIndexCache::lock() .get(document_1.handle(), document_1_page_2.page_handle()) .is_some()); assert_eq!( PdfPageIndexCache::lock() .get(document_1.handle(), document_1_page_2.page_handle()) .unwrap() .index, 2 ); assert!(PdfPageIndexCache::lock() .get(document_1.handle(), document_1_page_3.page_handle()) .is_some()); assert_eq!( PdfPageIndexCache::lock() .get(document_1.handle(), document_1_page_3.page_handle()) .unwrap() .index, 3 ); assert!(PdfPageIndexCache::lock() .documents_by_maximum_index .get(&document_1.handle()) .is_some()); assert_eq!( PdfPageIndexCache::lock() .documents_by_maximum_index .get(&document_1.handle()) .copied() .unwrap(), 3 ); } ``` -------------------------------- ### Get Page Objects as an Inclusive Range Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/trait.PdfPageObjectsCommon.html Returns a standard Rust inclusive range representing the indices of all page objects. Useful for operations that require both the start and end indices. ```rust fn as_range_inclusive(&self) -> RangeInclusive { ... } ``` -------------------------------- ### copy_pages_from_document Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/pages.rs.html Copies one or more pages, specified using a user-friendly page range string, from the given source `PdfDocument`, inserting the pages sequentially starting at the given destination page index in this `PdfPages` collection. The page range string should be in a comma-separated list of indexes and ranges, for example "1,3,5-7". Pages are indexed starting at one, not zero. ```APIDOC ## copy_pages_from_document ### Description Copies one or more pages, specified using a user-friendly page range string, from the given source `PdfDocument`, inserting the pages sequentially starting at the given destination page index in this `PdfPages` collection. The page range string should be in a comma-separated list of indexes and ranges, for example "1,3,5-7". Pages are indexed starting at one, not zero. ### Method `copy_pages_from_document(&mut self, source: &PdfDocument, pages: &str, destination_page_index: PdfPageIndex) -> Result<(), PdfiumError>` ### Parameters - **source**: `&PdfDocument` - The source PDF document from which to copy pages. - **pages**: `&str` - A string representing the page range to copy (e.g., "1,3,5-7"). Pages are 1-indexed. - **destination_page_index**: `PdfPageIndex` - The index at which to insert the copied pages in the destination document (0-based). ``` -------------------------------- ### From> for PdfAction<'a> Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/launch/struct.PdfActionLaunch.html Converts a PdfActionLaunch<'a> into a PdfAction<'a>. ```rust fn from(action: PdfActionLaunch<'a>) -> Self ``` -------------------------------- ### Get Text Characters within a PDF Rectangular Region Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/page/text.rs.html Retrieves all characters that fall within a specified rectangular area on a PDF page. Handles cases where characters are found at the start, end, or not at all within the rectangle. ```rust pub fn chars_inside_rect<'b>( &'b self, rect: PdfRect, ) -> Result, PdfiumError> { let tolerance_x = rect.width() / 2.0; let tolerance_y = rect.height() / 2.0; let center_height = rect.bottom() + tolerance_y; match ( Self::get_char_index_near_point( self.text_page_handle(), rect.left(), tolerance_x, center_height, tolerance_y, self.bindings(), ), Self::get_char_index_near_point( self.text_page_handle(), rect.right(), tolerance_x, center_height, tolerance_y, self.bindings(), ), ) { (Some(start), Some(end)) => Ok(PdfPageTextChars::new( self.page.document_handle(), self.page.page_handle(), self.text_page_handle(), (start as i32..=end as i32 + 1).collect(), )), (Some(start), None) => Ok(PdfPageTextChars::new( self.page.document_handle(), self.page.page_handle(), self.text_page_handle(), (start as i32..=start as i32 + 1).collect(), )), (None, Some(end)) => Ok(PdfPageTextChars::new( self.page.document_handle(), self.page.page_handle(), self.text_page_handle(), (end as i32..=end as i32 + 1).collect(), )), _ => Err(PdfiumError::NoCharsInRect), } } ``` -------------------------------- ### Initialize and Load PDF Document (Rust FFI) Source: https://docs.rs/pdfium-render/latest/pdfium_render/index.html Shows the equivalent Rust code using pdfium-render's low-level FFI bindings to perform the same operations as the C++ example. ```rust let pdfium = Pdfium::default(); let bindings = pdfium.bindings(); let test_doc = "test.pdf"; unsafe { bindings.FPDF_InitLibrary(); let doc = bindings.FPDF_LoadDocument(test_doc, None); // ... do something with doc bindings.FPDF_CloseDocument(doc); bindings.FPDF_DestroyLibrary(); } ``` -------------------------------- ### Installed Font Management Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/trait.PdfiumLibraryBindings.html Functions for adding and managing installed fonts. ```APIDOC ## FPDF_AddInstalledFont ### Description Adds an installed font to the system's font list. ### Method `FPDF_AddInstalledFont` ### Parameters - `mapper` (*mut c_void) - Pointer to the font mapper. - `face` (&str) - The font face name. - `charset` (c_int) - The character set of the font. ``` -------------------------------- ### Initialize PDFium Library Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindings/dynamic_bindings.rs.html Initializes the PDFium library with default settings. This is a simpler alternative to FPDF_InitLibraryWithConfig. ```rust unsafe fn FPDF_InitLibrary(&self) { (self.extern_FPDF_InitLibrary)(); } ``` -------------------------------- ### Render Page Bitmap Start Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindings/dynamic_bindings.rs.html Initiates the rendering of a PDF page to a bitmap. Requires a valid bitmap, page handle, coordinates, dimensions, rotation, flags, and a pause callback. ```rust #[inline] #[allow(non_snake_case)] unsafe fn FPDF_RenderPageBitmap_Start( &self, bitmap: *mut FPDF_BITMAP, page: FPDF_PAGE, start_x: c_int, start_y: c_int, size_x: c_int, size_y: c_int, rotate: c_int, flags: c_int, pause: *mut IFSDK_PAUSE, ) -> c_int { (self.extern_FPDF_RenderPageBitmap_Start)( bitmap, page, start_x, start_y, size_x, size_y, rotate, flags, pause, ) } ``` -------------------------------- ### FPDFImageObj_GetImagePixelSize Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/trait.PdfiumLibraryBindings.html?search= Gets the image size in pixels. This is a faster method to get only image size. ```APIDOC ## unsafe fn FPDFImageObj_GetImagePixelSize ### Description Gets the image size in pixels. This is a faster method to get only image size. ### Parameters - `image_object` (FPDF_PAGEOBJECT) - handle to an image object. - `width` (*mut c_uint) - receives the image width in pixels; must not be `NULL`. - `height` (*mut c_uint) - receives the image height in pixels; must not be `NULL`. ### Returns - `FPDF_BOOL` - `true` if successful. ``` -------------------------------- ### Porting C++ Pdfium code to Rust Source: https://docs.rs/pdfium-render/latest/pdfium_render/index.html?search=std%3A%3Avec This snippet demonstrates the translation of a C++ Pdfium code example to its Rust equivalent using the raw FFI bindings provided by pdfium-render. It shows the initialization, document loading, and cleanup process. ```c++ string test_doc = "test.pdf"; FPDF_InitLibrary(); FPDF_DOCUMENT doc = FPDF_LoadDocument(test_doc, NULL); // ... do something with doc FPDF_CloseDocument(doc); FPDF_DestroyLibrary(); ``` ```rust let pdfium = Pdfium::default(); let bindings = pdfium.bindings(); let test_doc = "test.pdf"; unsafe { bindings.FPDF_InitLibrary(); let doc = bindings.FPDF_LoadDocument(test_doc, None); // ... do something with doc bindings.FPDF_CloseDocument(doc); bindings.FPDF_DestroyLibrary(); } ``` -------------------------------- ### Get Link Annotation Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/struct.PdfPageLinkAnnotation.html Retrieves the PdfLink associated with this PdfPageLinkAnnotation. Use this to get the URI of the link. ```rust pub fn link(&self) -> Result, PdfiumError> ``` -------------------------------- ### Create a new page at the start Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/pages.rs.html Creates a new, blank page with specified dimensions and inserts it at the beginning of the page collection. ```APIDOC ## create_page_at_start ### Description Creates a new, empty `PdfPage` with the given `PdfPagePaperSize` and inserts it at the start of this `PdfPages` collection, shuffling down all other pages. ### Signature `#[inline] pub fn create_page_at_start(&mut self, size: PdfPagePaperSize) -> Result, PdfiumError>` ### Parameters - `size` (`PdfPagePaperSize`): The desired dimensions for the new page. ### Returns - `Result, PdfiumError>`: Ok containing the newly created `PdfPage` if successful, or an `Err` if page creation fails. ``` -------------------------------- ### PdfFonts Search Examples Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/struct.PdfFonts.html?search= Examples of how to perform searches within PdfFonts. These demonstrate common search patterns. ```APIDOC ## Example Searches ### Search for a specific type: ``` std::vec ``` ### Search for type conversions: ``` u32 -> bool ``` ### Search for generic type transformations: ``` Option, (T -> U) -> Option ``` ``` -------------------------------- ### Start Text Search from Index Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/page/text.rs.html Initiates a search for a given text string starting from a specific character index. ```APIDOC ## search_from ### Description Starts a search for a specified text string from a given character index on the PDF page, returning a `PdfPageTextSearch` object. ### Method `pub fn search_from(&self, text: &str, options: &PdfSearchOptions, index: PdfPageTextCharIndex) -> Result, PdfiumError>` ### Parameters - `text`: The string to search for. - `options`: A reference to `PdfSearchOptions` to configure the search. - `index`: The `PdfPageTextCharIndex` from which to start the search. ### Returns A `Result` containing a `PdfPageTextSearch` object for iterating through matches, or a `PdfiumError` if the search cannot be started (e.g., if the search text is empty). ``` -------------------------------- ### Bind to PDFium Library from Path Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdfium.rs.html Initializes the PDFium library by loading it from a specified file path. This function is not available on WASM targets or when the 'static' feature is enabled. It returns a `PdfiumLibraryBindings` object or an error if the library cannot be loaded or is already initialized. ```rust pub fn bind_to_library( path: impl AsRef, ) -> Result, PdfiumError> { if BINDINGS.get().is_none() { let bindings = DynamicPdfiumBindings::new( unsafe { Library::new(path.as_ref().as_os_str()) } .map_err(PdfiumError::LoadLibraryError)?, )?; Ok(Box::new(bindings)) } else { Err(PdfiumError::PdfiumLibraryBindingsAlreadyInitialized) } } ``` -------------------------------- ### Get Structure Tree for Page Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindgen/pdfium_7763.rs.html Get the structure tree for a given page. The caller owns the returned handle and must close it. ```APIDOC ## FPDF_StructTree_GetForPage ### Description Get the structure tree for a page. ### Parameters - **page** (FPDF_PAGE) - Handle to the page, as returned by FPDF_LoadPage(). ### Returns - `FPDF_STRUCTTREE` - A handle to the structure tree or NULL on error. Caller must release with FPDF_StructTree_Close(). ``` -------------------------------- ### Import all public definitions with prelude Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/index.html Use this statement to import all public definitions from the pdfium-render crate at once. This is the most convenient way to use the library. ```rust use pdfium_render::prelude::*; ``` -------------------------------- ### FPDF_InitLibraryWithConfig Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/trait.PdfiumLibraryBindings.html?search= Initializes the PDFium library with a specific configuration. ```APIDOC ## FPDF_InitLibraryWithConfig ### Description Initializes the PDFium library with a specific configuration. ### Method `unsafe fn FPDF_InitLibraryWithConfig(&self, config: *const FPDF_LIBRARY_CONFIG)` ### Parameters - `config` (*const FPDF_LIBRARY_CONFIG) - A pointer to the library configuration structure. ``` -------------------------------- ### Get JavaScript Action Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindgen/pdfium_7763.rs.html Get a specific JavaScript action from a document by its index. The caller owns the returned handle and must close it. ```APIDOC ## FPDFDoc_GetJavaScriptAction ### Description Get the JavaScript action at |index| in |document|. ### Parameters - **document** (FPDF_DOCUMENT) - Handle to a document. - **index** (`::std::os::raw::c_int`) - The index of the requested JavaScript action. ### Returns - `FPDF_JAVASCRIPT_ACTION` - The handle to the JavaScript action, or NULL on failure. Caller must close with FPDFDoc_CloseJavaScriptAction(). ``` -------------------------------- ### Get PDF Attachment Size Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/attachment.rs.html Determines the size of a PDF attachment in bytes. It calls FPDFAttachment_GetFile with a null buffer to get the length. ```rust let mut out_buflen: c_ulong = 0; if self.bindings().is_true(unsafe { self.bindings().FPDFAttachment_GetFile( self.handle, std::ptr::null_mut(), 0, &mut out_buflen, ) }) { out_buflen as usize } else { 0 } ``` -------------------------------- ### Bind to System Pdfium Library Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdfium.rs.html Initializes the external Pdfium library by loading it from system libraries. Returns bindings or an error if the library cannot be loaded. This is used when Pdfium is not statically linked and the `static` feature is not enabled. ```rust pub fn bind_to_system_library() -> Result, PdfiumError> { if BINDINGS.get().is_none() { let bindings = DynamicPdfiumBindings::new( unsafe { Library::new(Self::pdfium_platform_library_name()) } .map_err(PdfiumError::LoadLibraryError)?, )?; Ok(Box::new(bindings)) } else { Err(PdfiumError::PdfiumLibraryBindingsAlreadyInitialized) } } ``` -------------------------------- ### Render Thumbnail Example Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/struct.PdfPage.html Demonstrates how to render an embedded thumbnail for a PdfPage. If no thumbnail is embedded, it shows how to render one using PdfRenderConfig::thumbnail. ```rust let thumbnail_desired_pixel_size = 128; let thumbnail = page.render_with_config( &PdfRenderConfig::thumbnail(thumbnail_desired_pixel_size) )?; ``` -------------------------------- ### Add Installed Font Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindings/dynamic_bindings.rs.html Adds an installed font to PDFium's font mapping. This allows PDFium to use system-installed fonts for rendering. ```APIDOC ## extern_FPDF_AddInstalledFont ### Description Adds an installed font to the font mapper. ### Signature ```rust extern_FPDF_AddInstalledFont: unsafe extern "C" fn(mapper: *mut c_void, face: *const c_char, charset: c_int) ``` ### Parameters * `mapper` (*mut c_void): Pointer to the font mapper. * `face` (*const c_char): The name of the font face. * `charset` (c_int): The character set of the font. ``` -------------------------------- ### Pdfium Instance Creation Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/struct.Pdfium.html Methods for creating new Pdfium instances with or without custom configurations. ```APIDOC ## pub fn new(bindings: Box) -> Self Creates a new Pdfium instance from the given external Pdfium library bindings. ### Parameters - `bindings`: A boxed trait object implementing `PdfiumLibraryBindings`. ### Returns - `Self`: A new `Pdfium` instance. ``` ```APIDOC ## pub fn new_with_config( bindings: Box, config: PdfiumLibraryConfig, ) -> Self Creates a new Pdfium instance from the given external Pdfium library bindings, using the custom library configuration in the given `PdfiumLibraryConfig`. ### Parameters - `bindings`: A boxed trait object implementing `PdfiumLibraryBindings`. - `config`: A `PdfiumLibraryConfig` object specifying custom configurations. ### Returns - `Self`: A new `Pdfium` instance. ``` -------------------------------- ### Get Rendered Bitmap of Image Object Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindings/dynamic_bindings.rs.html Gets a rendered bitmap of the image object from a specific page and document. This provides a visual representation. ```rust unsafe fn FPDFImageObj_GetRenderedBitmap( &self, document: FPDF_DOCUMENT, page: FPDF_PAGE, image_object: FPDF_PAGEOBJECT, ) -> FPDF_BITMAP { (self.extern_FPDFImageObj_GetRenderedBitmap)(document, page, image_object) } ``` -------------------------------- ### Get JavaScript Action Name Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindgen/pdfium_7763.rs.html Get the name of a JavaScript action. The buffer is only modified if it's large enough. Returns 0 on errors. ```APIDOC ## FPDFJavaScriptAction_GetName ### Description Get the name from the |javascript| handle. |buffer| is only modified if |buflen| is longer than the length of the name. On errors, |buffer| is unmodified and the returned length is 0. ### Parameters - **javascript** (FPDF_JAVASCRIPT_ACTION) - Handle to an JavaScript action. - **buffer** (*mut FPDF_WCHAR) - Buffer for holding the name, encoded in UTF-16LE. - **buflen** (`::std::os::raw::c_ulong`) - Length of the buffer in bytes. ### Returns - `::std::os::raw::c_ulong` - The length of the JavaScript action name in bytes. ``` -------------------------------- ### Render thumbnail for PdfPage Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/struct.PdfPage.html?search= Example of rendering a thumbnail for a PdfPage with a specified pixel size using `render_with_config`. ```rust let thumbnail_desired_pixel_size = 128; let thumbnail = page.render_with_config( &PdfRenderConfig::thumbnail(thumbnail_desired_pixel_size) )?; // Renders a 128 x 128 thumbnail of the page ``` -------------------------------- ### FPDF_InitLibrary Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/trait.PdfiumLibraryBindings.html?search= Initializes the PDFium library with default settings. ```APIDOC ## FPDF_InitLibrary ### Description Initializes the PDFium library with default settings. ### Method `unsafe fn FPDF_InitLibrary(&self)` ``` -------------------------------- ### Get JavaScript Action Script Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindgen/pdfium_7763.rs.html Get the script content of a JavaScript action. The buffer is only modified if it's large enough. Returns 0 on errors. ```APIDOC ## FPDFJavaScriptAction_GetScript ### Description Get the script from the |javascript| handle. |buffer| is only modified if |buflen| is longer than the length of the script. On errors, |buffer| is unmodified and the returned length is 0. ### Parameters - **javascript** (FPDF_JAVASCRIPT_ACTION) - Handle to an JavaScript action. - **buffer** (*mut FPDF_WCHAR) - Buffer for holding the name, encoded in UTF-16LE. - **buflen** (`::std::os::raw::c_ulong`) - Length of the buffer in bytes. ### Returns - `::std::os::raw::c_ulong` - The length of the JavaScript action name in bytes. ``` -------------------------------- ### Get Parameter Blob Value Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindgen/pdfium_7763.rs.html Retrieves the blob value of a property in a content mark by its key. Can be used to get the required buffer size or the blob value itself. ```APIDOC ## FPDFPageObjMark_GetParamBlobValue ### Description Experimental API. Get the value of a blob property in a content mark by key. ### Parameters - **mark** (FPDF_PAGEOBJECTMARK) - Handle to a content mark. - **key** (FPDF_BYTESTRING) - String key of the property. - **buffer** (*mut ::std::os::raw::c_uchar) - Buffer for holding the returned value. This is only modified if |buflen| is large enough to store the value. Optional, pass null to just retrieve the size of the buffer needed. - **buflen** (::std::os::raw::c_ulong) - Length of the buffer in bytes. - **out_buflen** (*mut ::std::os::raw::c_ulong) - Pointer to variable that will receive the minimum buffer size in bytes to contain the name. This is a required parameter. Not filled if FALSE is returned. ### Returns Returns TRUE if the key maps to a string/blob value, FALSE otherwise. ``` -------------------------------- ### Create New PDF Document Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdfium.rs.html Creates a new, empty PDF document in memory. The document is initialized with a default version. ```rust pub fn create_new_pdf<'a>(&'a self) -> Result, PdfiumError> { Self::pdfium_document_handle_to_result( unsafe { self.bindings().FPDF_CreateNewDocument() }, self.bindings(), ) .map(|mut document| { document.set_version(PdfDocumentVersion::DEFAULT_VERSION); document }) } ``` -------------------------------- ### Get Parameter String Value Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindgen/pdfium_7763.rs.html Retrieves the string value of a property in a content mark by its key. Can be used to get the required buffer size or the string value itself. ```APIDOC ## FPDFPageObjMark_GetParamStringValue ### Description Experimental API. Get the value of a string property in a content mark by key. ### Parameters - **mark** (FPDF_PAGEOBJECTMARK) - Handle to a content mark. - **key** (FPDF_BYTESTRING) - String key of the property. - **buffer** (*mut FPDF_WCHAR) - Buffer for holding the returned value in UTF-16LE. This is only modified if |buflen| is large enough to store the value. Optional, pass null to just retrieve the size of the buffer needed. - **buflen** (::std::os::raw::c_ulong) - Length of the buffer in bytes. - **out_buflen** (*mut ::std::os::raw::c_ulong) - Pointer to variable that will receive the minimum buffer size in bytes to contain the name. This is a required parameter. Not filled if FALSE is returned. ### Returns Returns TRUE if the key maps to a string/blob value, FALSE otherwise. ``` -------------------------------- ### TryFrom Implementation Example Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/enum.PdfFormType.html Demonstrates the conversion from another type `U` into `T` (PdfFormType in this context) which may fail. The `Error` type indicates potential conversion issues. ```rust type Error = Infallible; fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Get XFA Packet Count Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindings/dynamic_bindings.rs.html Gets the number of XFA (XML Forms Architecture) packets in a PDF document. This feature is enabled by the 'pdfium_enable_xfa' feature flag. ```rust #[cfg(feature = "pdfium_enable_xfa")] #[inline] #[allow(non_snake_case)] unsafe fn FPDF_GetXFAPacketCount(&self, document: FPDF_DOCUMENT) -> c_int { (self.extern_FPDF_GetXFAPacketCount)(document) } ``` -------------------------------- ### Initialize PdfBookmarksIterator Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/bookmarks.rs.html Constructs a new PdfBookmarksIterator. It takes an optional starting node, a flag to include descendants, an optional sibling to skip, and the PDF document handle. ```rust pub(crate) fn new( start_node: Option>, include_descendants: bool, skip_sibling: Option>, document_handle: FPDF_DOCUMENT, ) -> Self { let mut result = PdfBookmarksIterator { document_handle, include_descendants, pending_stack: Vec::with_capacity(20), visited: HashSet::new(), skip_sibling: std::ptr::null_mut(), lifetime: PhantomData, }; // If we have a skip-sibling, record its handle. if let Some(skip_sibling) = skip_sibling { result.skip_sibling = skip_sibling.bookmark_handle(); } // Push the start node onto the stack to initiate graph traversal. if let Some(start_node) = start_node { result.pending_stack.push(( start_node.bookmark_handle(), start_node .parent() .map(|parent| parent.bookmark_handle()) .unwrap_or(std::ptr::null_mut()), )); } result } ``` -------------------------------- ### From> for PdfAction<'a> Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/launch/struct.PdfActionLaunch.html?search= Provides a conversion from PdfActionLaunch to PdfAction. ```APIDOC ### impl<'a> From> for PdfAction<'a> #### fn from(action: PdfActionLaunch<'a>) -> Self Converts to this type from the input type. ``` -------------------------------- ### Get PDF Attachment Name Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/attachment.rs.html Retrieves the name of a PDF attachment. This is a two-step process: first, get the name length, then retrieve the name itself in UTF16-LE format. ```rust let buffer_length = unsafe { self.bindings() .FPDFAttachment_GetName(self.handle, std::ptr::null_mut(), 0) }; if buffer_length == 0 { return String::new(); } let mut buffer = create_byte_buffer(buffer_length as usize); let result = unsafe { self.bindings().FPDFAttachment_GetName( self.handle, buffer.as_mut_ptr() as *mut FPDF_WCHAR, buffer_length, ) }; assert_eq!(result, buffer_length); get_string_from_pdfium_utf16le_bytes(buffer).unwrap_or_default() ``` -------------------------------- ### Sync for PdfActionLaunch<'a> Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/launch/struct.PdfActionLaunch.html Indicates that PdfActionLaunch<'a> can be safely shared between threads. Available only when the 'thread_safe' feature is enabled. ```rust impl<'a> Sync for PdfActionLaunch<'a> ``` -------------------------------- ### Get a specific path object from PdfClipPath Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/struct.PdfClipPath.html Use the `get` method with an index to retrieve a specific `PdfClipPathSegments` object. Returns a `Result` which may contain a `PdfiumError`. ```rust pub fn get( &self, index: PdfClipPathSegmentIndex, ) -> Result, PdfiumError> ``` -------------------------------- ### Get Unscaled Font Size Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/char/struct.PdfPageTextChar.html Retrieves the font size explicitly applied to the character, before any vertical scaling. Use `scaled_font_size` to get the effective rendered size. ```rust pub fn unscaled_font_size(&self) -> PdfPoints ``` -------------------------------- ### Public Prelude for pdfium-render Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/lib.rs.html This snippet defines the public prelude for the `pdfium-render` crate. It allows users to import all public definitions conveniently with a single `use` statement. ```rust /// A prelude for conveniently importing all public `pdfium-render` definitions at once. /// /// Usage: /// ``` /// use pdfium_render::prelude::* /// ``` pub mod prelude { pub use crate::{ bindings::*, config::*, error::*, pdf::action::*, pdf::appearance_mode::*, pdf::bitmap::*, pdf::color::*, pdf::color_space::*, pdf::destination::*, pdf::document::attachment::*, pdf::document::attachments::*, pdf::document::bookmark::*, pdf::document::bookmarks::*, pdf::document::fonts::*, pdf::document::form::*, pdf::document::metadata::*, pdf::document::page::annotation::attachment_points::*, pdf::document::page::annotation::circle::*, pdf::document::page::annotation::free_text::*, pdf::document::page::annotation::highlight::*, pdf::document::page::annotation::ink::*, pdf::document::page::annotation::link::*, pdf::document::page::annotation::objects::*, pdf::document::page::annotation::popup::*, pdf::document::page::annotation::redacted::*, pdf::document::page::annotation::square::*, pdf::document::page::annotation::squiggly::*, pdf::document::page::annotation::stamp::*, pdf::document::page::annotation::strikeout::*, pdf::document::page::annotation::text::*, pdf::document::page::annotation::underline::*, pdf::document::page::annotation::unsupported::*, pdf::document::page::annotation::variable_text::*, pdf::document::page::annotation::widget::*, pdf::document::page::annotation::xfa_widget::*, pdf::document::page::annotation::{ PdfPageAnnotation, PdfPageAnnotationCommon, PdfPageAnnotationType, }, pdf::document::page::annotations::*, pdf::document::page::boundaries::*, pdf::document::page::field::button::*, pdf::document::page::field::checkbox::*, pdf::document::page::field::combo::*, pdf::document::page::field::list::*, pdf::document::page::field::option::*, pdf::document::page::field::options::*, pdf::document::page::field::radio::* }; } ``` -------------------------------- ### Get Unscaled Font Size of a Character Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/page/text/char.rs.html Retrieves the base font size of a character, ignoring any vertical scaling. Use this to get the font's intrinsic size. ```rust pub fn unscaled_font_size(&self) -> PdfPoints { unsafe { PdfPoints::new( self.bindings() .FPDFText_GetFontSize(self.text_page_handle, self.index) as f32, ) } } ``` -------------------------------- ### Provide Custom Font Implementation Source: https://docs.rs/pdfium-render/latest/pdfium_render/prelude/provider/trait.PdfiumCustomFontProvider.html?search= Implement the `provide` method to handle custom font lookup requests. Return `Some(PdfiumCustomFontProviderResponse)` if the font is found, or `None` if it's not available. ```rust fn provide( &mut self, request: PdfiumCustomFontProviderRequest, ) -> Option ``` -------------------------------- ### Bind to System Library Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdfium.rs.html Initializes the external Pdfium library by loading it from the system libraries. This function is available when the `static` feature is not enabled. It returns a `PdfiumLibraryBindings` object or an error if the library cannot be loaded. ```APIDOC ## bind_to_system_library ### Description Initializes the external Pdfium library, loading it from the system libraries. Returns a new [PdfiumLibraryBindings] object that contains bindings to the functions exposed by the library, or an error if the library could not be loaded. This function is available when the `static` feature is not enabled. ### Method `Pdfium::bind_to_system_library()` ### Returns - `Result, PdfiumError>`: A boxed trait object for Pdfium bindings if successful, or a `PdfiumError` if the library could not be loaded or was already initialized. ``` -------------------------------- ### Get Path Fill Mode Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdf/document/page/object/path.rs.html Retrieves the fill mode used for determining which sub-paths of a path should be filled. This function interacts with the PDFium library to get the drawing mode. ```rust pub fn fill_mode(&self) -> Result { let mut raw_fill_mode: c_int = 0; let mut _raw_stroke: FPDF_BOOL = self.bindings().FALSE(); if self.bindings().is_true(unsafe { self.bindings().FPDFPath_GetDrawMode( self.object_handle(), &mut raw_fill_mode, &mut _raw_stroke, ) }) { PdfPathFillMode::from_pdfium(raw_fill_mode) } else { Err(PdfiumError::PdfiumLibraryInternalError( PdfiumInternalError::Unknown, )) } } ``` -------------------------------- ### Get Structure Tree Child at Index Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/bindgen/pdfium_7763.rs.html Get a child element from the structure tree at a specific index. The handle remains valid as long as the structure tree handle is valid. ```APIDOC ## FPDF_StructTree_GetChildAtIndex ### Description Get a child in the structure tree. ### Parameters - **struct_tree** (FPDF_STRUCTTREE) - Handle to the structure tree. - **index** (`::std::os::raw::c_int`) - The index for the child, 0-based. Must be less than the value returned by FPDF_StructTree_CountChildren(). ### Returns - `FPDF_STRUCTELEMENT` - The child at the n-th index or NULL on error. The caller does not own the handle. ``` -------------------------------- ### Bind to Library Source: https://docs.rs/pdfium-render/latest/src/pdfium_render/pdfium.rs.html Initializes the external pdfium library, loading it from the given path. Returns a new [PdfiumLibraryBindings] object that contains bindings to the functions exposed by the library, or an error if the library could not be loaded. ```APIDOC ## bind_to_library ### Description Initializes the external pdfium library, loading it from the given path. Returns a new [PdfiumLibraryBindings] object that contains bindings to the functions exposed by the library, or an error if the library could not be loaded. ### Function Signature `pub fn bind_to_library(path: impl AsRef) -> Result, PdfiumError>` ```