boazsegev / combine_pdf

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

Pages counter pdf #149

Closed curiosport closed 5 years ago

curiosport commented 5 years ago

Hello.

What part of your code counts pages in a pdf? I would like to be able to use that code without having to import the gem into my module.

Thank you.

boazsegev commented 5 years ago

Hi @curiosport ,

I'm think my answer might disappoint you, because the page "counting" code only works after the PDF was parsed and deconstructed into Ruby objects.

In practice, CombinePDF collects all the Ruby objects that represent valid (viewable) PDF pages and returning them as an Array.

If all you need is to count the number of pages in a PDF, this might not be the optimal gem for your needs.

Kindly, Bo.

curiosport commented 5 years ago

@boazsegev I don't really want to use any gem, many work the same as yours, they always apply functions I don't need, but then do you know any way to count the pages with pure Ruby?

boazsegev commented 5 years ago

I'm sorry, I can't think of any way to do so without parsing the PDF (at least partially, if not fully).

On Dec 14, 2018, at 05:51, curiosport notifications@github.com wrote:

@boazsegev https://github.com/boazsegev I don't really want to use any gem, many work the same as yours, they always apply functions I don't need, but then do you know any way to count the pages with pure Ruby?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/boazsegev/combine_pdf/issues/149#issuecomment-447289229, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1I3keOcmOoaY_h57B5LYeahzz6XKs1ks5u44KrgaJpZM4ZS3wU.

curiosport commented 5 years ago

Thanks anyway, I read that I could create a virtual printer and every page that is "printed" counting it, is a good idea but with Ruby there are no examples of how to do it.

boazsegev commented 5 years ago

I think a virtual printer would cost more (in performance) than using a gem in order to parse the PDF and count the pages.

I'm not sure why you don't want to use any gems in your project, but I think gems are an important resource. Yes, dependencies should be kept to a minimum where possible, but parsing a PDF file is probably not something you want to code from zero.