Skip to content

Commit

Permalink
Progressing #80
Browse files Browse the repository at this point in the history
  • Loading branch information
Alastair Carey committed Apr 10, 2023
1 parent cee625f commit e808cf9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pdfium-render"
version = "0.8.0"
version = "0.8.1"
edition = "2018"
publish = true
description = "A high-level idiomatic Rust wrapper around Pdfium, the C++ PDF library used by the Google Chromium project."
Expand All @@ -10,15 +10,15 @@ repository = "https://github.com/ajrcarey/pdfium-render"
license = "MIT OR Apache-2.0"
keywords = ["pdf", "pdfium"]
categories = ["api-bindings", "multimedia::images", "visualization", "wasm"]
authors = ["Alastair Carey <alastair@duetto.dev>"]
authors = ["Alastair Carey <alastair@alastaircarey.com>"]

[lib]
name = "pdfium_render"
crate-type = ["lib", "staticlib", "cdylib"]
doctest = false

[dependencies]
bitflags = "^1"
bitflags = "^2"
bytes = "^1"
bytemuck = "^1"
image = { version = ">= 0.24.0", optional = true } # DynamicImage trait definitions changed between 0.23.14 and 0.24.0; we use trait from version 0.24.0 and later.
Expand All @@ -30,7 +30,7 @@ utf16string = "^0.2"
vecmath = "^1"

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_log = "^0.2"
console_log = "^1"
console_error_panic_hook = "^0.1"
js-sys = "^0.3"
wasm-bindgen = { version = "^0.2", features = ["enable-interning"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/form_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn main() -> Result<(), PdfiumError> {
.or_else(|_| Pdfium::bind_to_system_library())?,
);

let document = pdfium.load_pdf_from_file("test/form-test.pdf", None)?; // Load the sample file...
let document = pdfium.load_pdf_from_file("test/form-test.pdf", None)?;

match document.form() {
Some(form) => println!(
Expand Down
4 changes: 2 additions & 2 deletions examples/thread_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use std::thread;
// _not_ multi-threading.

fn main() -> Result<(), PdfiumError> {
// For general comments about pdfium-render and binding to Pdfium, see export.rs.

// Define bitmap rendering settings that will be used by all threads.

let config = PdfRenderConfig::new()
Expand Down Expand Up @@ -62,8 +64,6 @@ fn render(render_config: &PdfRenderConfig, path: &str) -> Result<(), PdfiumError
// Render each page in the document at the given path out to a JPG file, using the
// given bindings and rendering configuration.

// For general comments about pdfium-render and binding to Pdfium, see export.rs.

let pdfium = Pdfium::new(
Pdfium::bind_to_library(Pdfium::pdfium_platform_library_name_at_path("./"))
.or_else(|_| Pdfium::bind_to_system_library())?,
Expand Down
4 changes: 2 additions & 2 deletions examples/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ pub async fn log_page_metrics_to_console(url: String) {
pub async fn get_image_data_for_page(
url: String,
index: PdfPageIndex,
width: u16,
height: u16,
width: Pixels,
height: Pixels,
) -> ImageData {
Pdfium::new(Pdfium::bind_to_system_library().unwrap())
.load_pdf_from_fetch(url, None)
Expand Down
18 changes: 9 additions & 9 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::bindgen::{
FPDF_FORMHANDLE, FPDF_PAGE, FS_RECTF,
};
use crate::bindings::PdfiumLibraryBindings;
use crate::bitmap::{PdfBitmap, PdfBitmapFormat, PdfBitmapRotation};
use crate::bitmap::{PdfBitmap, PdfBitmapFormat, PdfBitmapRotation, Pixels};
use crate::create_transform_setters;
use crate::error::{PdfiumError, PdfiumInternalError};
use crate::font::PdfFont;
Expand Down Expand Up @@ -718,8 +718,8 @@ impl<'a> PdfPage<'a> {
/// using [PdfBitmap::empty()] and reuse it across multiple calls to [PdfPage::render_into_bitmap()].
pub fn render(
&self,
width: u16,
height: u16,
width: Pixels,
height: Pixels,
rotation: Option<PdfBitmapRotation>,
) -> Result<PdfBitmap, PdfiumError> {
let mut bitmap =
Expand Down Expand Up @@ -749,8 +749,8 @@ impl<'a> PdfPage<'a> {
let settings = config.apply_to_page(self);

let mut bitmap = PdfBitmap::empty(
settings.width as u16,
settings.height as u16,
settings.width as Pixels,
settings.height as Pixels,
PdfBitmapFormat::from_pdfium(settings.format as u32)
.unwrap_or_else(|_| PdfBitmapFormat::default()),
self.bindings,
Expand All @@ -773,8 +773,8 @@ impl<'a> PdfPage<'a> {
pub fn render_into_bitmap(
&self,
bitmap: &mut PdfBitmap,
width: u16,
height: u16,
width: Pixels,
height: Pixels,
rotation: Option<PdfBitmapRotation>,
) -> Result<(), PdfiumError> {
let mut config = PdfRenderConfig::new()
Expand Down Expand Up @@ -915,8 +915,8 @@ impl<'a> PdfPage<'a> {
#[doc(hidden)]
pub fn get_bitmap(
&self,
width: u16,
height: u16,
width: Pixels,
height: Pixels,
rotation: Option<PdfBitmapRotation>,
) -> Result<PdfBitmap, PdfiumError> {
self.render(width, height, rotation)
Expand Down
4 changes: 2 additions & 2 deletions src/page_object_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,12 @@ impl<'a> PdfPageImageObject<'a> {
/// This function is only available when this crate's `image` feature is enabled.
#[cfg(feature = "image")]
pub fn set_image(&mut self, image: &DynamicImage) -> Result<(), PdfiumError> {
let width: u16 = image
let width: Pixels = image
.width()
.try_into()
.map_err(|_| PdfiumError::ImageSizeOutOfBounds)?;

let height: u16 = image
let height: Pixels = image
.height()
.try_into()
.map_err(|_| PdfiumError::ImageSizeOutOfBounds)?;
Expand Down

0 comments on commit e808cf9

Please sign in to comment.