Skip to content

Commit

Permalink
Resolves #142
Browse files Browse the repository at this point in the history
  • Loading branch information
Alastair Carey committed Jun 13, 2024
1 parent 37d394f commit 2523a4a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 49 deletions.
3 changes: 1 addition & 2 deletions examples/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ pub fn main() -> Result<(), PdfiumError> {
let result = page
.render_with_config(&render_config)? // Initializes a bitmap with the given configuration for this page ...
.as_image() // ... renders it to an Image::DynamicImage ...
.as_rgba8() // ... sets the correct color space ...
.ok_or(PdfiumError::ImageError)?
.into_rgb8() // ... sets the correct color space ...
.save_with_format(format!("export-test-page-{}.jpg", index), ImageFormat::Jpeg); // ... and exports it to a JPEG.

assert!(result.is_ok());
Expand Down
3 changes: 1 addition & 2 deletions examples/export_clip_crop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ fn main() -> Result<(), PdfiumError> {
(clip_right - clip_left) as u32,
(clip_bottom - clip_top) as u32,
)
.as_rgba8()
.ok_or(PdfiumError::ImageError)?
.into_rgb8()
.save_with_format(
format!(
"export-clip-crop-test-{}-{}.jpg",
Expand Down
84 changes: 41 additions & 43 deletions examples/fill_form_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,47 @@ pub fn main() -> Result<(), PdfiumError> {
if let Some(field) = annotation.as_form_field_mut() {
// If this field is a fillable form field...

// if let Some(field) = field.as_radio_button_field_mut() {
// // ... select its radio button.
//
// println!(
// "Page {}, radio button {}: {:?} currently has value: {}",
// page_index,
// annotation_index,
// field.name(),
// format!("{:?}", field.is_checked()),
// );
//
// field.set_checked()?;
//
// println!(
// "Page {}, radio button {}: {:?} now has updated value: {}",
// page_index,
// annotation_index,
// field.name(),
// format!("{:?}", field.is_checked()),
// );
// } else if let Some(field) = field.as_checkbox_field_mut() {
// // ... check its checkbox.
//
// println!(
// "Page {}, checkbox {}: {:?} currently has value: {}",
// page_index,
// annotation_index,
// field.name(),
// format!("{:?}", field.is_checked()),
// );
//
// field.set_checked(true)?;
//
// println!(
// "Page {}, checkbox {}: {:?} now has updated value: {}",
// page_index,
// annotation_index,
// field.name(),
// format!("{:?}", field.is_checked()),
// );
// } else

if let Some(field) = field.as_text_field_mut() {
if let Some(field) = field.as_radio_button_field_mut() {
// ... select its radio button.

println!(
"Page {}, radio button {}: {:?} currently has value: {}",
page_index,
annotation_index,
field.name(),
format!("{:?}", field.is_checked()),
);

field.set_checked()?;

println!(
"Page {}, radio button {}: {:?} now has updated value: {}",
page_index,
annotation_index,
field.name(),
format!("{:?}", field.is_checked()),
);
} else if let Some(field) = field.as_checkbox_field_mut() {
// ... check its checkbox.

println!(
"Page {}, checkbox {}: {:?} currently has value: {}",
page_index,
annotation_index,
field.name(),
format!("{:?}", field.is_checked()),
);

field.set_checked(true)?;

println!(
"Page {}, checkbox {}: {:?} now has updated value: {}",
page_index,
annotation_index,
field.name(),
format!("{:?}", field.is_checked()),
);
} else if let Some(field) = field.as_text_field_mut() {
// ... set its value to the field's internal name.

println!(
Expand Down
4 changes: 2 additions & 2 deletions examples/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use web_sys::ImageData;
// on how to build and package this example alongside a WASM build of Pdfium, suitable
// for running in a browser.

/// Downloads the given url, opens it as a PDF document, then Logs the width and height of
/// Downloads the given URL, opens it as a PDF document, then logs the width and height of
/// each page in the document, along with other document metrics, to the Javascript console.
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
Expand Down Expand Up @@ -111,7 +111,7 @@ pub async fn log_page_metrics_to_console(url: String) {
});
}

/// Downloads the given url, opens it as a PDF document, then returns the ImageData for
/// Downloads the given URL, opens it as a PDF document, then returns the ImageData for
/// the given page index using the given bitmap dimensions.
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
Expand Down

0 comments on commit 2523a4a

Please sign in to comment.