Evidlo / remarkable_printer

Native printing to reMarkable.
GNU General Public License v3.0
257 stars 21 forks source link

Filename is always "Printed" on reMarkable #27

Closed gavinmcc closed 2 years ago

gavinmcc commented 3 years ago

I got my first reMarkable recently and started with 2.6.1.71. After hacking around the problem described in #23 which resulted in an empty file), I am still seeing an issue with the printed files always being called "Printed".

Looking at the code here:

https://github.com/Evidlo/remarkable_printer/blob/master/main.go#L130-L152

it looks like the correct filename should be taken from the contents of the jetdirect preamble "@PJL JOB NAME". However,

  1. I do see the "PDF begin" (indicating we are in debug mode)
  2. I never see the debug line "Setting title to:" which suggests we never set the title
  3. I never see any @PJL debug lines suggesting there are none (in debug mode, they would all be logged).
Mar 27 07:14:58 reMarkable printer.arm[2209]: Saving PDF to: /home/root/.local/share/remarkable/xochitl/f1a24f5d-8b0a-4fc6-abd6-8f5ab05fc691.pdf
Mar 27 07:14:58 reMarkable printer.arm[2209]: %PDF-1.3
Mar 27 07:14:58 reMarkable printer.arm[2209]: PDF begin
Mar 27 07:14:58 reMarkable printer.arm[2209]: Saving metadata to /home/root/.local/share/remarkable/xochitl/f1a24f5d-8b0a-4fc6-abd6-8f5ab05fc691.metadata
Mar 27 07:14:58 reMarkable printer.arm[2209]: Saving content file to /home/root/.local/share/remarkable/xochitl/f1a24f5d-8b0a-4fc6-abd6-8f5ab05fc691.content
Mar 27 07:14:58 reMarkable printer.arm[2209]: Restarting xochitl

My working theory is that the PJL statements are not being sent to the print service at all and that this must be some problem with either the PPV (I'm using the one in this package), the CUPS filter (on Mac Catalina 10.15.7) or how I have configured the printer.

gavinmcc commented 3 years ago

or how I have configured the printer.

I went back and used this to make sure I was using the standard Macbook setup:

38f9d35c0f7b:remarkable_printer gavinmc$ sudo make install_config
Password:
lpadmin: Printer drivers are deprecated and will stop working in a future version of CUPS.

No change.

gavinmcc commented 3 years ago

As an experiment, I added an extra PJL line to the start of a stock PDF file to make sure the Go code still does what we would expect, if the PJL is included in the payload:

38f9d35c0f7b:~ gavinmc$ head -5  Downloads/forgotten_side_dns_hacked.pdf 
@PJL JOB NAME = "Document Title!" <LF>
%PDF-1.5
%????
6 0 obj
<<
38f9d35c0f7b:~ gavinmc$ nc 10.11.99.1 9100 < Downloads/forgotten_side_dns_hacked.pdf 
38f9d35c0f7b:~ gavinmc$

Sure enough, we see it in the log and the file is titled "Document Title!" in the reMarkable UI.

Mar 28 05:09:42 reMarkable printer.arm[2209]: Saving PDF to: /home/root/.local/share/remarkable/xochitl/c94d476e-d51d-4bb3-837b-98cb6948ef21.pdf
Mar 28 05:09:42 reMarkable printer.arm[2209]: @PJL JOB NAME = "Document Title!" <LF>
Mar 28 05:09:42 reMarkable printer.arm[2209]: Setting title to: Document Title!
Mar 28 05:09:42 reMarkable printer.arm[2209]: %PDF-1.5
Mar 28 05:09:42 reMarkable printer.arm[2209]: PDF begin
Mar 28 05:09:42 reMarkable printer.arm[2209]: Saving metadata to /home/root/.local/share/remarkable/xochitl/c94d476e-d51d-4bb3-837b-98cb6948ef21.metadata
Mar 28 05:09:42 reMarkable printer.arm[2209]: Saving content file to /home/root/.local/share/remarkable/xochitl/c94d476e-d51d-4bb3-837b-98cb6948ef21.content
Mar 28 05:09:43 reMarkable printer.arm[2209]: Restarting xochitl
Evidlo commented 3 years ago

This should have been fixed in https://github.com/Evidlo/remarkable_printer/issues/21

Have you reinstalled the printer config since I made that update?

gavinmcc commented 3 years ago

Have you reinstalled the printer config since I made that update?

Yes, I only have my reMarkable a week :-)

Can you point me at the patch that solved this? Is it this one?

https://github.com/Evidlo/remarkable_printer/commit/8531bea5e3a096d0cd3d913fbd72e65ea3009f52#diff-1598b99604c92b737ea40d727f3c8c19301d3183c3dc18b1ae0ea012eab6b936

I don't see the string "PJL JOB NAME" anywhere in there. Should it be?

Evidlo commented 3 years ago

It seems to be a regression from https://github.com/Evidlo/remarkable_printer/pull/26. After replacing pdftopdf with -, I find that the @PJL JOB NAME line is not being sent.

You might try two things:

  1. delete the cupsFilter2 line. This worked on my Linux machine, but in the output I see this:

    ESC%-12345X@PJL
    @PJL JOB NAME = "NPR _ National Public Radio" DISPLAY = "155 evan NPR _ National Public R"
    @PJL SET USERNAME = "evan"
    ...
    % This file was generated by pdftopdf
    %%PDFTOPDFNumCopies : 1
    %%PDFTOPDFCollate : false
    1 0 obj
    << /Pages 3 0 R /Type /Catalog >>
    endobj
    2 0 obj
    ...

    So it seems like cups will use pdftopdf even though the cupsFilter line doesn't explicitly say so. Maybe CUPS is smart enough to automatically use cgpdftopdf on OSX?

  2. replace - with cgpdftopdf for the cupsFilter2 line like you had originally suggested. This change is not portable to Linux as you are probably aware.

If the first doesn't work on OSX but the second does, then we may want to symlink cgpdftopdf to pdftopdf in the install script.

Evidlo commented 3 years ago

Also something I found useful when debugging this ppd stuff was to use netcat to listen on port 9100 and change the printer IP to localhost.

[evan@blackbox ~] nc -l -p 9100 | head -n 20
-12345X@PJL
@PJL JOB NAME = "NPR _ National Public Radio" DISPLAY = "154 evan NPR _ National Public R"
@PJL SET USERNAME = "evan"
@PJL SET RENDERMODE=COLOR
@PJL SET DUPLEX=OFF
@PJL SET PAPER=LETTER
@PJL SET RESOLUTION=600
@PJL SET BORDERLESS=ON
@PJL SET EDGETOEDGE=YES
@PJL SET JOBOFFSET=ON
@PJL SET LOWSUPPLIES=CONTINUE
@PJL SET MANUALDUPLEX=OFF
@PJL SET MANUALFEED=OFF
@PJL SET OVERRIDEA4WITHLETTER=YES
@PJL SET RET=NOTSET
@PJL ENTER LANGUAGE = PDF
%PDF-1.4
%¿÷¢þ
% This file was generated by pdftopdf
%%PDFTOPDFNumCopies : 1
gavinmcc commented 3 years ago

It looks to me like the issue is that cgpdftopdf doesn't pass any PJL commands. That's been pretty consistently true with various things I have tried. Removing cupsFilter2 and directly passing cgpdftopdf doesn't seem to help.

I've been looking at hacking a wrapper script around cgpdftopdf which would add the extra lines PJL lines as an experiment.

38f9d35c0f7b:Downloads gavinmc$ nc -l 127.0.0.1 9100 | head -10
%PDF-1.3
%?????????
4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>
stream
gavinmcc commented 3 years ago

In case it triggers anything in your head, I've noted this "NO filtering is needed" output from cgpdftopdf when I run it.

DEBUG: Trying /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/en.lproj/cups_apple.strings
DEBUG: Message catalog filename is "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/en.lproj/cups_apple.strings".
DEBUG: cgpdftopdf - NO filtering is needed; passing data through.

This is the help output.

38f9d35c0f7b:~ gavinmc$ /usr/libexec/cups/filter/cgpdftopdf --help
DEBUG: Trying /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/en.lproj/cups_apple.strings
DEBUG: Message catalog filename is "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/en.lproj/cups_apple.strings".
Usage: /usr/libexec/cups/filter/cgpdftopdf job-id user title copies options [file]
Evidlo commented 3 years ago

This filter manually inserts the PJL line before the PDF content:

/usr/lib/cups/filter/rmfilter

#!/bin/bash
# send job name
echo -n "@PJL JOB NAME = "
echo "\"$3\""
# accept PDF as argument or from stdin
if [ -n "$6" ]
then
    cat "$6"
else
    cat
fi
Evidlo commented 3 years ago

There was an issue with the filter above, which I corrected. I created an rmfilter branch which should install the filter automatically along with a .ppd that is configured to use it. Can you try it out?

gavinmcc commented 3 years ago

This filter manually inserts the PJL line before the PDF content:

Yeah, hand-hacking that in works alright. I think in an ideal world, one would want to still use cgpdftopdf to do other transforms it might need to, something like this:

#!/bin/bash
# send job name
echo -n "@PJL JOB NAME = "
echo "\"$3\""
# accept PDF as argument or from stdin
if [ -n "$6" ]
then
    echo $(/usr/libexec/cups/filter/cgpdftopdf "$@")
else
    cat | /usr/libexec/cups/filter/cgpdftopdf "$@"
fi

This seems to work fine. I've only tested the second branch which uses the "cat".

Evidlo commented 3 years ago

xochitl uses pdfium which I think is much more featureful than a typical PDF printer, so I don't think pdftopdf or cgpdftopdf are going to do much here.

gavinmcc commented 3 years ago

Ah, fair enough then, I assumed it would be potentially reading options from position 4 in the CLI (which seems to allow N-UP etc):

Usage: /usr/libexec/cups/filter/cgpdftopdf job-id user title copies options [file]
gavinmcc commented 3 years ago

In the Makefile:

    sudo cp rmfilter /usr/lib/cups/filter

I think you need something like this to put the file in /usr/libexec/cups/filter on a Mac:

    sudo cp rmfilter $(cups-config --serverbin)/filter
Evidlo commented 3 years ago

Seems like cups-config isn't available on Linux. May need to check the distro to set the right install path.

gavinmcc commented 3 years ago

Seems like cups-config isn't available on Linux. May need to check the distro to set the right install path.

That's a pain. Seems it's part of the dev tools on Ubuntu (which nobody will have installed).

ubuntu@ip-172-31-9-203:~$ cups-config

Command 'cups-config' not found, but can be installed with:

sudo apt install libcups2-dev

There's a recipe based on "uname -s" here:

https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux

Evidlo commented 2 years ago

Is this still happening with the latest release?