printing PDFs from Revit…why is it so hard?

image by guys from office space

Disclaimer: 

If you don’t have to, please don’t reinvent the wheel. I am a proponent of just going out and buying the tools you need to do your job, rather than re-making them yourself. It’s a bit inefficient to solve the same problem that others have already solved. With that said, the best tool on the market for running PDF prints is RTV Tools. Get that if you can spend a few bucks. The rest of us poor souls, read on! 

I put Revit’s name in the title, but to be honest the responsibility for this lies somewhere in-between Autodesk and Adobe. First, let’s make it clear, that for a piece of software that main’s job is to create documentation drawings of buildings (99% of the time distributed in PDF format), not to have its own PDF creator, or at least licensed and implemented one of the handful available ones…I just have no words for this Autodesk. This condition, that we have been dealing with since Revit’s inception some 15+ years ago, is just not acceptable. Sure, it’s hunky-dory to let users specify their own Printer, but for god’s sake, Autodesk, please also give them an embedded one that comes with the software. That would also allow you to cater to needs of those of us, that want a little more out of the software than a typical end user. I am speaking of the development community that wants to build automation tools on top of your software, and having access to embedded PDF creator, with ability to specify things like JPG Compression, Security protocols or simply FILE NAME. Yes! File name, and location that will not be overridden by the 3rd party PDF creator like Adobe’s Distiller. Now that we are on the subject of Adobe and its free PDF Reader, I just have no words for how shitty that thing is. Yes, it’s free, but it’s also severely crippled, and ON PURPOSE! What the hell were you thinking Adobe, always launching Acro Tray process in the background, and leaving it open even, when printing is done. WTF? Yes, the paid version of your software has more support, but still…that’s just sad. Anyways, let’s talk about some solutions here:

You probably know that if you set Printing Preferences for Adobe PDF printer, like this…

…you should be able to send a printing job of multiple sheets, and you would not be prompted to specify location for each one individually. That’s great if you are content with the pre-defined print location. What happens when you are building a plug-in and you want your users to be able to specify custom file names and file locations? In that case there is so far been one option:

Override the PrinterJobControl registry input! What?! Yes, in order to specify a file name, one must dabble with Registry. Thanks Autodesk! That’s swell! Here’s how and why:

Adobe PDF, normally prompts user for a new file location. However, there is a way to override that, if one overrides the PrinterJobControl subkey, with a Key/Value pair specifically telling Adobe that for the next printing job submitted from Revit.exe process, you want it to print to a specific filename and location. Here’s a small utility that will do that for you:

As you can see this will only work for Adobe PDF printer. I also have a global variable named CURRENT_REVIT_VERSION stored in my Settings file. This should be either 2016 or 2017 depending on what version of Revit I am compiling my plug-in for. Basically, you would need to call this method before every single sheet is submitted to Revit’s Print Manager for printing. That way, you always override the next print job’s name, and location and Adobe won’t prompt for filename.

Now, it might ask to replace an existing file if you didn’t uncheck that setting in the Printing Preferences dialog box. To avoid seeing that prompt, just use the regular File.Exists() method and File.Delete() to clean up before printing. Something like this will do:

Now, I also often do a post processing routine. Take for example, Zipping up all of your files to be sent to consultant or even combining them into a single PDF, if you are that adventurous. Since printing a PDF can take quite some time, even minutes, which in computer world is freaking decades, you will need a small utility to wait for the last file to print before starting your post processing. Here’s one I copy-pasted from Stack Overflow (copying and pasting from SO is an art.):

I call it like this:

The “lastCreatedFileName” variable is as you can guess the name of the last sheet that I have submitted to Print Manager. I am only really checking the last file submitted, since all others would be done, before I can submit my last one. My wait routine, has 1000 loops each halting the execution for 300 ms for a total of 3min. If printing of your last sheet takes more than 3min, it will most likely be skipped in the post-processing routine. Just an FYI.

I hope this helps. Cheers!

Support archi-lab on Patreon!

27 Comments

  1. Viktor Kuzev says:

    Great post and the “Office Space” reference is hilarious. I can’t count how many weird looks I’ve taken from colleagues when stating that Revit does not have its own PDF printer.
    I still feel quite uncomfortable even looking at c# code though :)

  2. JefferyHarwood says:

    This is great. Thank you for the lesson.

  3. Great blog my friend :-)

  4. Konrad, have you looked at other free pdf printers? A lot of people use cutePDF.
    In the past line used a schedule and DOS batch file to rename after the fact. Clunky but robust.
    A python version for using in Dynamo world be great.

  5. 4bimferdie says:

    Hi Konrad,

    Nice blog…i hear you. 10 years ago i have same problem with AutocCAD, it has no built-pdf creator. I have to make my own, now i face the same thing for years now i am only happy with plotting via the revit ui using cutepdf. But I recently discovered the power of dynamo so i joined the dynamo forum. At first i was searching for a way to create pdf with minimal user input like what i have done in autocad thru lisp and scripts. But i have no luck, what you have done in the pdf creation side in dynamo are amazing well done to you.

    I think i can recreate my pdf printing program again using dynamo. I have very positive results. I will post it in the dynamo forum once i am happy everything is working. I will then use it in revit to created pdfs with customized filenames etc.

    Thanks

  6. Michael Park says:

    Hello,

    I made a few tweaks to the code in one of your old articles that allows you to send in the list of filenames you want to export (so you can have a separate filename for each page you are exporting.) This allows me to have all the files named in the first place once you choose where you want the files to save. I have attached a zip file of the .dyn file and the .py file for my changes. Let me know if this is helpful for you. Just a bit easier than needing to use the rename files nodes as it names it correctly in the first place. (In my opinion).

    Cheers,

    Michael

  7. joaco says:

    would it be too much to ask for a walkthrough on how to use this code? i never use dinamo
    :(

    • Sorry, this is an old post. I don’t usually provide that kind of support. Please try asking on the Dynamo Forum. Maybe someone there will be willing to walk you through this.

  8. John MacIvor says:

    Simple Use Bluebeam!

  9. Nathan says:

    Totally agree with your sentiment. A piece of software designed to produce construction documents that doesn’t have it it’s own basic PDF driver/printer. That makes sense. But it can create DWFs, which everyone uses as much as PDFs. Oh wait…

    In regards to comment about Bluebeam, if you use the add-in that comes with Bluebeam, it does have some useful additional controls, including changing where they get saved, bookmarks, print order, and some file name controls if creating individual PDFs. Nothing as automated as RTV Tools.

  10. Ivan says:

    This is only one reason why ArchiCAD is superior to Revit.

    Autodesk bought Revit because they knew BIM was the future and they didn’t have a BIM product. ArchiCAD was already doing this many years ago- easy to print your sets!

    Autodesk cares about it’s stock, not you.

    • Sure. I agree that Autodesk, and for that matter majority of all companies, all across the world, operate that way. I am not sure this is exclusive to Autodesk. I would say that companies that don’t operate that way are an exception, and a refreshing and welcome one for sure, but still an exception.

  11. Petr F. says:

    It’s hard but not imposible

    You can try my plugin PF Printer PDF

    – Print all selected sheets to PDF with correct paper size…You can use standard size or custom paper size…all is doing automaticaly

    I used it everyday. Spend my time

  12. Cesar Trevizo says:

    What I do is go to the Properties to Specify the “Output” folder in the “Adobe PDF Output Folder” field. Sometimes I use a “space” or “underscore”, because it will always add ” – Sheet – (Sheet Number) – (Sheet Name).pdf”. So the “Name” in the Revit Print Prompt would be “C:\Folder1\Folder2\_.pdf”.
    This is how I avoid “Specifying” the file name when printing individual sheet files.

  13. Michael Coffey says:

    Konrad, thanks for sharing. I don’t know why I can’t get this to work. I see the keys changing as my macro runs but i don’t know where the pdfs are going. (I also checked Documents) They never get made in the specified folder, even though i see the acrobat pdf creating popup. The second key listed has ‘-1’ as its name. Any help is appreciated. Thanks.

  14. I can’t believe how much time those software companies suck out of your day.

  15. Johnny K says:

    Autodesk is the biggest joke. It symbolizes everything wrong with our culture today. They never learn from or care about their customer base. I wish I didn’t have to work with them. And nobody say, “You don’t have to. There are plenty of other programs out there.” Yes, if you own the company or have choice of your client list then that’s true. For everyone else, we get solve all of Autodesk’s problems until they fix something in one of their programs just before it goes obsolete anyway. Sorry, just had to get it out. Maybe I’ll be better tomorrow. Just annoying when there’s never any state of flow achieved when having to work with Revit in particular.

Reply to Ivan Cancel Reply