Author Topic: print a PDF file (not a DWG) on an external device (a physical printer)  (Read 1040 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 723
is it possible (with VLisp) to print a PDF file (not a DWG)
on an external device (a physical printer) ?

. . . can we use vla-PlotToDevice ?
And how to define the plot-object (the argument of vla-PlotToDevice) ?

however I really don't think vla-PlotToDevice is the right way
« Last Edit: March 30, 2023, 05:18:26 AM by domenicomaria »

domenicomaria

  • Swamp Rat
  • Posts: 723
I have found this but I am not able to get it working . . .

https://www.theswamp.org/index.php?topic=33156.msg574054#msg574054

Code - Auto/Visual Lisp: [Select]
  1. (defun :PDF-TO-PRINTER (path file-name-lst printer-name / full-file-name)
  2.    (dos_getprogress "Printing" "Please wait..." 100)
  3.  
  4.    (foreach fn file-name-lst
  5.       (setq full-file-name (strcat path fn) )
  6.       (dos_getprogress -1)
  7.  
  8.       (dos_shellexe "AcroRd32.exe" (strcat "/N /T \"" full-file-name "\"" printer-name ) 0 3)
  9.       (vl-cmdf "_.delay" 500)
  10.       (while (dos_openp full-file-name) (vl-cmdf "_.delay" 500))
  11.    )
  12.    
  13.    (dos_getprogress t)
  14. )
  15.  
  16. (defun C:XXX ( / path )  
  17.    (setq path (dcl-browsefolder "select a folder containing PDF files :" "c:\\") )
  18.    (:PDF-TO-PRINTER path   (vl-directory-files path "*.pdf") "Brother MFC-6490CW Printer")
  19. )
  20.  
  21.  



domenicomaria

  • Swamp Rat
  • Posts: 723
in the original code, it appears that a quote was omitted. . . Or am I wrong ?

(DOS_SHELLEXE "AcroRd32.exe" (strcat "/N /T \"" FilNam "\" YourPrinterName") 0 3)

(DOS_SHELLEXE "AcroRd32.exe" (strcat "/N /T \"" FilNam "\"" YourPrinterName") 0 3)

57gmc

  • Bull Frog
  • Posts: 358
It's using an AutoCAD addin called DosLib. Do you have that installed? If not, those lisp functions that start with "dos" won't be available to you. Anyway, all its doing is using Windows shell to use acrobat to print the pdf.

You can also modify the SHELL section of your acad.pgp file if you don't want to get DosLib. Work with this section of the file.
Quote
; Examples of external commands for Windows
; See also the (STARTAPP) AutoLISP function for an alternative method.

EXPLORER,  START EXPLORER, 1,,
NOTEPAD,   START NOTEPAD,  1,*File to edit: ,
PBRUSH,    START PBRUSH,   1,,
« Last Edit: March 30, 2023, 10:34:16 AM by 57gmc »

domenicomaria

  • Swamp Rat
  • Posts: 723
I use DosLib

danAllen

  • Newt
  • Posts: 132
in the original code, it appears that a quote was omitted. . . Or am I wrong ?

(DOS_SHELLEXE "AcroRd32.exe" (strcat "/N /T \"" FilNam "\" YourPrinterName") 0 3)

(DOS_SHELLEXE "AcroRd32.exe" (strcat "/N /T \"" FilNam "\"" YourPrinterName") 0 3)

I think you are mistaken. The original code intends to put the file path in quotes to protect for spaces.
Code - Auto/Visual Lisp: [Select]
  1. : (setq FilNam "C:\\TEMP\\TESTPLOT.PDF")
  2. "C:\\TEMP\\TESTPLOT.PDF"
  3. : (setq YourPrinterName "EpsonPrinter")
  4. "EpsonPrinter"
  5. : (strcat "/N /T \"" FilNam "\" YourPrinterName")
  6. "/N /T \"C:\\TEMP\\TESTPLOT.PDF\" YourPrinterName"

danAllen

  • Newt
  • Posts: 132
I don't have adobe on my computer (I use bluebeam), so I don't know if the command line printing works.

I found this page that may show it was disabled:
https://community.adobe.com/t5/acrobat-reader-discussions/how-to-print-a-pdf-from-the-command-line/td-p/8941837

A quick google search shows this option that serves as a "wrapper" around the free PDF-Xchange Viewer
http://www.columbia.edu/~em36/pdftoprinter.html

domenicomaria

  • Swamp Rat
  • Posts: 723
ok

I will try to do something with PDFtoPrinter

Thank you

domenicomaria

  • Swamp Rat
  • Posts: 723
@danAllen

(setq FilNam "C:\\TEMP\\TESTPLOT.PDF")
"C:\\TEMP\\TESTPLOT.PDF"

(setq YourPrinterName "EpsonPrinter")
"EpsonPrinter"

(strcat "/N /T \"" FilNam "\" YourPrinterName")
returns :
"/N /T \"C:\\TEMP\\TESTPLOT.PDF\" YourPrinterName"


While it has to return :

(strcat "/N /T \"" FilNam "\"" YourPrinterName )
"/N /T \"C:\\TEMP\\TESTPLOT.PDF\"EpsonPrinter"

domenicomaria

  • Swamp Rat
  • Posts: 723
ok

I will try to do something with PDFtoPrinter

Thank you

But I still hope that there may be a solution only with VLISP . . .
. . . maybe using FileSystemObject . . .

57gmc

  • Bull Frog
  • Posts: 358
Re: print a PDF file (not a DWG) on an external device (a physical printer)
« Reply #10 on: March 31, 2023, 11:05:38 AM »
ok

I will try to do something with PDFtoPrinter

Thank you

But I still hope that there may be a solution only with VLISP . . .
. . . maybe using FileSystemObject . . .
FileSystemObject only handles files and folder operations. The Shell object is what runs other programs. But to use Shell, the desired program has to accept command line arguments. Dan seems to think that Adobe Acrobat no longer does. If you find a pdf program that has a COM api available then you can code it. Maybe not with lisp though. Lisp vlx commands are written to work with AutoCAD's COM api, but I'm not aware that it can attach to another exe's COM api.

danAllen

  • Newt
  • Posts: 132
Re: print a PDF file (not a DWG) on an external device (a physical printer)
« Reply #11 on: March 31, 2023, 02:51:01 PM »
@domenicomaria

My mistake, I think this is correct:
Code - Auto/Visual Lisp: [Select]
  1. (setq FilNam "C:\\temp\\folder with spaces\\testplot.pdf")
  2. "C:\\temp\\folder with spaces\\testplot.pdf"
  3.  
  4. (setq YourPrinterName "EpsonPrinter")
  5. "EpsonPrinter"
  6.  
  7. (princ (strcat "/N /T \"" FilNam "\" " YourPrinterName))
  8.  
returns
Code: [Select]
/N /T "C:\temp\folder with spaces\testplot.pdf" EpsonPrinter

danAllen

  • Newt
  • Posts: 132
Re: print a PDF file (not a DWG) on an external device (a physical printer)
« Reply #12 on: March 31, 2023, 02:59:13 PM »
Note I only think it may be that Adobe disabled printing from command line, based on the above web page. I thought to test but the Adobe Reader DC download wanted to install crap and seemed such a large download that I cancelled.

I use open source Sumtra as an alternate light PDF reader. It includes command line arguments for printing:
https://www.sumatrapdfreader.org/docs/Command-line-arguments

danAllen

  • Newt
  • Posts: 132
Re: print a PDF file (not a DWG) on an external device (a physical printer)
« Reply #13 on: March 31, 2023, 03:45:20 PM »
Found this command line reference:
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/overview/apxDevFAQ.html?highlight=command%20line#how-do-i-use-the-windows-command-line
also simpler version
https://www.thewindowsclub.com/command-switches-for-adobe-reader-to-aid-deployment

Try not using the /n parameter, and then try using the driver and portname.

Quote
AcroRd32.exe /t path “printername” “drivername” “portname” — Start Acrobat Reader and print a file while suppressing the Print dialog box. The path must be fully specified.

The four parameters of the /t option evaluate to path , printername , drivername , and portname (all strings).

Quote
/n   Start a separate instance of Acrobat or Acrobat Reader, even if one is currently open.

Info on using:
https://stackoverflow.com/questions/31095927/cmd-batch-print-pdf-through-acrobat-reader-dc

tested and at windows command line this dumps a bunch of printer config info to text file which includes DriverName and PortName
Code: [Select]
wmic path Win32_Printer get /value >zda1.txt