PrintManager settings not applying during PDF printing

PrintManager settings not applying during PDF printing

navyabasavaraju01
Contributor Contributor
78 Views
1 Reply
Message 1 of 2

PrintManager settings not applying during PDF printing

navyabasavaraju01
Contributor
Contributor

Dear Experts,

 

I'm facing an issue with the Revit API related to printing sheets programmatically. I'm using the Print Manager class to configure settings such as paper size, orientation, and print range. However, despite applying these settings in code, none of them seem to take effect when the sheets are exported.

Here’s a quick summary of what I’ve tried:

  • Configured Print Manager settings before initiating the print job
  • Verified that the settings are being applied in the code
  • Tried different combinations of settings and print setups
  • Ensured the correct printer and print setup are selected

I’ve tested this with multiple printers including PDF24, Bluebeam, and Adobe PDF, but the issue persists across all of them. The exported sheets ignore the applied settings and revert to default values. I’m not getting any errors, but the output is not as expected.

Has anyone encountered this issue before? Is there something I might be missing in the workflow or a known limitation with Print Manager?

Code snippet is appended below for further investigation.

Any guidance or suggestions would be greatly appreciated!

 

Thanks in advance,
Navya Y.B

        public static void ExportPDFDocument _doc, string printer, List<string> items,
            Int64 eidInt, string pathplusname)
        {
            PrintManager printManager = _doc.PrintManager;
            printManager.SelectNewPrintDriver("Bluebeam PDF");
            printManager.PrintRange = Autodesk.Revit.DB.PrintRange.Select;


            printManager.PrintSetup.CurrentPrintSetting = printManager.PrintSetup.InSession;
            PrintParameters pp = printManager.PrintSetup.CurrentPrintSetting.PrintParameters;

            // ------------------ Settings ------------------

            // Paper size
            string paperSize = items[0];
            Autodesk.Revit.DB.PaperSize chosenPaper = printManager.PaperSizes
                .Cast<Autodesk.Revit.DB.PaperSize>()
                .FirstOrDefault(ps => ps.Name.Contains(paperSize));
            if (chosenPaper != null)
                pp.PaperSize = chosenPaper;

            // Vector / Raster
            string vector_raster = items[1];
            if (vector_raster?.ToLower().Contains("vector") == true)
                pp.HiddenLineViews = HiddenLineViewsType.VectorProcessing;
            else if (vector_raster?.ToLower().Contains("raster") == true)
                pp.HiddenLineViews = HiddenLineViewsType.RasterProcessing;

            // Paper placement + offset
            string paperplacement1 = items[2];
            if (paperplacement1?.ToLower().Contains("center") == true)
                pp.PaperPlacement = PaperPlacementType.Center;

          
            // Fit / Zoom
            string paperorientationfit = items[6];
            if (paperorientationfit?.Contains("fit2page") == true)
                pp.ZoomType = ZoomType.FitToPage;
            else if (paperorientationfit?.Contains("zoom") == true && !string.IsNullOrEmpty(items[7]))
            {
                pp.ZoomType = ZoomType.Zoom;
                pp.Zoom = Convert.ToInt32(items[7]);
            }

            // Orientation
            string paperorientation = items[8];
            if (paperorientation?.Contains("portrait") == true)
                pp.PageOrientation = PageOrientationType.Portrait;
            else if (paperorientation?.Contains("landscape") == true)
                pp.PageOrientation = PageOrientationType.Landscape;
            else if (paperorientation?.Contains("auto") == true)
                pp.PageOrientation = PageOrientationType.Auto;

            // Raster quality
            string rasterquality = items[9];
            if (rasterquality?.Contains("High") == true)
                pp.RasterQuality = RasterQualityType.High;
            else if (rasterquality?.Contains("Medium") == true)
                pp.RasterQuality = RasterQualityType.Medium;
            else if (rasterquality?.Contains("Low") == true)
                pp.RasterQuality = RasterQualityType.Low;
            else if (rasterquality?.Contains("Presentation") == true)
                pp.RasterQuality = RasterQualityType.Presentation;

            // Colors
            string rastercolor = items[10];
            if (rastercolor?.Contains("Black Line") == true)
                pp.ColorDepth = ColorDepthType.BlackLine;
            else if (rastercolor?.Contains("Color") == true)
                pp.ColorDepth = ColorDepthType.Color;
            else if (rastercolor?.Contains("Gray Scale") == true)
                pp.ColorDepth = ColorDepthType.GrayScale;

            // Common controls
            pp.HideScopeBoxes = items[11]?.Contains("true") == true;
            pp.HideReforWorkPlanes = items[12]?.Contains("true") == true;
            pp.HideCropBoundaries = items[13]?.Contains("true") == true;
            pp.HideUnreferencedViewTags = items[14]?.Contains("true") == true;
            pp.ReplaceHalftoneWithThinLines = items[15]?.Contains("true") == true;
            pp.MaskCoincidentLines = items[16]?.Contains("true") == true;

            // ------------------ Apply + Print ------------------

            

            string tempSetName = "TempPrintSet_" + Guid.NewGuid().ToString("N");
            ViewSheetSetting vss = printManager.ViewSheetSetting;
            ViewSheet vs = _doc.GetElement(new ElementId(eidInt)) as ViewSheet;
            ViewSet vSet = new ViewSet();
            vSet.Insert(vs);

            vss.CurrentViewSheetSet.Views = vSet;
            vss.SaveAs(tempSetName);
            printManager.PrintToFile = true;
            printManager.PrintToFileName = pathplusname + ".pdf";
            printManager.CombinedFile = true;
            printManager.Apply();
            try
            {
                printManager.SubmitPrint();
            }
            catch { }

            interloop_class.deleteexistingset(tempSetName, _doc);
            vSet.Dispose();
        }

 

0 Likes
79 Views
1 Reply
Reply (1)
Message 2 of 2

Mohamed_Arshad
Advisor
Advisor

Hi @navyabasavaraju01 

 

As per my understanding printer setup setting is not applied when you print the sheets, As have noticed small thing in your code, that you're getting the PrinterSetup from the PrinterManger but after changing the values of Parameter it is not re-assigned to the CurrentPrintSetting. Kindly check the below code for additional reference.

Reference Code

///Get the Parameter
            InSessionPrintSetting printerSettings = printManager.PrintSetup.InSession;
            PrintParameters pp = printerSettings.PrintParameters;

            // ------------------ Settings ------------------

///Change the Parameters

///Re-Apply to the Printer-Setup
 vss.CurrentViewSheetSet.Views = vSet;
 vss.SaveAs(tempSetName);
 printManager.PrintToFile = true;
 printManager.PrintToFileName = pathplusname + ".pdf";
 printManager.CombinedFile = true;
 printManager.PrintSetup.CurrentPrintSetting = printerSettings;
 printManager.Apply();
 try
 {
     printManager.SubmitPrint();
 }
 catch { }

 

Kindly check it, If not then will think in other perspective.

Or of you want to Export only PDF then you can use the below method 

Export Method (String, IList(ElementId), PDFExportOptions)

 

Hope this will Helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes