@@ -25,6 +25,7 @@ type PrintJobOptions struct {
2525 PrintScaling string // "auto" | "auto-fit" | "fit" | "fill" | "none"
2626 PageRange string // e.g. "1-5 8 10-12"
2727 Mirror bool // mirror / horizontal flip
28+ Pages int // total document pages (for job-impressions hint)
2829}
2930
3031// SendPrintJob sends data to the printer via IPP using goipp to build the
@@ -71,12 +72,11 @@ func SendPrintJob(printerURI string, r io.Reader, mime string, username string,
7172 }
7273 req .Job .Add (goipp .MakeAttribute ("copies" , goipp .TagInteger , goipp .Integer (copies )))
7374
74- // Orientation
75- switch opts .Orientation {
76- case "landscape" :
75+ // Orientation – only override when landscape; portrait is the CUPS default
76+ // and explicitly sending orientation-requested=3 may cause pdftopdf to
77+ // re-process the document, leading to an inflated page count in CUPS.
78+ if opts .Orientation == "landscape" {
7779 req .Job .Add (goipp .MakeAttribute ("orientation-requested" , goipp .TagEnum , goipp .Integer (4 )))
78- default :
79- req .Job .Add (goipp .MakeAttribute ("orientation-requested" , goipp .TagEnum , goipp .Integer (3 )))
8080 }
8181
8282 // Paper size (media)
@@ -117,6 +117,17 @@ func SendPrintJob(printerURI string, r io.Reader, mime string, username string,
117117 req .Job .Add (goipp .MakeAttribute ("mirror" , goipp .TagBoolean , goipp .Boolean (true )))
118118 }
119119
120+ // Job impressions hint – tells CUPS the expected page count so that its
121+ // job-accounting display matches the actual document instead of relying
122+ // on the filter-reported count (which may be off by one).
123+ if opts .Pages > 0 {
124+ impressions := opts .Pages
125+ if copies > 1 {
126+ impressions = opts .Pages * copies
127+ }
128+ req .Job .Add (goipp .MakeAttribute ("job-impressions" , goipp .TagInteger , goipp .Integer (impressions )))
129+ }
130+
120131 payload , err := req .EncodeBytes ()
121132 if err != nil {
122133 return "" , fmt .Errorf ("encode ipp request: %w" , err )
0 commit comments