boazsegev / combine_pdf

A Pure ruby library to merge PDF files, number pages and maybe more...
MIT License
734 stars 155 forks source link

Possible to show total number of pages with number_pages method? #144

Closed leesmith closed 6 years ago

leesmith commented 6 years ago

Is it possible to show "3 of 8" as an optional format to the number_pages method? Thanks!

boazsegev commented 6 years ago

Hi @leesmith

Sure it's possible. Read the documentation for CombinePDF::PDF#number_pages and consider:

filename = "foo.pdf"
pdf = CombinePDF.load filename
page_count = pdf.pages.length
number_format = "%s of #{page_count}"
pdf.number_pages number_format: number_format

Kindly, Bo.

leesmith commented 6 years ago

That worked perfectly! Thanks @boazsegev 🍻