Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export the sheet to pdf and suppress the dialog to save the file location

8 REPLIES 8
Reply
Message 1 of 9
imaliasad
3296 Views, 8 Replies

Export the sheet to pdf and suppress the dialog to save the file location

Hello all,

 

I'm trying to export sheet in PDF format by using @jeremytammik solution (link here). So far the solution is perfect. However, whenever  I try to export the sheet a dialog box appears to choose the location to save. I was wondering  Is it possible to override the print driver settings, without a dialog popping up? I want to automatically choose the locations, rather than clicking it in the file system each time.

 

Here's the code:

 

        public static void ExportSheetToPDF(Document doc, string path)
        {
            using (Transaction tx = new Transaction(doc))

            {

                tx.Start("Exportint to PDF");
                PrintManager pm = doc.PrintManager;
               
                pm.SelectNewPrintDriver("Adobe PDF");               
                pm.PrintRange = PrintRange.Current;             
                pm.CombinedFile = true;            
                pm.PrintToFile = true;        
                pm.PrintToFileName = path + @"\PDF\" + "test.pdf";             

                pm.SubmitPrint();
                tx.Commit();

            }
            
        }

surpress the dialog.PNG

 

 Update:

Also, I don't want to change the 'Printing Preferences' setting because in that case dialog will be suppressed but the location where the pdf will be saved get hard coded. I would like to provide the filepath value from code dynamically. 

8 REPLIES 8
Message 2 of 9
grahamcook
in reply to: imaliasad

Hi

 

Probably not the answer you want but in the past I've used a custom CutePDF writer to achieve this.  It allows you to create an uninterruptable print as you can specify the output path of the saved PDF.  It's not free though but does work very well.

 

Message 3 of 9
RPTHOMAS108
in reply to: imaliasad

This is a common question here but it relates more to the PDF driver than Revit. There is a print to file in the settings Revit side but this is often ignored by the driver.

 

For example I believe within the Adobe PDF writer there is a RegKey that can be set for a one time print to a specific path, so presumably you set this between prints. I never got it working due to virtualisation of the registry in my case but is probably more straightforward outside of that on a local PC.

 

The link below is old but there'll likely be a more recent equivalent. If you aren't using Adobe then you need to look for help based on what you are using.

 

https://stackoverflow.com/questions/2075104/bypass-adobe-pdf-printer-savefileas-prompt

 

My current solution is to spot the appearance of the window with the Win32 API, feed the window a filename and press the OK. Seems to work but I'm just waiting for the error when someone prints two things at the same time and two windows pop up. A bit of a ridiculous solution really, all in all.

Message 4 of 9
grahamcook
in reply to: RPTHOMAS108

Yep, that's pretty much how the Custom CutePDF printer works.  Pseudo code:

 

Set registry value "BypassSaveAs" to true
Set registry value "OutputFile" to required path

Set Revit Printer to CutePDF and set settings
Print drawing

Set registry value "BypassSaveAs" to false (so that standard UI use of the printer pops the Save Dialog)
Set registry value "OutputFile" to ""

 

Back in the day we found that the CutePDF option was cheaper especially if you buy a site licence.

Message 5 of 9
imaliasad
in reply to: RPTHOMAS108

Thanks for the reply @PTHOMAS108.

Now, the prompting got turned off and now I'm facing another issue. The issue is the Adobe Printer got stuck while creating the pdf file. See the below image: The PDF creating progress bar seems frozen, I waited for more than 10 mins and it didn't create the pdf file.

Can anybody provide any fix? Appreciate any suggestion.adobe pdf error.PNG

 

 

 

Message 6 of 9
RPTHOMAS108
in reply to: imaliasad

You'll probably get better knowledge and support for this on the Adobe forums.

 

I recall something similar happening.

Message 7 of 9
imaliasad
in reply to: RPTHOMAS108

Thank you for your reply, I'm hoping to get some support from Adobe forum. Will share the solution, once it get fixed. 

 

Cheers,

Ali

Message 8 of 9
WorldDue
in reply to: imaliasad

Any solution found?

Message 9 of 9
jeremy_tammik
in reply to: WorldDue

Yes. Switch to Revit 2022 or Revit 2023 and use the built-in Revit PDF export functionality instead of some external driver:

  

https://thebuildingcoder.typepad.com/blog/2021/04/whats-new-in-the-revit-2022-api.html#4.2.3.1

  

Otherwise, please refer to @RPTHOMAS108  explanation above: it is a driver issue

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community