pklaus / brother_ql

Python package for the raster language protocol of the Brother QL series label printers (QL-500, QL-550, QL-560, QL-570, QL-700, QL-710W, QL-720NW, QL-800, QL-810W, QL-820NWB, QL-1050, QL-1060N and more).
GNU General Public License v3.0
560 stars 166 forks source link

Cut after last label only #150

Open stuartlynne opened 8 months ago

stuartlynne commented 8 months ago

My application prints either one or two labels on pre-cut 62x100 labels.

I need to cut after the last label only.

If a single label is printed cut after it.

If two labels are printed cut only after the second.

I am using pdf2image convert_from_bytes to generate an images list (from pdf on stdin.)

And then:

model = 'QL-710W'
printer = 'tcp://192.168.40.16:9100'
kwargs = { 'rotate': '90', 'cut': False, 'label': labelsize,
qlr = BrotherQLRaster(model)
instructions = convert(qlr, images, **kwargs)
send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)

Setting cut to False I get no cut. Setting it to True I get a cut after each label.

Suggestions? Thanks!

FriedrichFroebel commented 8 months ago

This does not seem to be supported without further changes as both command sets handled here are supported by your model: https://github.com/pklaus/brother_ql/blob/56cf4394ad750346c6b664821ccd7489ec140dae/brother_ql/conversion.py#L175-L187 You might try to use

convert(qlr, images, **kwargs)
qlr.cut_at_end = True
qlr.add_expanded_mode()
instructions = qlr.data

but I have not tested it and this probably will not actually work.

stuartlynne commented 8 months ago

No, that did not work.

On Sat, Mar 2, 2024 at 1:27 AM FriedrichFroebel @.***> wrote:

This does not seem to be supported without further changes as both command sets handled here are supported by your model: https://github.com/pklaus/brother_ql/blob/56cf4394ad750346c6b664821ccd7489ec140dae/brother_ql/conversion.py#L175-L187 You might try to use

convert(qlr, images, **kwargs)qlr.cut_at_end = Trueqlr.add_expanded_mode()instructions = qlr.data

but I have not tested it and this probably will not actually work.

— Reply to this email directly, view it on GitHub https://github.com/pklaus/brother_ql/issues/150#issuecomment-1974744742, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACIUWJS7Y27TKQ5TFHXCE3YWGLONAVCNFSM6AAAAABEC6AQA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZUG42DINZUGI . You are receiving this because you authored the thread.Message ID: @.***>

-- __O____ -\<,____ ____()/()___


@.***>__604-518-1749(m)604-461-7532(h)

FriedrichFroebel commented 8 months ago

Then you might want to create your custom raster class:

class CutAtEndRaster(BrotherQLRaster):
    def add_expanded_mode(self):
        self.cut_at_end = True
        return super().add_expanded_mode()

qlr = CutAtEndRaster(model)
instructions = convert(qlr, images, **kwargs)
send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)
stuartlynne commented 8 months ago

That gets a cut after each label.

On Sun, Mar 3, 2024 at 9:56 AM FriedrichFroebel @.***> wrote:

Then you might want to create your custom raster class:

class CutAtEndRaster(BrotherQLRaster): def add_expanded_mode(self): self.cut_at_end = True super().add_expanded_mode()

qlr = CutAtEndRaster(model)instructions = convert(qlr, images, **kwargs)send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)

— Reply to this email directly, view it on GitHub https://github.com/pklaus/brother_ql/issues/150#issuecomment-1975244987, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACIUWLRIGSQYF7AJ6UW5ZTYWNP55AVCNFSM6AAAAABEC6AQA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZVGI2DIOJYG4 . You are receiving this because you authored the thread.Message ID: @.***>

-- __O____ -\<,____ ____()/()___


@.***>__604-518-1749(m)604-461-7532(h)

FriedrichFroebel commented 8 months ago

Did you set cut=False for this? Then you are only left with doing the same as in my previous comment with add_cut_every(n) and setting n to the number of pages you have while enabling cut=True as far as I understand.

stuartlynne commented 8 months ago

This is cuts every label if 'cut' is True, or no cuts if False

┆ kwargs = { 'rotate': '90', 'cut': True, 'label': labelsize, } ┆ qlr = BrotherQLRaster(model) ┆ convert(qlr, images, **kwargs) ┆ qlr.add_cut_every(2) ┆ instructions = qlr.data ┆ send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)

This was the previous. Again with 'cut' False no cuts, 'cut' True cuts after each label.

┆ kwargs = { 'rotate': '90', 'cut': False, 'label': labelsize, } ┆ class CutAtEndRaster(BrotherQLRaster): ┆ def add_expanded_mode(self): ┆ self.cut_at_end = True ┆ super().add_expanded_mode() ┆ qlr = CutAtEndRaster(model) ┆ convert(qlr, images, **kwargs) ┆ qlr.add_expanded_mode() ┆ instructions = qlr.data ┆ send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)

On Sun, Mar 3, 2024 at 11:57 AM FriedrichFroebel @.***> wrote:

Did you set cut=False for this? Then you are only left with doing the same as in my previous comment with add_cut_every(n) and setting n to the number of pages you have.

— Reply to this email directly, view it on GitHub https://github.com/pklaus/brother_ql/issues/150#issuecomment-1975279403, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACIUWPTZY234ARZAY5EGW3YWN6CNAVCNFSM6AAAAABEC6AQA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZVGI3TSNBQGM . You are receiving this because you authored the thread.Message ID: @.***>

-- __O____ -\<,____ ____()/()___


@.***>__604-518-1749(m)604-461-7532(h)

FriedrichFroebel commented 8 months ago
convert(qlr, images, **kwargs)
qlr.add_cut_every(2)

is wrong. You need a custom BrotherQLRaster class which overrides add_cut_every with your custom logic and cut=True set, as convert does not allow you to pass these parameters directly.

stuartlynne commented 8 months ago

I thought something like this would work, but still get cuts after every label:

┆ kwargs = { 'rotate': '90', 'cut': False, 'label': labelsize, } ┆ class CutAtEndRaster(BrotherQLRaster): ┆ def init(self, model, pages): ┆ self.pages = pages ┆ self.page_count = 0 ┆ print('pages: %s' % (pages), file=sys.stderr) ┆ super(CutAtEndRaster, self).init(model) ┆

┆ def add_autocut(self, flag):

┆ self.page_count += 1 ┆ print('add_autocut: flag: %s page_count: %s' % (flag, self.page_count), file=sys.stderr) ┆ if self.page_count == self.pages: ┆ print('add_autocut: calling super', file=sys.stderr)

┆ super(CutAtEndRaster, self).add_autocut(flag)

┆ ┆ def add_cut_every(self, n): ┆ print('add_cut_every: n: %s overide: %s' % (n, self.pages), file=sys.stderr) ┆ if self.page_count == self.pages:

┆ print('add_autocut: calling super', file=sys.stderr)

┆ super(CutAtEndRaster, self).add_cut_every(self.pages) ┆ ┆ qlr = CutAtEndRaster(model, len(images)) ┆ convert(qlr, images, **kwargs) ┆ instructions = qlr.data ┆ send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)

On Mon, Mar 4, 2024 at 3:15 AM FriedrichFroebel @.***> wrote:

convert(qlr, images, **kwargs) qlr.add_cut_every(2)

is wrong. You need a custom BrotherQLRaster class which overrides add_cut_every with your custom logic and cut=True set, as convert misses these parameters.

— Reply to this email directly, view it on GitHub https://github.com/pklaus/brother_ql/issues/150#issuecomment-1976347030, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACIUWJ4C5A24XUS77GR6QTYWRJV3AVCNFSM6AAAAABEC6AQA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZWGM2DOMBTGA . You are receiving this because you authored the thread.Message ID: @.***>

-- __O____ -\<,____ ____()/()___


@.***>__604-518-1749(m)604-461-7532(h)