excid3 / receipts

Easy receipts and invoices for your Ruby on Rails applications
MIT License
612 stars 77 forks source link

How to customize the layout for a receipt printer? #7

Closed HatemMahmoud closed 3 years ago

HatemMahmoud commented 7 years ago

Hi,

Thanks for the great gem!

How can you customize the layout of the pdf to use smaller margins and smaller fonts for printing on small thermal paper? Also, how could you add a logo and update the message on the header of the receipt?

Thank you!

excid3 commented 7 years ago

Hey @HatemMahmoud!

Probably the best way of doing that would be to create like a ThermalReceipt class or something that redefines the methods for generating the receipt. You'll basically have to tweak the bounding boxes and things to get a smaller size and then the same for fonts and stuff.

It might be a good time to refactor all the code for the receipt so that all the margin values and things could be configurable in a hash early on instead of being hardcoded.

Dragonicity commented 6 years ago

The message on the header of the receipt can be overridden by simply including a message attribute when creating the new receipt in the Charge model:

def receipt
  Receipts::Receipt.new(
    id: id,
    message: "My custom message text",
...
kudapara commented 3 years ago

Probably the best way of doing that would be to create like a ThermalReceipt class or something that redefines the methods for generating the receipt. You'll basically have to tweak the bounding boxes and things to get a smaller size and then the same for fonts and stuff.

Does this also work when attempting to change the size of the print paper, e.g printing to A5?

excid3 commented 3 years ago

Yep, changing the size of the paper larger or smaller would need the same tweaks.

If someone wants to make a PR for customizable sizes, that'd be awesome!