Skip to content
/ img2pdf Public

Simple crate for converting an image to PDF in Rust

Notifications You must be signed in to change notification settings

pstwh/img2pdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

img2pdf

img2pdf is a simple rust library for converting an image into a PDF file. It supports handling image files with transparency and compressing them into PDF documents. It's really simple.

Usage

Converting an Image from Bytes

To convert an image provided as a byte array to a PDF in memory:

use img2pdf::img2pdf_from_bytes;

let image_data = std::fs::read("sample_image.jpg").expect("Failed to read image");
let pdf_data = img2pdf_from_bytes(&image_data).expect("Failed to convert image to PDF");

std::fs::write("output.pdf", pdf_data).expect("Failed to write PDF file");

Converting an Image File to a PDF File

To convert an image file directly to a PDF file:

use img2pdf::img2pdf_file;

img2pdf_file("sample_image.png", "output.pdf").expect("Failed to convert image to PDF");

Command Line Interface

There is also a CLI option, but it may not be relevant for your use case

img2pdf <input_image> <output_pdf>

About

Simple crate for converting an image to PDF in Rust

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages