Evidlo / remarkable_printer

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

What driver do you use on a Mac? #38

Closed kesmit13 closed 9 months ago

kesmit13 commented 1 year ago

I'm trying to follow the installation instructions and it sounds like you need a PDF driver in order to use this on a Mac, but I'm not sure how to get one. When adding a printer, the only options I get are Generic PostScript Printer, Generic PCL Printer, and AutoSelect. I tried the PostScript printer, but I get errors on the reMarkable. Do you have more detailed instructions for this setting on the Mac?

kesmit13 commented 1 year ago

I haven't found a PDF printer for MacOS and it's starting to look like they don't exist anymore. I have another idea which uses Folder Actions so that you can save a PDF from the print dialog to a specific folder and the Folder Action (written in Python) will write the contents of the file to the reMarkable socket. It does seem to work, but the content is not valid. I'm guessing that your code does not support the new reMarkable v3.0 metadata. Is that correct?


#!/usr/bin/python

from __future__ import print_function, unicode_literals

import os
import socket
import sys

HOST = '192.168.1.175'
PORT = 9100

for f in sys.argv[1:]:
    if not f.lower().endswith('.pdf'):
        continue
    s = None
    print(f)
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((HOST, PORT))

        title = os.path.splitext(os.path.basename(f))[0]
        title = title.replace('"', "'").encode('utf-8')
        s.send(b'@PJL JOB NAME "%s"\n' % title)

        with open(f, 'rb') as infile:
            s.sendall(infile.read())

    finally:
        if s is not None:
            os.remove(f)
            s.close()```
kesmit13 commented 1 year ago

Also, I noticed that the UI restarted once the document was uploaded. I'm guessing that's normal?

kesmit13 commented 1 year ago

With the latest release of remarkable_printer, the files are valid now. The above folder action will work to allow you to save a PDF document into a folder and have it automatically show up on the tablet. It would be nice if there was a PDF driver for Mac so this wasn't necessary, but I haven't found one.

kesmit13 commented 1 year ago

There is a way to create a printer plugin on Mac to get around the issue above with creating an extra folder. If you follow the instructions here, https://github.com/juruen/rmapi/blob/master/docs/tutorial-print-macosx.md#create-automator-script, but use the following Python script rather than their bash script. It works beautifully.

#!/usr/bin/python

import os
import re
import socket
import sys

HOST = '192.168.1.175'
PORT = 9100

for f in sys.argv[1:]:
    s = None

    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((HOST, PORT))

        try:
            title = os.path.splitext(os.path.basename(f))[0].replace('"', "'")
            title = re.sub(r'\.pdf\s*$', r'', title)
            s.send('@PJL JOB NAME "%s"\n' % title)

        except:
            pass

        with open(f, 'rb') as infile:
            s.sendall(infile.read())
            pass

    finally:
        if s is not None:
            s.close()
Evidlo commented 1 year ago

I checked on a friend's laptop and I found that option still there. What version of OSX are you on?

image (17)
kesmit13 commented 1 year ago

The JetDirect option is there, but there's no way to send PDF to it, only Postscript and PCL.

kesmit13 commented 1 year ago

Here's an update to the above script which allows you to change the name of the document.

#!/usr/bin/python

import os
import subprocess
import re
import socket
import sys

HOST = '192.168.1.175'
PORT = 9100

for f in sys.argv[1:]:
    s = None

    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((HOST, PORT))

        try:
            title = os.path.splitext(os.path.basename(f))[0].replace('"', "'")
            title = re.sub(r'\.pdf\s*$', r'', title)

            txt = subprocess.check_output(['osascript', '-e', 
                      'Tell application "System Events" to display dialog "Document Name" '
                      'default answer "%s"' % title, '-s', 'so'])
            m = re.search(r'\btext returned\s*:\s*"([^"]+)"', txt)
            if m:
                title = m.group(1)

            s.send('@PJL JOB NAME "%s"\n' % title)

        except:
            pass

        with open(f, 'rb') as infile:
            s.sendall(infile.read())
            pass

    finally:
        if s is not None:
            s.close()
Evidlo commented 9 months ago

It's been a long time (sorry about that). Is this still an issue?

The script does a few extra things, but as far as I can tell, it opens a TCP socket on 9100 to the reMarkable and sends the PDF data prefixed with @PJL JOB NAME [title]\n which is roughly what the JetDirect driver and rmfilter bash script should be doing. Any idea why that isn't working for you?

kesmit13 commented 9 months ago

I used this workaround a long time ago, but I haven't been using this feature recently. This issue can be closed.