OpenPrinting / cups-filters

filters, backends, driverless utility, ... - Everything which CUPS 2.x needs to be used on non-Mac systems
Apache License 2.0
157 stars 125 forks source link

Can't set margins in texttopdf 2.0.0? #577

Open Strahinja opened 6 months ago

Strahinja commented 6 months ago

Describe the bug texttopdf from cups-filters 2.0.0 (version used in the OpenBSD package cups-filters) doesn't seem to respect the page-* option(s).

To Reproduce Steps to reproduce the behavior:

1.

/usr/local/libexec/cups/filter/texttopdf 1 user title 1 'media=A4 page-left=56' \
/etc/passwd > p.pdf

2.

/usr/local/libexec/cups/filter/texttopdf 1 user title 1 'media=A4' /etc/passwd > p2.pdf
  1. Open both files: p.pdf, and p2.pdf in a PDF viewer.
  2. See error - left margin is the same in both files.

Expected behavior Left margin should be increased to about 2cm in the file p.pdf (generated with the option page-left=56).

Screenshots 2024-03-04-194832-dwm

System Information:

Additional context For example, Alpine Linux has cups-filters 1.28.17 fixed as the last upstream release they use for building the cups-filters package. With that version of cups-filters, the command

/usr/lib/cups/filter/texttopdf 1 user title 1 'page-left=56' /etc/passwd > p.pdf

produces a PDF file with the left margin set to about 2cm. A similar command in OpenBSD:

/usr/local/libexec/cups/filter/texttopdf 1 user title 1 'page-left=56' /etc/passwd > p.pdf

complains:

DEBUG: Color space requested: Default
DEBUG: Final output format: CUPS Raster
WARN: Could not determine the output page dimensions, falling back to US Letter format
WARN: cfFilterPDFToPDF: Could not determine the width of the left margin, falling back to 18 pt/6.35 mm
WARN: cfFilterPDFToPDF: Could not determine the width of the bottom margin, falling back to 36 pt/12.7 mm
WARN: cfFilterPDFToPDF: Could not determine the width of the right margin, falling back to 18 pt/6.35 mm
WARN: cfFilterPDFToPDF: Could not determine the width of the top margin, falling back to 36 pt/12.7 mm

when given the additional parameter of media=A4 (A has to be uppercase, unlike with 1.28.17!):

/usr/local/libexec/cups/filter/texttopdf 1 user title 1 'media=A4 page-left=56' \
/etc/passwd > p.pdf

the output is reduced to

DEBUG: Color space requested: Default
DEBUG: Final output format: CUPS Raster

and there is no difference in the generated PDF from

/usr/local/libexec/cups/filter/texttopdf 1 user title 1 'media=A4' /etc/passwd > p2.pdf
RudraIIT commented 6 months ago

Please attach the ppd file which should be available in /etc/cups/ppd

Strahinja commented 6 months ago

Please attach the ppd file which should be available in /etc/cups/ppd

With these packages installed:

$ pkg_info -A | grep cups
cups-2.4.7p0        Common Unix Printing System
cups-browsed-2.0.0  browse network for remote CUPS queues and IPP printers
cups-filters-2.0.0p0 OpenPrinting CUPS filters
cups-libs-2.4.7     CUPS libraries and headers
cups-pdf-3.0.1p1    PDF backend for CUPS
gtk+3-cups-3.24.38  gtk+3 CUPS print backend
libcupsfilters-2.0.0p0 library for developing printing filters

on OpenBSD-release 7.4 I have:

$ ls -l /etc/cups/ppd/
total 0
$ ls -ld /etc/cups/ppd/
drwxr-xr-x  2 root  _cups  512 Mar 22 17:06 /etc/cups/ppd//
$

FYI, this doesn't seem to be system-related. I have tried the example from the OP in up-to-date Artix Linux (having the latest CUPS), with the same results as in OpenBSD: page-left has no effect, I get the same warnings and the directory /etc/cups/ppd is empty.

Strahinja commented 6 months ago

In previous versions of CUPS, the texttopdf filter worked without setting up a printer. Still, to test if this is related to adding a printer, I added a "Generic CUPS-PDF Printer (w/ options)" as "Virtual_PDFPrinter", changed its default paper size to A4 and set it up as "server default" in the cups web interface. This created the file /etc/cups/ppd/Virtual_PDFPrinter.ppd (zipped here, as Github doesn't accept .ppd files: Virtual_PDF_Printer.zip). With that, I have (I wrapped the output for readability):

$ doas rcctl start cupsd
cupsd(ok)
$ rcctl check cupsd
cupsd(ok)
$ lpq
Virtual_PDF_Printer is ready
no entries
$ lpoptions
copies=1 device-uri=cups-pdf:/ finishings=3 job-cancel-after=10800 job-hold-until=no-hold
job-priority=50 job-sheets=none,none marker-change-time=0 number-up=1 print-color-mode=color
printer-commands=AutoConfigure,Clean,PrintSelfTestPage printer-info='Virtual PDF Printer'
printer-is-accepting-jobs=true printer-is-shared=false printer-is-temporary=false
printer-location printer-make-and-model='Generic CUPS-PDF Printer (w/ options)'
printer-state=3 printer-state-change-time=1711277143 printer-state-reasons=none
printer-type=10678348 printer-uri-supported=ipp://localhost/printers/Virtual_PDF_Printer
$ lpoptions -l
PageSize/Page Size: Custom.WIDTHxHEIGHT 11x14 11x17 13x19 16x20 16x24 2A 4A 8x10 8x12 A0
A1 A2 A3 *A4 A5 AnsiA AnsiB AnsiC AnsiD AnsiE ArchA ArchB ArchC ArchD ArchE C0 C1 C2 C3 C4
C5 Env10 EnvC5 EnvDL EnvMonarch Executive ISOB0 ISOB1 ISOB2 ISOB3 ISOB4 ISOB5 JISB0 JISB1
JISB2 JISB3 JISB4 JISB5 Ledger Legal Letter RA0 RA1 RA2 RA3 RA4 SRA0 SRA1 SRA2 SRA3 SRA4
SuperA SuperB TabloidExtra Tabloid Resolution/Output Resolution: 150dpi *300dpi 600dpi
1200dpi 2400dpi
PDFVer/PDF version: 1.1 *1.2 1.3 1.4 1.5
Truncate/Truncate output filename to: 8 16 32 *64
Label/Label outputfiles: 0 1 *2
TitlePref/Prefer title from: *0 1
LogType/Log level: 1 3 *7
$ /usr/local/libexec/cups/filter/texttopdf 1 user title 1 'page-left=56' /etc/cups/cups-browsed.conf > p2.pdf
DEBUG: Color space requested: Default
DEBUG: Final output format: CUPS Raster
WARN: Could not determine the output page dimensions, falling back to US Letter format
WARN: cfFilterPDFToPDF: Could not determine the width of the left margin, falling back to 18 pt/6.35 mm
WARN: cfFilterPDFToPDF: Could not determine the width of the bottom margin, falling back to 36 pt/12.7 mm
WARN: cfFilterPDFToPDF: Could not determine the width of the right margin, falling back to 18 pt/6.35 mm
WARN: cfFilterPDFToPDF: Could not determine the width of the top margin, falling back to 36 pt/12.7 mm
$

However, this didn't change anything - the resulting PDF file p2.pdf still doesn't have the desired margin.