attah / harbour-seaprint

🐟🖨 Network printing for Sailfish OS
GNU General Public License v3.0
16 stars 20 forks source link

Add option to set paper size #26

Closed piggz closed 4 years ago

piggz commented 4 years ago

When printing a photo, it is necessary to set a paper size other than A4. I was able to print a picture on my Canon MG5700, and I loaded it with 5x7 photo paper, but when printed, the printer insisted I loaded A4.

attah commented 4 years ago

I just need to make a translation table so the names get more human-friendly, and this should be ready. Current architecture made it a ~2-line addition, not counting the table.

attah commented 4 years ago

How about this: f063b57fdf5ed948b64e64d6bf49bbba5c095252 ?

piggz commented 4 years ago

Tried to print on a 5x7, but got this error and no print [W] unknown:18 - file:///usr/share/harbour-seaprint/qml/pages/PrinterPage.qml:18: TypeError: Cannot read property 'value' of undefined

attah commented 4 years ago

I'm afraid that the jpeg support may have been a bit of an overstatement. Some printers happily accept arbitrary jpegs, but some only see it only as a means for compressing exactly sized pages. Seems i need to add raster format support and handle converting images to those instead for a more consistent experience. (jpeg-to-jpeg conversions is probably less than optimal)

I don't think that is an actual error, just my ineptitude at checking for presence of values in qml objects. If you got an banner with an error in the app, it worked as intended.

piggz commented 4 years ago

No, i dont think a banner happened. Because of the error on that line I dont think the lines after execute.

attah commented 4 years ago

This should help 27cc5a38e575fff42c03c74828d6ebf22c277ab6 QML is certainly not my day job...

attah commented 4 years ago

This option is withheld for the time being, until i can be more sure it does something meaningful. I.e. pdfs will likely be limited to A4, letter and maybe A3. For Images i could in theory implement conversion to any format, it is just a matter of having the application know how big they are. I'm likely going to be removing sending raw jpegs to printers when conversions are in place.

attah commented 4 years ago

Now image printing is backed up by a resize to the selected paper size, please try it out :) 2da5baad591c48f5cb086e646d192b71ed30c4cc

piggz commented 4 years ago

Hi, can you add bytestream.h to the repository so i can build. ta

attah commented 4 years ago

I think a git submodule update --init --recursive should do the trick. Bytestream was already a submodule dependency of ppm2pwg, which is now submodule'd in, so i stopped keeping a copy for SeaPrint, and use that on instead.

piggz commented 4 years ago

Ok, got past that, but still had to add

include

include

to convertworker.cpp

piggz commented 4 years ago

Tried to print a 5x7 photo and got print failed. This was the log, happy to supply any more info as required https://paste.mozilla.org/TAD9jEcv

attah commented 4 years ago

Hmm, i must have messed up the size calculation with imperial/US customary units... See you on IRC?

attah commented 4 years ago

For the benefit of others reading this. The size snafu is fixed, but the printer still doesn't like it. Printing to a test printer yields a file with seemingly correct contents.

piggz commented 4 years ago

Tried the latest code.

Printer: Canon MG5700 Page size: 5x7 Selecting JPEG fails instantly Selecting URF or PWG spends time transferring the file, but fails at the end. Page Size: A4 JPEG: Fails with unsupported format URF: Printed ok ... got to 18%, and printer told me to change paper to A4 (still had 5x7 in) and then continued printing/transferring

piggz commented 4 years ago

I did some debugging using ipptool and reading the ipp specs.

From what i understand, seaprint current;y issues IPP v1.1 commands. Using ipptool, i was able to recreate the error im having with the following ipp command file:

This is a comment

{

The name of the test

  NAME "Print JPG File"
  VERSION 1.1

  # The request to send
  OPERATION Print-Job

  GROUP operation-attributes-tag
  ATTR charset attributes-charset utf-8
  ATTR language attributes-natural-language en
  ATTR uri printer-uri ipp://192.168.5.244/ipp/print
  ATTR name requesting-user-name piggz
  ATTR mimeMediaType document-format image/jpeg

  GROUP job-attributes-tag
  ATTR keyword media na_5x7_5x7in

  FILE test.jpg

  # The response to expect
  STATUS successful-ok
  EXPECT job-id OF-TYPE integer WITH-VALUE >0
  EXPECT job-uri OF-TYPE uri
}
{
  # The name of the test
  NAME "Wait for Job to Complete"

  # The request to send
  OPERATION Get-Job-Attributes

  GROUP operation-attributes-tag
  ATTR charset attributes-charset utf-8
  ATTR language attributes-natural-language en
  ATTR uri printer-uri $uri
  ATTR integer job-id $job-id
  ATTR name requesting-user-name $user

  # The response to expect
  STATUS successful-ok
  EXPECT job-id OF-TYPE integer WITH-VALUE $job-id
  EXPECT job-uri OF-TYPE uri
  EXPECT job-state OF-TYPE enum WITH-VALUE >5 REPEAT-NO-MATCH
  EXPECT job-originating-user-name OF-TYPE name WITH-VALUE "$user"

  # Show the job state until completed...
  DISPLAY job-state
  DISPLAY job-state-reasons
}

By using an IPP v2.0 style file, and the media-col property, i was able to print a jpeg to 5x7 without any conversions, the media-col property uses sizes of 2540 per inch.

This is a comment

{

The name of the test

  NAME "Print JPG File"
  VERSION 2.0

  # The request to send
  OPERATION Print-Job

  GROUP operation-attributes-tag
  ATTR charset attributes-charset utf-8
  ATTR language attributes-natural-language en
  ATTR uri printer-uri ipp://192.168.5.244/ipp/print
  ATTR name requesting-user-name piggz
  ATTR mimeMediaType document-format image/jpeg

  GROUP job-attributes-tag
  ATTR collection media-col {
    MEMBER collection media-size {
        # 4x6
        MEMBER integer x-dimension 12700
        MEMBER integer y-dimension 17780
    }
}

  FILE test.jpg

  # The response to expect
  STATUS successful-ok
  EXPECT job-id OF-TYPE integer WITH-VALUE >0
  EXPECT job-uri OF-TYPE uri
}
{
  # The name of the test
  NAME "Wait for Job to Complete"

  # The request to send
  OPERATION Get-Job-Attributes

  GROUP operation-attributes-tag
  ATTR charset attributes-charset utf-8
  ATTR language attributes-natural-language en
  ATTR uri printer-uri $uri
  ATTR integer job-id $job-id
  ATTR name requesting-user-name $user

  # The response to expect
  STATUS successful-ok
  EXPECT job-id OF-TYPE integer WITH-VALUE $job-id
  EXPECT job-uri OF-TYPE uri
  EXPECT job-state OF-TYPE enum WITH-VALUE >5 REPEAT-NO-MATCH
  EXPECT job-originating-user-name OF-TYPE name WITH-VALUE "$user"

  # Show the job state until completed...
  DISPLAY job-state
  DISPLAY job-state-reasons
}
piggz commented 4 years ago

I think to implement this in seaprint would (just) require changing the version numbers to 2.0, and adding support for the collection type to the encoder?

attah commented 4 years ago

I will look in to it. The big question is how to hook this human-unfriendly attribute to the gui. The app should indeed report IPP 2.0, at least whenever possible.

Have you tried with both media and media-col together? If that works, maybe media-col can just follow media and not need to be exposed to the user...

piggz commented 4 years ago

Yes, the following works: GROUP job-attributes-tag ATTR keyword media na_5x7_5x7in ATTR collection media-col { MEMBER collection media-size {

4x6

        MEMBER integer x-dimension 12700
        MEMBER integer y-dimension 17780
    }
}

but without the media-col collection, the printer returns Internal error.(BeginPrintJob)

So yes, i think it woud be a case of adding the collection property, and hiding it from the user, and populating it from the media size chosen

piggz commented 4 years ago

ignore the 4x6 comment, those values are 5x7 :)

attah commented 4 years ago

I needed to clean out some cruft first, to avoid accumulating too much technical debt, but now i got around to doing something about encoding collections. Seems to work for your use-case, can you please review/confirm?

Next will be adding these attributes based on user input... for which i don't really have any ideas (apart from the obvious relaying of page sizes in media-col too where supported). Ideas?

piggz commented 4 years ago

I would at least include an option to set a single margin value, which sets all the media*-margin attributes. This would allow borderless printing.

piggz commented 4 years ago

Ive tested by manually adding the appropriate attributes for paper-size/margin against your collection encoding and it worked fine. JSON was this https://github.com/attah/harbour-seaprint/compare/master...piggz:test-collection?expand=1#diff-867d093568214e0f19dbbf286e4682dcR407

attah commented 4 years ago

I would still need to model such settings based on allowed values... That helps with only including it if supported, if nothing else. I'll experiment with a custom setting component that deals with margins, so that it can keep within the current architecture.

piggz commented 4 years ago

I tested the latest code, but on printing, i was left with a screen that said "Loading" with a busy control

Log was: [D] unknown:0 - QNetworkReply::NetworkError(NoError) "Unknown error" "" [D] unknown:0 - 0 QJsonObject({"attributes-charset":{"tag":71,"value":"utf-8"},"attributes-natural-language":{"tag":72,"value":"en-us"}}) QJsonObject({"charset-configured":{"tag":71,"value":"us-ascii"},"charset-supported":{"tag":71,"value":["us-ascii","utf-8"]},"color-supported":{"tag":34,"value":true},"compression-supported":{"tag":68,"value":["none"]},"copies-default":{"tag":33,"value":1},"copies-supported":{"tag":51,"value":{"high":99,"low":1}},"document-format-default":{"tag":73,"value":"application/octet-stream"},"document-format-supported":{"tag":73,"value":["application/octet-stream","image/jpeg","image/urf","image/pwg-raster"]},"finishings-default":{"tag":35,"value":3},"finishings-supported":{"tag":35,"value":[3]},"generated-natural-language-supported":{"tag":72,"value":["en-us"]},"identify-actions-default":{"tag":68,"value":"flash"},"identify-actions-supported":{"tag":68,"value":["flash"]},"ipp-features-supported":{"tag":68,"value":["airprint-1.4"]},"ipp-versions-supported":{"tag":68,"value":["1.1","2.0"]},"job-creation-attributes-supported":{"tag":68,"value":["copies","finishings","sides","orientation-requested","media","print-quality","printer-resolution","output-bin","media-col","print-color-mode","ipp-attribute-fidelity","job-name"]},"jpeg-k-octets-supported":{"tag":51,"value":{"high":12288,"low":0}},"jpeg-x-dimension-supported":{"tag":51,"value":{"high":19200,"low":16}},"jpeg-y-dimension-supported":{"tag":51,"value":{"high":19200,"low":16}},"landscape-orientation-requested-preferred":{"tag":35,"value":5},"marker-colors":{"tag":66,"value":["#D945DD","#2C2C2C","#DFD31D","#101010","#39D2E7"]},"marker-high-levels":{"tag":33,"value":[100,100,100,100,100]},"marker-levels":{"tag":33,"value":[90,20,90,50,90]},"marker-low-levels":{"tag":33,"value":[15,15,15,15,15]},"marker-names":{"tag":66,"value":["Magenta","Black(BK)","Yellow","Black(PGBK)","Cyan"]},"marker-types":{"tag":68,"value":["inkCartridge","inkCartridge","inkCartridge","inkCartridge","inkCartridge"]},"media-bottom-margin-supported":{"tag":33,"value":[500,0,3250]},"media-col-supported":{"tag":68,"value":["media-bottom-margin","media-left-margin","media-right-margin","media-size","media-source","media-top-margin","media-type"]},"media-default":{"tag":68,"value":"iso_a4_210x297mm"},"media-left-margin-supported":{"tag":33,"value":[340,0,640,560]},"media-ready":{"tag":68,"value":"iso_a4_210x297mm"},"media-right-margin-supported":{"tag":33,"value":[340,0,630,560]},"media-source-supported":{"tag":68,"value":["auto","main"]},"media-supported":{"tag":68,"value":["iso_a5_148x210mm","iso_a4_210x297mm","jis_b5_182x257mm","na_letter_8.5x11in","na_legal_8.5x14in","jpn_hagaki_100x148mm","na_number-10_4.125x9.5in","iso_dl_110x220mm","oe_photo-l_3.5x5in","na_index-4x6_4x6in","na_5x7_5x7in","na_govt-letter_8x10in","custom_min_88.9x127mm","custom_max_215.9x355.6mm"]},"media-top-margin-supported":{"tag":33,"value":[500,0,800]},"media-type-supported":{"tag":68,"value":["stationery","photographic","envelope"]},"multiple-document-jobs-supported":{"tag":34,"value":false},"multiple-operation-time-out":{"tag":33,"value":60},"natural-language-configured":{"tag":72,"value":"en-us"},"operations-supported":{"tag":35,"value":[2,4,5,6,8,9,10,11,60]},"orientation-requested-default":{"tag":35,"value":3},"orientation-requested-supported":{"tag":35,"value":[3]},"output-bin-default":{"tag":68,"value":"face-up"},"output-bin-supported":{"tag":68,"value":["face-up"]},"output-mode-default":{"tag":68,"value":"color"},"output-mode-supported":{"tag":68,"value":["color","monochrome","auto","auto-monochrome"]},"page-ranges-supported":{"tag":34,"value":false},"pages-per-minute":{"tag":33,"value":10},"pages-per-minute-color":{"tag":33,"value":6},"pdf-versions-supported":{"tag":68,"value":["none"]},"pdl-override-supported":{"tag":68,"value":["attempted"]},"print-color-mode-default":{"tag":68,"value":"color"},"print-color-mode-supported":{"tag":68,"value":["color","monochrome","auto","auto-monochrome"]},"print-content-optimize-default":{"tag":68,"value":"auto"},"print-content-optimize-supported":{"tag":68,"value":["auto"]},"print-quality-default":{"tag":35,"value":4},"print-quality-supported":{"tag":35,"value":[4,5]},"print-scaling-default":{"tag":68,"value":"auto"},"print-scaling-supported":{"tag":68,"value":["none","fill","fit","auto-fit","auto"]},"printer-device-id":{"tag":65,"value":"MFG:Canon;CMD:BJL,BJRaster3,BSCCe,NCCe,IVEC,IVECPLI,URF;SOJ:BJNP2,BJNPe;MDL:MG5700 series;CLS:PRINTER;DES:Canon MG5700 series;VER:2.050;STA:10;FSI:00;HRI:D;MSI:AOFF,B240,DAT,E3,HFSF,JOFF,K21000700,LOFF;PDR:4;PSE:KMBM38879;CID:CA_IVEC1TYPE4_IJP;URF:V1.4,CP1,PQ4-5,RS600,SRGB24,W8,OB9,OFU0,DM3,IS1;"},"printer-dns-sd-name":{"tag":66,"value":"Canon MG5700 series"},"printer-firmware-name":{"tag":66,"value":"IPP"},"printer-firmware-string-version":{"tag":65,"value":"2.0"},"printer-firmware-version":{"tag":48,"value":"\u0002"},"printer-geo-location":{"tag":69,"value":"geo:0.00000,0.00000,0"},"printer-icons":{"tag":69,"value":["http://192.168.5.244/icon/printer_icon.png","http://192.168.5.244/icon/printer_icon_large.png"]},"printer-info":{"tag":65,"value":"Canon MG5700 series"},"printer-input-tray":{"tag":48,"value":["type=other;mediafeed=-2;mediaxfeed=-2;maxcapacity=-2;level=-2;status=5;name=auto;","type=sheetFeedAutoRemovableTray;mediafeed=-2;mediaxfeed=-2;maxcapacity=-2;level=-2;status=5;name=main;"]},"printer-is-accepting-jobs":{"tag":34,"value":true},"printer-kind":{"tag":68,"value":["document","envelope","photo"]},"printer-location":{"tag":65,"value":""},"printer-make-and-model":{"tag":65,"value":"Canon MG5700 series"},"printer-more-info":{"tag":69,"value":"http://192.168.5.244/index.html?page=PAGE_AAP"},"printer-name":{"tag":66,"value":"MG5700 series"},"printer-output-tray":{"tag":48,"value":"type=unRemovableBin;maxcapacity=-2;remaining=-2;status=5;name=face-up;stackingorder=lastToFirst;pagedelivery=faceUp;"},"printer-resolution-default":{"tag":50,"value":{"units":3,"x":600,"y":600}},"printer-resolution-supported":{"tag":50,"value":[{"units":3,"x":600,"y":600}]},"printer-state":{"tag":35,"value":3},"printer-state-reasons":{"tag":68,"value":"none"},"printer-supply-info-uri":{"tag":69,"value":"http://192.168.5.244/index.html?page=PAGE_INK"},"printer-up-time":{"tag":33,"value":6075822},"printer-uri-supported":{"tag":69,"value":["ipp://192.168.5.244/ipp/print"]},"printer-uuid":{"tag":69,"value":"urn:uuid:00000000-0000-1000-8000-7438B77780F8"},"pwg-raster-document-resolution-supported":{"tag":50,"value":[{"units":3,"x":600,"y":600}]},"pwg-raster-document-sheet-back":{"tag":68,"value":"rotated"},"pwg-raster-document-type-supported":{"tag":68,"value":["srgb_8","sgray_8"]},"queued-job-count":{"tag":33,"value":0},"sides-default":{"tag":68,"value":"one-sided"},"sides-supported":{"tag":68,"value":["one-sided","two-sided-long-edge","two-sided-short-edge"]},"urf-supported":{"tag":68,"value":["V1.4","CP1","PQ4-5","RS600","SRGB24","W8","OB9","OFU0","DM3","IS1"]},"uri-authentication-supported":{"tag":68,"value":["none"]},"uri-security-supported":{"tag":68,"value":["tls"]}}) [D] unknown:0 - additionalDocumentFormats () [W] unknown:0 - QQmlExpression: Expression file:///usr/share/harbour-seaprint/qml/pages/FirstPage.qml:122:41 depends on non-NOTIFYable properties: [W] unknown:0 - ConvertChecker::pdf [W] unknown:0 - QQmlExpression: Expression file:///usr/share/harbour-seaprint/qml/pages/FirstPage.qml:237:35 depends on non-NOTIFYable properties: [W] unknown:0 - ConvertChecker::pdf [D] servicesChanged:23 - services changed [D] go:28 - go! [D] servicesChanged:23 - services changed [D] go:28 - go! [D] :85 - choice changed 68 "na_5x7_5x7in" [D] :94 - {"media":{"tag":68,"value":"na_5x7_5x7in"}} [D] :85 - choice changed 68 "auto" [D] :94 - {"media":{"tag":68,"value":"na_5x7_5x7in"},"media-source":{"tag":68,"value":"auto"}} [D] onClicked:26 - {"media":{"tag":68,"value":"na_5x7_5x7in"},"media-source":{"tag":68,"value":"auto"}} [W] unknown:32 - file:///usr/share/harbour-seaprint/qml/pages/BusyPage.qml:32: TypeError: Cannot read property 'busyMessage' of null [W] unknown:29 - file:///usr/share/harbour-seaprint/qml/pages/PrinterPage.qml:29: TypeError: Cannot call method 'print' of null

attah commented 4 years ago

That's super weird, and not obviously related. The printer object itself seems to have gone missing, which should have happened for me too. Is it reproducible?

piggz commented 4 years ago

Ah, ok, it worked when i tried again....i probably dropped off the wifi, and it was getting late so i never retried ...

So, the current code still isnt sending the paper size in media-col, so my prints still fail with unknown error.

attah commented 4 years ago

Ah, sorry, i wasn't clear... it only sends paper size in media-col if there is already something in media-col, and thus using media would be invalid. I.e. if you set zero margins, you should have it.

I guess i should throw in a global setting to move it unconditionally too.

piggz commented 4 years ago

Just tested 0.5.2 built from source and it worked really well. I was able to print a borderless photo, sent as a jpeg to 5x7 ... I did the same print as previously which had one white edge, and it printed without the edge

attah commented 4 years ago

Great to hear, hope that sorts it for most people.

piggz commented 4 years ago

abranson is still having issues with his epson i believe, though it does now get closer to printing after I talked him through setting the media-col option.

Perhaps a debugging guide using ipptool would be useful, to determin the settings required for a printer?

attah commented 4 years ago

Alright... I'll be happy to reopen with some input. Right, yes it would. However i'm not so sure i'd know what to put in the guide to help finding what settings to use. What tipped you off?

All i have to offer is really that the built-in command file works for me like so: ipptool -tv -f Downloads/1.pdf ipp://192.168.1.192/ipp/print printjob.ipp

And this gets you started writing your own files. https://istopwg.github.io/ipp/ippguide.html

piggz commented 4 years ago

Yeah, maybe just point people to that, and get them to submit a minimum ipp file which fixes the problem, then you know what needs to be set.

piggz commented 4 years ago

What tipped me off was experimenting with the test files from cups, and seeing what attributes they set ... when it worked with media-col, i then started hacking the file to the basics that were required.