danielsaidi / PrintingKit

PrintingKit is a Swift SDK that helps you print images, strings, views, PDFs etc. in Swift and SwiftUI.
MIT License
95 stars 12 forks source link

Unclear how to set paper sizes #7

Open dayglojago opened 3 months ago

dayglojago commented 3 months ago

Hi there!

I'm not sure if this is the correct forum for this question/issue, but I've been using PrintingKit in the same project referenced in issue #6, and after inspecting the code, it's not clear how to change the target text/paper size.

I'd also like to address the margins, because 1" margins on a 2.83" slice of paper is definitely not working :)

In my use case, I'm printing to a thermal receipt printer. The default paper size is 72 mm x 2000 mm or ~2.83" x ~78.74" (the length is basically infinity though, because it can go as long as there's paper left.) However, it seems that PrintingKit defaults to 8.5 x 11" paper, which creates this preview:

Screenshot 2024-06-22 at 1 30 42 PM

And this output:

IMG_2050

As you can see, it does print, although perhaps with less readability than I was hoping. I was looking at maybe using the scale parameter, but I'm not sure that would help with my issues with—for example—overlarge margins.

I've scoured the documentation and the code; it's unclear that there are any other parameters to play around with other than scale. Are different paper sizes supported? Is there a way to set them? I just need the one! :)

danielsaidi commented 3 months ago

Hi @dayglojago

For now, some PrintItem cases let you define a print configuration. Perhaps all item types should support it, or perhaps the configuration should be passed into the print function instead?

However, string and attributed string lets you define a PDF page configuration, which currently lets you define page size and page margins.

I haven't experienced the subpar result you shared in the image, but I'm sure there are many caveats when it comes to printing on various printers. :|