Skip to content

Commit

Permalink
Allow setting a document title from the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantaly committed Feb 24, 2021
1 parent b10e471 commit 0d3d957
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jpeg-to-pdf"
version = "0.2.1"
version = "0.2.2"
authors = ["Kai Page <kai@quantaly.net>"]
edition = "2018"
description = "Create PDFs from JPEG images"
Expand Down
15 changes: 11 additions & 4 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{fs::{self, File}, io::Write};
use std::io::{self, BufWriter};
use std::fs::{self, File};
use std::io::{self, prelude::*, BufWriter};
use std::path::PathBuf;
use std::process;

Expand All @@ -8,7 +8,7 @@ use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Opt {
/// By default, uses the same name as the first input with a ".pdf" extension
/// By default, uses the same name as the first input, with the extension changed to ".pdf"
#[structopt(short, long, parse(from_os_str))]
output: Option<PathBuf>,

Expand All @@ -21,6 +21,10 @@ struct Opt {
/// Strip EXIF metadata from the embedded images
#[structopt(long)]
strip_exif: bool,

/// Add a title to the generated PDF
#[structopt(long)]
title: Option<String>,
}

fn main() -> io::Result<()> {
Expand All @@ -45,7 +49,10 @@ fn main() -> io::Result<()> {
// have to do this with a for loop instead of job.add_images() to use the ? error-handling operator
job = job.add_image(fs::read(image)?);
}
job = job.set_dpi(opt.dpi).strip_exif(opt.strip_exif);
job = job
.set_dpi(opt.dpi)
.strip_exif(opt.strip_exif)
.set_document_title(opt.title.unwrap_or_else(String::new));

let mut out = BufWriter::new(out_file);
if let Err(e) = job.create_pdf(&mut out) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc(html_root_url = "https://docs.rs/jpeg-to-pdf/0.2.1")]
#![doc(html_root_url = "https://docs.rs/jpeg-to-pdf/0.2.2")]
//! Creates PDFs from JPEG images.
//!
//! Images are embedded directly in the PDF, without any re-encoding.
Expand Down

0 comments on commit 0d3d957

Please sign in to comment.