# sending pdf files to pcl printer from command line



## exeter (Dec 25, 2022)

I have a large number of medical advice leaflets as pdf files. I'd like to print them, individually, not all at once, when required,  to a PCL6 printer from the command line. I have reviewed the printing section of Handbook and Googled the issue but I'm unsure of the best solution. I can print text files from the command line like this `$ lpr textfile.txt`so a solution along the lines of`$ something advicefile.pdf` would be ideal.


----------



## Alain De Vos (Dec 25, 2022)

Why not use cups with its pcl drivers ?
Or you can try:


			Printing with Netcat
		

&  ghostscript9-agpl-base contains pdf2ps


----------



## Holger (Dec 26, 2022)

If you use Cups, you can use its command line interface `lpr-cups`. It accepts PDF files and works as follows:

```
/home/hsebert % lpr-cups --help
Usage: lpr [options] [file(s)]
Options:
-# num-copies           Specify the number of copies to print
-E                      Encrypt the connection to the server
-H server[:port]        Connect to the named server and port
-m                      Send an email notification when the job completes
-o option[=value]       Specify a printer-specific option
-o job-sheets=standard  Print a banner page with the job
-o media=size           Specify the media size to use
-o number-up=N          Specify that input pages should be printed N-up (1, 2, 4, 6, 9, and 16 are supported)
-o orientation-requested=N
                        Specify portrait (3) or landscape (4) orientation
-o print-quality=N      Specify the print quality - draft (3), normal (4), or best (5)
-o sides=one-sided      Specify 1-sided printing
-o sides=two-sided-long-edge
                        Specify 2-sided portrait printing
-o sides=two-sided-short-edge
                        Specify 2-sided landscape printing
-P destination          Specify the destination
-q                      Specify the job should be held for printing
-r                      Remove the file(s) after submission
-T title                Specify the job title
-U username             Specify the username to use for authentication
```

See also here: https://www.cups.org/doc/options.html


----------



## hruodr (Dec 26, 2022)

Ghostcript does take pdf, no need to translate it into ps.
Write an executable file ps2pcl6 on a directory on your path, say  /usr/opt/bin/, with the content



> #!/bin/sh
> /usr/local/bin/gs -dSAFER -dNOPAUSE -dBATCH -q -sDEVICE=pxlmono -r600 -sPAPERSIZE=a4 -sOutputFile=- -


(or adjust papersize)

And print with the command line

`cat file.pdf | ps2pcl6 > /dev/ulpt0`
(or use device where your printer is connected)


----------



## scottro (Dec 26, 2022)

My printer is on 192.168.1.50. I use netcat and it does it without cups. This is for one-sided printing.
First, I change it to ps file. 

```
pdf2ps myfile.pdf myfile.ps
```
Then

```
nc 192.168.1.50 9100 < myfile.ps
```
This is on a Samsung C460 printer that handles postscript,but most printers handle postscript these days.

But, hruodr's solution is probably quicker in the long run.

There is a saying, There's always more than one way to do something in Unix, with the corollary, Someone will think your way is stupid.  But having been married so long, I'm used to someone thinking what I do is stupid.


----------



## exeter (Dec 26, 2022)

Holger said:


> If you use Cups, you can use its command line interface `lpr-cups`. It accepts PDF files and works as follows:
> 
> ```
> /home/hsebert % lpr-cups --help
> ...


Thanks for that. CUPS seems very capable. Unfortunately the instructions at https://docs.freebsd.org/en/articles/cups/ don't work for me. For example I can't make a connection to http://192.168.0.5:631 and the file /etc/devfs.rules doesn't exist, but the instructions clearly think it should. I'd like to get it going and I've done my due diligence searching freebsd.org, cups.org and Googling the issue but I haven't come up with a source of instructions that work. Any ideas as to where I might find instructions.


----------



## Alain De Vos (Dec 26, 2022)

```
service cupsd onestart
firefox "http://127.0.0.1:631"
```

These is is my /etc/defvs.rules:

```
[system=10]
add path 'usb/*'    mode 0660 group operator
add path 'ugen*'    mode 0660 group operator
add path 'usbctl'   mode 0660 group operator
add path 'usb*'     mode 0660 group operator
add path 'uscan*'   mode 0660 group operator
#SCSI
add path 'pass*'    mode 0660 group operator
add path 'xpt*'     mode 0660 group operator
#CD
add path 'acd*'     mode 0660 group operator
add path 'cd*'      mode 0660 group operator
#VIDEO
add path 'video*'   mode 0660 group operator
#MMCSD
add path 'mmcsd*'   mode 0660 group operator
#IICDEV
add path 'iicdev*'  mode 0660 group operator
#ad
add path 'ad*'      mode 0660 group operator
#da
add path 'da*'      mode 0666 group operator
#wayland
add path 'input/*'  mode 0660 group operator
```


----------



## hruodr (Dec 26, 2022)

scottro said:


> This is on a Samsung C460 printer that handles postscript


That is why the OP needs a script like my ps2pcl6, if his printer is only PCL6.

 The same script can be put as input filter (if) in /etc/printcap, and then he can use 
`lpr`, for sending ps and pdf files. Some more little work is necessary for sending also txt files.


----------



## Alain De Vos (Dec 26, 2022)

I never tried it but there is 

```
lprsetup.sh -?
```


----------



## exeter (Dec 26, 2022)

hruodr said:


> That is why the OP needs a script like my ps2pcl6, if his printer is only PCL6.
> 
> The same script can be put as input filter (if) in /etc/printcap, and then he can use
> `lpr`, for sending ps and pdf files. Some more little work is necessary for sending also txt files.


Hmmm, I think I may have been misled. I looked at the documentation for my printer, a Brother HL-2150n and it said it was PCL6, but just now I  Googled it again and got this page: https://support.brother.com/g/b/spec.aspx?c=gb&lang=en&prod=hl2150n_all , which calls it a GDI printer in Linux. I'm guessing, but it seems to be a PCL6 printer when accessed via the Windows driver. Oddly, when I print the 'Network configuration' page from the web control panel in the printer, it mentions 'POSTSCRIPT_P1' in active services. How odd. Just as oddly, I can print text files which incorporate HPGL codes without a hitch.


----------



## Alain De Vos (Dec 26, 2022)

PPD file for brother HL-2140

```
*PPD-Adobe: "4.3"
*%
*% For information on using this, and to obtain the required backend
*% script, consult http://www.openprinting.org/
*%
*% This file is published under the GNU General Public License
*%
*% PPD-O-MATIC (4.0.0 or newer) generated this PPD file. It is for use with 
*% all programs and environments which use PPD files for dealing with
*% printer capability information. The printer must be configured with the
*% "foomatic-rip" backend filter script of Foomatic 4.0.0 or newer. This 
*% file and "foomatic-rip" work together to support PPD-controlled printer
*% driver option access with all supported printer drivers and printing
*% spoolers.
*%
*% To save this file on your disk, wait until the download has completed
*% (the animation of the browser logo must stop) and then use the
*% "Save as..." command in the "File" menu of your browser or in the 
*% pop-up manu when you click on this document with the right mouse button.
*% DO NOT cut and paste this file into an editor with your mouse. This can
*% introduce additional line breaks which lead to unexpected results.
*%
*% You may save this file as 'Brother-HL-2140-Postscript.ppd'
*%
*%
*FormatVersion:    "4.3"
*FileVersion:    "1.1"
*LanguageVersion: English 
*LanguageEncoding: ISOLatin1
*PCFileName:    "POSTSCRI.PPD"
*Manufacturer:    "Brother"
*Product:    "(HL-2140 series)"
*cupsVersion:    1.0
*cupsManualCopies: True
*cupsModelNumber:  2
*cupsFilter:    "application/vnd.cups-postscript 100 foomatic-rip"
*cupsFilter:    "application/vnd.cups-pdf 0 foomatic-rip"
*%pprRIP:        foomatic-rip other
*ModelName:     "Brother HL-2140"
*ShortNickName: "Brother HL-2140 Postscript"
*NickName:      "Brother HL-2140 Foomatic/Postscript"
*PSVersion:    "(3010.000) 550"
*PSVersion:    "(3010.000) 651"
*PSVersion:    "(3010.000) 652"
*PSVersion:    "(3010.000) 653"
*PSVersion:    "(3010.000) 704"
*PSVersion:    "(3010.000) 705"
*PSVersion:    "(3010.000) 800"
*PSVersion:    "(3010.000) 815"
*PSVersion:    "(3010.000) 850"
*PSVersion:    "(3010.000) 860"
*PSVersion:    "(3010.000) 861"
*PSVersion:    "(3010.000) 862"
*PSVersion:    "(3010.000) 863"
*PSVersion:    "(3010.000) 864"
*PSVersion:    "(3010.000) 870"
*LanguageLevel:    "3"
*ColorDevice:    False
*DefaultColorSpace: Gray
*FileSystem:    False
*Throughput:    "1"
*LandscapeOrientation: Plus90
*TTRasterizer:    Type42
*1284DeviceID: "MFG:Brother;MDL:HL-2140 series;CMD:PJL,HBP;DRV:DPostscript,R0,M0,TP;"

*driverName Postscript: ""
*driverType P/PostScript: ""
*driverUrl: "http://partners.adobe.com/public/developer/ps/index_specs.html"
*driverObsolete: False
*driverManufacturerSupplied: False




*HWMargins: 18 36 18 36
*VariablePaperSize: True
*MaxMediaWidth: 100000
*MaxMediaHeight: 100000
*NonUIOrderDependency: 100 AnySetup *CustomPageSize
*CustomPageSize True: "pop pop pop
<</PageSize [ 5 -2 roll ] /ImagingBBox null>>setpagedevice"
*End
*ParamCustomPageSize Width: 1 points 36 100000
*ParamCustomPageSize Height: 2 points 36 100000
*ParamCustomPageSize Orientation: 3 int 0 0
*ParamCustomPageSize WidthOffset: 4 points 0 0
*ParamCustomPageSize HeightOffset: 5 points 0 0

*FoomaticIDs: Brother-HL-2140 Postscript
*FoomaticRIPCommandLine: "cat%A%B%Z"
*FoomaticRIPNoPageAccounting: True

*OpenGroup: General/General

*OpenUI *PageSize/Page Size: PickOne
*OrderDependency: 100 AnySetup *PageSize
*DefaultPageSize: Letter
*PageSize Letter/US Letter: "<</PageSize[612 792]/ImagingBBox null>>setpagedevice"
*PageSize A4/A4: "<</PageSize[595 842]/ImagingBBox null>>setpagedevice"
*PageSize 11x17/11x17: "<</PageSize[792 1224]/ImagingBBox null>>setpagedevice"
*PageSize A3/A3: "<</PageSize[842 1191]/ImagingBBox null>>setpagedevice"
*PageSize A5/A5: "<</PageSize[421 595]/ImagingBBox null>>setpagedevice"
*PageSize B5/B5 (JIS): "<</PageSize[516 729]/ImagingBBox null>>setpagedevice"
*PageSize Env10/Envelope #10: "<</PageSize[297 684]/ImagingBBox null>>setpagedevice"
*PageSize EnvC5/Envelope C5: "<</PageSize[459 649]/ImagingBBox null>>setpagedevice"
*PageSize EnvDL/Envelope DL: "<</PageSize[312 624]/ImagingBBox null>>setpagedevice"
*PageSize EnvISOB5/Envelope B5: "<</PageSize[499 709]/ImagingBBox null>>setpagedevice"
*PageSize EnvMonarch/Envelope Monarch: "<</PageSize[279 540]/ImagingBBox null>>setpagedevice"
*PageSize Executive/Executive: "<</PageSize[522 756]/ImagingBBox null>>setpagedevice"
*PageSize Legal/US Legal: "<</PageSize[612 1008]/ImagingBBox null>>setpagedevice"
*CloseUI: *PageSize

*OpenUI *PageRegion: PickOne
*OrderDependency: 100 AnySetup *PageRegion
*DefaultPageRegion: Letter
*PageRegion Letter/US Letter: "<</PageSize[612 792]/ImagingBBox null>>setpagedevice"
*PageRegion A4/A4: "<</PageSize[595 842]/ImagingBBox null>>setpagedevice"
*PageRegion 11x17/11x17: "<</PageSize[792 1224]/ImagingBBox null>>setpagedevice"
*PageRegion A3/A3: "<</PageSize[842 1191]/ImagingBBox null>>setpagedevice"
*PageRegion A5/A5: "<</PageSize[421 595]/ImagingBBox null>>setpagedevice"
*PageRegion B5/B5 (JIS): "<</PageSize[516 729]/ImagingBBox null>>setpagedevice"
*PageRegion Env10/Envelope #10: "<</PageSize[297 684]/ImagingBBox null>>setpagedevice"
*PageRegion EnvC5/Envelope C5: "<</PageSize[459 649]/ImagingBBox null>>setpagedevice"
*PageRegion EnvDL/Envelope DL: "<</PageSize[312 624]/ImagingBBox null>>setpagedevice"
*PageRegion EnvISOB5/Envelope B5: "<</PageSize[499 709]/ImagingBBox null>>setpagedevice"
*PageRegion EnvMonarch/Envelope Monarch: "<</PageSize[279 540]/ImagingBBox null>>setpagedevice"
*PageRegion Executive/Executive: "<</PageSize[522 756]/ImagingBBox null>>setpagedevice"
*PageRegion Legal/US Legal: "<</PageSize[612 1008]/ImagingBBox null>>setpagedevice"
*CloseUI: *PageRegion

*DefaultImageableArea: Letter
*ImageableArea Letter/US Letter: "18 36 594 756"
*ImageableArea A4/A4: "18 36 577 806"
*ImageableArea 11x17/11x17: "18 36 774 1188"
*ImageableArea A3/A3: "18 36 824 1155"
*ImageableArea A5/A5: "18 36 403 559"
*ImageableArea B5/B5 (JIS): "18 36 498 693"
*ImageableArea Env10/Envelope #10: "18 36 279 648"
*ImageableArea EnvC5/Envelope C5: "18 36 441 613"
*ImageableArea EnvDL/Envelope DL: "18 36 294 588"
*ImageableArea EnvISOB5/Envelope B5: "18 36 481 673"
*ImageableArea EnvMonarch/Envelope Monarch: "18 36 261 504"
*ImageableArea Executive/Executive: "18 36 504 720"
*ImageableArea Legal/US Legal: "18 36 594 972"

*DefaultPaperDimension: Letter
*PaperDimension Letter/US Letter: "612 792"
*PaperDimension A4/A4: "595 842"
*PaperDimension 11x17/11x17: "792 1224"
*PaperDimension A3/A3: "842 1191"
*PaperDimension A5/A5: "421 595"
*PaperDimension B5/B5 (JIS): "516 729"
*PaperDimension Env10/Envelope #10: "297 684"
*PaperDimension EnvC5/Envelope C5: "459 649"
*PaperDimension EnvDL/Envelope DL: "312 624"
*PaperDimension EnvISOB5/Envelope B5: "499 709"
*PaperDimension EnvMonarch/Envelope Monarch: "279 540"
*PaperDimension Executive/Executive: "522 756"
*PaperDimension Legal/US Legal: "612 1008"

*JCLOpenUI *MediaType/Media Type: PickOne
*OrderDependency: 100 JCLSetup *MediaType
*DefaultMediaType: Plain
*MediaType Plain/Plain Paper: "@PJL SET MEDIATYPE=REGULAR<0A>"
*MediaType Bond/Bond Paper: "@PJL SET MEDIATYPE=BOND<0A>"
*MediaType Thick/Thick Paper: "@PJL SET MEDIATYPE=THICK<0A>"
*MediaType ThickEnvelopes/Thick Envelopes: "@PJL SET MEDIATYPE=ENV-THICK<0A>"
*MediaType Thicker/Thicker Paper: "@PJL SET MEDIATYPE=THICKER<0A>"
*MediaType Thin/Thin Paper: "@PJL SET MEDIATYPE=THIN<0A>"
*MediaType ThinEnvelopes/Thin Envelopes: "@PJL SET MEDIATYPE=ENV-THIN<0A>"
*MediaType Transparencies/Transparent: "@PJL SET MEDIATYPE=TRANS<0A>"
*JCLCloseUI: *MediaType

*JCLOpenUI *Economode/Economy Mode: PickOne
*OrderDependency: 100 JCLSetup *Economode
*DefaultEconomode: Off
*Economode Off/Off: "@PJL SET ECONOMODE=OFF<0A>"
*Economode On/On: "@PJL SET ECONOMODE=ON<0A>"
*JCLCloseUI: *Economode

*OpenUI *Duplex/Double-Sided Printing: PickOne
*OrderDependency: 130 AnySetup *Duplex
*DefaultDuplex: None
*Duplex DuplexNoTumble/Long Edge (Standard): "<</Duplex true /Tumble false>>setpagedevice"
*Duplex DuplexTumble/Short Edge (Flip): "<</Duplex true /Tumble true>>setpagedevice"
*Duplex None/Off: "<</Duplex false>>setpagedevice"
*CloseUI: *Duplex

*OpenUI *Resolution/Resolution: PickOne
*OrderDependency: 90 AnySetup *Resolution
*DefaultResolution: 600x600dpi
*Resolution 150x150dpi/150x150 DPI: "<</HWResolution[150 150]>>setpagedevice"
*Resolution 300x300dpi/300x300 DPI: "<</HWResolution[300 300]>>setpagedevice"
*Resolution 600x600dpi/600x600 DPI: "<</HWResolution[600 600]>>setpagedevice"
*CloseUI: *Resolution

*CloseGroup: General


*% Generic boilerplate PPD stuff as standard PostScript fonts and so on

*DefaultFont: Courier
*Font AvantGarde-Book: Standard "(001.006S)" Standard ROM
*Font AvantGarde-BookOblique: Standard "(001.006S)" Standard ROM
*Font AvantGarde-Demi: Standard "(001.007S)" Standard ROM
*Font AvantGarde-DemiOblique: Standard "(001.007S)" Standard ROM
*Font Bookman-Demi: Standard "(001.004S)" Standard ROM
*Font Bookman-DemiItalic: Standard "(001.004S)" Standard ROM
*Font Bookman-Light: Standard "(001.004S)" Standard ROM
*Font Bookman-LightItalic: Standard "(001.004S)" Standard ROM
*Font Courier: Standard "(002.004S)" Standard ROM
*Font Courier-Bold: Standard "(002.004S)" Standard ROM
*Font Courier-BoldOblique: Standard "(002.004S)" Standard ROM
*Font Courier-Oblique: Standard "(002.004S)" Standard ROM
*Font Helvetica: Standard "(001.006S)" Standard ROM
*Font Helvetica-Bold: Standard "(001.007S)" Standard ROM
*Font Helvetica-BoldOblique: Standard "(001.007S)" Standard ROM
*Font Helvetica-Narrow: Standard "(001.006S)" Standard ROM
*Font Helvetica-Narrow-Bold: Standard "(001.007S)" Standard ROM
*Font Helvetica-Narrow-BoldOblique: Standard "(001.007S)" Standard ROM
*Font Helvetica-Narrow-Oblique: Standard "(001.006S)" Standard ROM
*Font Helvetica-Oblique: Standard "(001.006S)" Standard ROM
*Font NewCenturySchlbk-Bold: Standard "(001.009S)" Standard ROM
*Font NewCenturySchlbk-BoldItalic: Standard "(001.007S)" Standard ROM
*Font NewCenturySchlbk-Italic: Standard "(001.006S)" Standard ROM
*Font NewCenturySchlbk-Roman: Standard "(001.007S)" Standard ROM
*Font Palatino-Bold: Standard "(001.005S)" Standard ROM
*Font Palatino-BoldItalic: Standard "(001.005S)" Standard ROM
*Font Palatino-Italic: Standard "(001.005S)" Standard ROM
*Font Palatino-Roman: Standard "(001.005S)" Standard ROM
*Font Symbol: Special "(001.007S)" Special ROM
*Font Times-Bold: Standard "(001.007S)" Standard ROM
*Font Times-BoldItalic: Standard "(001.009S)" Standard ROM
*Font Times-Italic: Standard "(001.007S)" Standard ROM
*Font Times-Roman: Standard "(001.007S)" Standard ROM
*Font ZapfChancery-MediumItalic: Standard "(001.007S)" Standard ROM
*Font ZapfDingbats: Special "(001.004S)" Standard ROM
```


----------



## exeter (Dec 26, 2022)

Alain De Vos said:


> PPD file for brother HL-2140
> 
> ```
> *PPD-Adobe: "4.3"
> ...


I like the look of that. Thank you so much for taking the time to reply. I'm reading the openprinting.github.io page to see how to use it. In the mean time are there any other resources that offer guidance on using it with FreeBSD. openprinting.github.io seems to be Linux specific, going as far as needing Snap installing.


----------



## exeter (Dec 26, 2022)

Oh ho. I finally got access to the CUPS web interface page using advice from here: http://thismightbehelpful.blogspot.com/2008/09/remote-access-to-cups-web-interface.html


----------



## exeter (Dec 26, 2022)

When I installed it earlier it stopped lpd running. Can CUPS be made to work along side lpd? During a transition I'd still like to be able to use my existing printing facilities.


----------



## hruodr (Dec 26, 2022)

exeter said:


> I looked at the documentation for my printer, a Brother HL-2150n and it said it was PCL6, but just now I Googled it again and got this page: https://support.brother.com/g/b/spec.aspx?c=gb&lang=en&prod=hl2150n_all , which calls it a GDI printer in Linux.


Strange. PCL& emulation, but GDI. And it is not mentioned in:






						Printer List | OpenPrinting - The Linux Foundation
					






					www.openprinting.org
				




But you may try and see if what I wrote before works.


----------



## dgmm (Dec 27, 2022)

Since I have a Brother Laser printer too, a 5100, this thread caught my eye.  I had a look through the full manual for the 2150 and it does appear to be a PCL6 printer not a GDI printer.  In the manual, it only refers to GDI in relation to the 2140, not the 2150 or 2170 which use PCL6 drivers.  If I was you, I'd first try treating it as as generic PCL5 or 6 printer and see what happens.


----------



## exeter (Dec 30, 2022)

I tried converting sample file pdf_file_to_print.pdf to PCL6 using: 
`user2@pr5:/usr/home/parkrow $ gs -dSAFER -dNOPAUSE -dBATCH -q -sDEVICE=pxlmono -r600 -sPAPERSIZE=a4 -sOutputFile=pcl_file.pcl /tmp/pdf_file_to_print.pdf`

which did create an output file: 
-rw-rw-r--  1 user2    parkrow      5228 Dec 30 18:34 pcl_file.pcl

I tried to send the PCL6 file to the printer like this:
`nc 192.168.0.11 9100 < pcl_file.pcl`
but there was no output. 

Does anything spring out as wrong?


----------



## exeter (Jan 5, 2023)

How would I test the PCL file to see if it is in fact a file suitable to send to a PCL6 printer?


----------



## scottro (Jan 5, 2023)

A cursory web search shows several online sites that will let you view a pcl document.  Here is the first link that came up. I have no idea if it tracks you or does otherwise nasty things but a search for something like online pcl viewers should help. I didn't see anything obvious doing pkg search pcl, but again, I didn't put much effort into it.  

Edit: I forgot to put the link. https://products.groupdocs.app/viewer/pcl


----------



## shepper (Friday at 2:40 AM)

hruodr  print filter is the correct one but they traditionally are placed in /usr/local/libexec.



> which did create an output file:
> -rw-rw-r--  1 user2    parkrow      5228 Dec 30 18:34 pcl_file.pcl



This lacks executable permissions and usually the owner:group is daemon:daemon

The reason the files go into /usr/local/libexec  is that they are executable files
See the handbook for correct location, owner/group and permissions
https://docs.freebsd.org/en/books/handbook/printing/#printing-lpd-setup

https://docs.freebsd.org/en/books/handbook/printing/#printing-lpd-filters-ps2pcl

There are two utilities that can convert a pdf to a ps (postscript) file: pdf2ps(1) which is the ghostscript tool.  pdftops(1) is from xpdf.  After converting *.pdf -> *.ps, you can command line print with
`lpr *.ps`

Personally, what I like to use for lpr printing is graphics/zathura-pdf-mupdf.  You can view the pdf and the command `:print` will bring up an lpr print dialog.  Another option is print/gv which essentially uses pdf2ps.


----------



## exeter (Sunday at 5:46 PM)

scottro said:


> A cursory web search shows several online sites that will let you view a pcl document.  Here is the first link that came up. I have no idea if it tracks you or does otherwise nasty things but a search for something like online pcl viewers should help. I didn't see anything obvious doing pkg search pcl, but again, I didn't put much effort into it.
> 
> Edit: I forgot to put the link. https://products.groupdocs.app/viewer/pcl


That's vee useful. Turns out the files don't seem to be proper PCL for some reason. I'll investigate in more detail later. Tar anyway.


----------

