Author Topic: Replace the use of a PDF writer for large format documents with XPS  (Read 4372 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
I was asked to share my notes on how I use the builtin XPS print driver to replace the typical PDF printer drivers found on the internet. Below are my own personal notes; please understand that I wrote these over time and for myself. I didn't spend any time cleaning up spelling errors, broken grammar or the weird "third person conversation" thing that usually can be found in notes to myself.

= BRIEF =
I want to replace the use of a PDF writer for large format documents.

= PDF DRIVER PROBLEMS =
1. Bluebeam PDF driver is a clunky mess.
        -e.g. I specify a path in Revit/AutoCAD and yet the driver
              still asks me where to write the file to. This is
              annoying.
2. Distiller has never been that reliable.
3. When looking into using another format, a conversion step will need
   to be preformed. This will be slower but also be a bottle neck to
   discover potential mistakes.

= Add Paper sizes to the XPS driver (WIN 7) =
The XPS driver does not have all the paper size you may need so here
is how to add the ones you want.

1. Add to the default paper sizes for the Microsoft XPS writer print driver.
        Go to Start -> Devices and Printers
        Select the XPS writer.
        Choose: "Print Server Properties"
        Choose: "Change Form Settings"
        Add the paper sizes  you want.

= XPS TO PDF CONVERTER =
Not everyone uses or knows what an XPS file is so I need to convert to
PDF. There are several XPS->PDF converters but the best (by far) is
the GhostXPS executable.
http://ghostscript.com/download/gxpsdnld.html

== BATCH FILE CONVERTER ==
I choose to use a batch file to do the actual calling of GSXPS. Here
are some possible scripts you can use (some require slight editing).

=== RENAME AND CONVERT - ALL ===
Code - Winbatch: [Select]
  1. @echo off
  2. setlocal enableDelayedExpansion
  3.  
  4. SET PROG=gxpswin32-9.18.exe
  5. SET OPTS=-sDEVICE=pdfwrite -dNOPAUSE -sPDFSETTINGS=/prepress
  6.  
  7. :: rename the XPS (remove Revit added prefix)
  8. for %%F in (*.xps) do (
  9.   set "name=%%F"
  10.   ren "!name!" "!name:*- Sheet - =!")
  11.  
  12. :: create the PDFs
  13. for %%F in (*.xps) do (
  14.         echo Making PDF of: %%~nF.xps
  15.         call %PROG% -sOutputFile="%%~nF.pdf" %OPTS% "%%~nF.xps")

=== CONVERT - DRAG AND DROP ===
Code - Winbatch: [Select]
  1. @echo off
  2. setlocal enableDelayedExpansion
  3. set PROG=gxpswin32-9.18.exe
  4. set OPTS=-sDEVICE=pdfwrite -dNOPAUSE -sPDFSETTINGS=/prepress
  5. :: -c "<</Orientation 1>> setpagedevice" -f
  6. :: The above adjusts the orientation of the page.
  7. set OUT=
  8. set PROCESS=%PROG% %OPTS%
  9.  
  10. :processArgs
  11.         if [%1]==[] goto endmark
  12.         call %PROG% -sOutputFile="%~dp1%~n1.pdf" %OPTS% "%~f1"
  13.         if errorlevel 1 goto errormark
  14.         SHIFT
  15.         goto processArgs
  16. :errormark
  17.         echo.
  18.         echo.
  19.         echo ERROR processing  %~f1
  20.         echo.
  21.         pause
  22. :endmark
  23. rem
  24. rem     finished
  25. pause
  26. rem

=== CONVERT - DRAG AND DROP (VBS) ===
This is a VBScript version of the (drag and drop example) above.
Code - Visual Basic: [Select]
  1. ' gxps.vbs WindowsScript wrapper v0.1, 12/08/15
  2. '
  3. '
  4. ' *Purpose*
  5. ' Use this WindowsScript to convert XPSs using drag&drop:
  6. ' 0.  make sure you have windows script host v5.1 on your system
  7. '     (enter 'cscript' in a DOS-Box and compare version number)
  8. ' 1.  adjust the path settings below to fit your needs
  9. ' 2a. put this file somewhere on the desktop
  10. ' 2b. start->execute, enter "sendto", drag the script or a link to it in
  11. '     sendto window (adjust names and icon as you like)
  12. ' 3a. drag one or more xps-files on the icon and they will be converted.
  13. ' 3b. select xps-file(s) and send it via the send-to menu to gsxps!
  14. '
  15. ' You may wish to create copies of this file with different options set.
  16. '
  17. '
  18. ' *History*
  19. ' V0.1 initial release
  20.  
  21. ' *** change path to your needs ***
  22.    path = "<LOCATION>\"   '!!! must end with a backslash !!!
  23.    gxps = "gxpswin32-9.18.exe"
  24.  
  25. ' *** change default options to your needs ***
  26.    opts = "-sDEVICE=pdfwrite -dNOPAUSE -sPDFSETTINGS=/prepress"
  27.  
  28. ' no changes needed below this line
  29. ' ##########################################################################
  30. Dim wsh, args, infile, fs
  31. title="XPS to PDF Script"
  32.  
  33. ' get input files
  34. Set wsh = WScript.CreateObject("WScript.Shell")
  35. Set args = WScript.Arguments
  36. If args.Count = 0 Then
  37.   MsgBox "XPS to PDF converter frontend script." & vbCR & _
  38.         "Please use drag & drop to specify input files.", vbInformation, title
  39.   WScript.Quit
  40. End If
  41.  
  42. ' check path
  43. Set fso = CreateObject("Scripting.FileSystemObject")
  44. If Not fso.FileExists(path & gxps) Then
  45.   MsgBox "Could not find GXPS!" & vbCR & "(looked for '" & path & gxps & "')", vbCritical, title
  46.   WScript.Quit
  47. End If
  48.  
  49. 'process files
  50. For i = 0 To args.Count-1
  51.   infile = args(i)
  52.   ' check input file
  53.  If fso.FolderExists(infile) Then
  54.     MsgBox "'" & infile & "' is a folder!" & vbCR & _
  55.         title & " only handles proper files.", vbInformation, title
  56.   Else
  57.    If Not fso.FileExists(infile) Then
  58.       MsgBox "Error opening input-file" & vbCR & "'" & infile & "'", vbCritical , title
  59.     Else
  60.     ' run gxps
  61.    If(LCase(getExtension(infile))="xps") Then 'decode
  62.      ret = wsh.Run(Chr(34) & path & gxps & Chr(34) & Chr(32) & " -sOutputFile=" & Chr(34) & _
  63.           getBasename(infile) & ".pdf" & Chr(34) & Chr(32) & opts & Chr(32) & Chr(34) & _
  64.           getBasename(infile) & ".xps" & Chr(34), 1, True)
  65.     End If
  66.     ' diagnostics
  67.    Select Case ret
  68.     Case (0) 'okeydokey
  69.    Case (-1)
  70.       MsgBox "GXPS aborted by user!", vbExclamation, title
  71.     Case (1)
  72.       MsgBox "Error returned by GXPS!" & vbCR & "(Check GXPS options and input file formats.)" & vbCR & "Used Options: " & opts, vbCritical, title
  73.     Case Else
  74.       MsgBox "Received unknown GXPS return-code: " & ret, vbCritical, title
  75.     End Select
  76.    End If
  77.   End If
  78. Next
  79.  
  80. WScript.Quit
  81. ' *******************************************************************
  82. ' utility functions
  83.  
  84. Function getBasename(filespec)
  85.   Dim fso
  86.   Set fso = CreateObject("Scripting.FileSystemObject")
  87.   Set f = fso.GetFile(filespec)
  88.  
  89.   getBasename = f.ParentFolder & "\" & fso.GetBaseName(filespec)
  90. End Function
  91.  
  92. Function getExtension(filespec)
  93.   Dim fso
  94.   Set fso = CreateObject("Scripting.FileSystemObject")
  95.   Set f = fso.GetFile(filespec)
  96.  
  97.   getExtension = fso.GetExtensionName(filespec)
  98. End Function
  99.  
  100. ' *******************************************************************
  101.  
  102. 'eof

= XPS AND PDF VIEWING =
The Sumatra PDF viewer supports XPS documents. However, Sumatra PDF doesn't allow you to add annotations.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

hudster

  • Gator
  • Posts: 2848
Re: Replace the use of a PDF writer for large format documents with XPS
« Reply #1 on: January 06, 2016, 05:18:00 AM »
I have this up and running and I must say I'm impressed, but quick question, how do I set the XPS printer up so it auto names the output file the same as the dwg file?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Replace the use of a PDF writer for large format documents with XPS
« Reply #2 on: January 06, 2016, 06:31:17 AM »
Glad you like it, hudster! Not sure I follow the question. Doesn't it already do that (doesn't it accept the name from AutoCAD/Plot dialog)? ...Or are you talking about AutoSpooling (I haven't set that up in years but I can try to brush up on it)?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

hudster

  • Gator
  • Posts: 2848
Re: Replace the use of a PDF writer for large format documents with XPS
« Reply #3 on: January 06, 2016, 09:49:59 AM »
whenever I create a XPS file, I get a plot dialogy, but the name is *.xps and if I click save it does nothing, I have to type in a file name for it to print. What I would like ot do is auto use the file name for XPS files.

Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Replace the use of a PDF writer for large format documents with XPS
« Reply #4 on: January 06, 2016, 09:51:53 AM »
Ah, from publish. That helps, I'll take a look in a bit.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: Replace the use of a PDF writer for large format documents with XPS
« Reply #5 on: January 06, 2016, 10:18:59 AM »
I just opened AutoCAD and I got the same thing. ...hum?! That shouldn't be like that; I mean I haven't used AutoCAD in a few years now but I'm almost positive I used the XPS driver from AutoCAD back when (I switched to XPS because I hate that prompt from other drivers). I'm not sure, hudster. I hope I didn't steer you down a bad path. I'll have to take another look when I get more time. Let me know if you find out anything on your end.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

hudster

  • Gator
  • Posts: 2848
Re: Replace the use of a PDF writer for large format documents with XPS
« Reply #6 on: January 06, 2016, 10:51:09 AM »
I'm sure its just a setting I missed, I'll have a dig about and see what I can find out
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue