Print to PDF using PDF995

Print to PDF using PDF995

Anonymous
Not applicable
3,013 Views
3 Replies
Message 1 of 4

Print to PDF using PDF995

Anonymous
Not applicable

I have installed PDF995 print driver and trying to hook it up when printing from Revit API.

The problem is, that Revit gives the following warning:

 

"PDF995 cannot be used with Main Drawings print settings. The <in-session> print settings will be used".

 

 

How can I suppress this warning?

 

Here is my code:

 

foreach (ViewSheet sheet in new FilteredElementCollector(openDoc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>())
{
    var viewType = GetViewType(sheet);
    if (viewType == ViewType.Unknown)
    {
        continue;
    }
    using (var transaction = new Transaction(openDoc, "save setting"))
    {
        transaction.Start();

        var printManager = openDoc.PrintManager;
        printManager.SelectNewPrintDriver("PDF995");
        printManager.PrintToFile = true;

        var setting = printManager.PrintSetup.InSession;
        var failOptions = transaction.GetFailureHandlingOptions();
        failOptions.SetFailuresPreprocessor(new WarningSwallower());
        transaction.SetFailureHandlingOptions(failOptions);

        var paperSize = GetPaperSize(sheet);
        setting.PrintParameters.PageOrientation = paperSize.PageOrientation;
        ...
        printManager.PrintSetup.CurrentPrintSetting = setting;
        printManager.PrintSetup.SaveAs("Tempsetting" + plotSettingsNumber.ToString());

        printManager.Apply();
        if (printManager.SubmitPrint(sheet))
        {
            // Success

            plotSettingsNumber++;

            ImageExportService.ExportSheet(sheet, pdf.PngFilePath, true);
        }
        else
        {
            // Failure
        }
        transaction.RollBack();
    }
}

 

I'm using WarningSwallower, as suggested in this post http://thebuildingcoder.typepad.com/blog/2016/09/warning-swallower-and-roomedit3d-viewer-extension.h..., but it doesn't seem to work here.

 

I appreciate any help.

 

 

0 Likes
Accepted solutions (1)
3,014 Views
3 Replies
Replies (3)
Message 2 of 4

RPTHOMAS108
Mentor
Mentor
Accepted solution

That usually appears once when you create an instance of the PrintManager, depending on how it has previously been used.

 

From then on it is more to do with the order you do things. The error of this nature usually occurs because the driver doesn't support a named paper form size or output location etc.

 

So you have to check the size you want to switch to is supported by the printer first. Doesn't matter if two defined sizes have the same dimensions but different names, it goes by the name. Virtual printers generally list the sizes defined by the print server in addition to those specifically added for it.

 

Knowing you are going to create an instance of the PrintManager (which must only be created once during a print process) you can immediately before and after attach/remove an event handler for the Application.DialogBoxShowing event. With the event args of this you can call .OverrideResult(1)

 

 

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

I'm setting paper size, as shown below (omitted that part of the code, as not important):

 

foreach (Autodesk.Revit.DB.PaperSize size in printManager.PaperSizes)
{
    if (size.Name == paperSize.SheetSize)
    {
        try
        {
            setting.PrintParameters.PaperSize = size;
        }
        catch (Exception ex) {
        }
        break;
    }
}

So, I'm assigning paper size, which is supported by the current PrintManager.

 

You've mentioned, that PrintManager should be created only once and immediately before print operation. How do I create an instance of PrintManager?

I'm using the instance from Autodesk.Revit.DB.Document -> PrintManager, which is also being used for DWF export.

0 Likes
Message 4 of 4

Anonymous
Not applicable

I have managed to solve the problem by swapping the order of PDF print and DWF export.

In my case it doesn't matter which one goes first.

But would be nice, if somebody could explain how to use PDF printer after DWF export with the same printManager.

0 Likes