Search code examples
pdfprintingregistryadobeacrobat

Adobe pdf printer doesn't creating the pdf file


I'm creating an add-in in Revit 2017. The addin will export drawing sheets to PDF files. So, whenever I try to export the sheet a dialog box appears to choose the location to save. I tried to turn off the Prompting programmatically by adding a key to the Windows registry (as described in Adobe documentation page 15-16).

Now, the prompting got turned off and now I'm facing an 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.

PDF file doesn't get generate the progress seems frozen

Edit here's the code that I've written for this purpose. I hope this may help to identify the problem.

public static bool 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.Apply();
        pm.PrintRange = PrintRange.Current;
        pm.Apply();
        pm.CombinedFile = true;
        pm.Apply();
        pm.PrintToFile = true;
        pm.Apply();
        pm.PrintToFileName = path + @"\PDF\" + "abc.pdf";
        pm.Apply();
        SuppressAdobeDialogAndSaveFilePath(path + @"\PDF\" + "abc.pdf");

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

    }
    return true;
}

// Add Registry Key to suppress the dialog box
public static void SuppressAdobeDialogAndSaveFilePath(string value)
{
    var valueName = @"C:\Program Files\Autodesk\Revit 2017\Revit.exe";
    var reg = currentUser.OpenSubKey(key, true);
    var tempReg = reg.OpenSubKey(valueName);
    if (tempReg == null)
    {
        reg = reg.CreateSubKey(valueName);
    }
    reg.SetValue(valueName, value);
    reg.Close();
}

Solution

  • I have explained how you can achieve this by overriding the registry key for Revit.exe process that Adobe uses to generate the next print.

    http://archi-lab.net/printing-pdfs-from-revit-why-is-it-so-hard/

    Please remember that you still have to print via Revit PrintManager, but then you can set the registry keys before every print to control where the files get saved.