boazsegev / combine_pdf

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

Adding page numbers set them to wrong positions #55

Closed AntonIsaev closed 8 years ago

AntonIsaev commented 8 years ago

Hello!

Please advise me with _number_pages_ method. I used the next code:

# erasing previously generated file
  if File::exist?('public/pdf/test_full.pdf')
    File::delete('public/pdf/test_full.pdf')
  end  

# creating an object
  pdf = CombinePDF.new()

# adding clear page
  pdf.new_page

# setting up options for number_pages procedure
  opt = {
        :number_format => '%s',
        :start_at => 1,
        :font => :Times,
        :margin_from_side => 0,
        :margin_from_height => 0,
        :location => [:bottom],
        :font_size => 12
  }

# running numbering
  pdf.number_pages(opt)

# getting a result
  pdf.save('public/pdf/test_full.pdf')

What I am waiting to receive: I want to see a blank page with "1" at the middle-bottom position of page.

What I received: "1" in strange position, as I wanted to add "1" to the center-right position of page. I attached a result file: test_full.pdf

boazsegev commented 8 years ago

Hi @AntonIsaev

There's an issue with the font you chose - it is unsupported (I'm amazed you have anything showing at all instead of a broken PDF).

A list of supported font options can be fount in the Page#textbox documentation.

Try Using:

# # No need for this - Files are always overwritten on "save":
#  if File::exist?('public/pdf/test_full.pdf')
#    File::delete('public/pdf/test_full.pdf')
#  end  

# creating an object
  pdf = CombinePDF.new()

# adding clear page
  pdf.new_page

# setting up options for number_pages procedure
  opt = {
        :number_format => '%s',
        :start_at => 1,
        :font => :"Times-Roman",
        :margin_from_side => 0,
        :margin_from_height => 0,
        :location => [:bottom],
        :font_size => 12
  }

# running numbering
  pdf.number_pages(opt)

# getting a result
  pdf.save('public/pdf/test_full.pdf')

In the future, I recommend using StackOverflow for questions, as the community is likely to respond with an answer before I can.

Good Luck! Bo.