Modifying PrintParameters

Modifying PrintParameters

BobbyC.Jones
Advocate Advocate
774 Views
1 Reply
Message 1 of 2

Modifying PrintParameters

BobbyC.Jones
Advocate
Advocate

I'm having trouble setting PrintParameter values.  The following code runs, and the PrintSetup saves, but the PageOrientation value never changes to Portrait.  What am I missing?  Thanks.

 

 

Document activeDoc = commandData.Application.ActiveUIDocument.Document;

var trans = new Transaction(activeDoc, "PrintSettings");
trans.Start();
activeDoc.PrintManager.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation = PageOrientationType.Portrait;
activeDoc.PrintManager.PrintSetup.SaveAs("MyPrintSettings");
PrintSetting myPs = activeDoc.GetPrintSettingIds(). Select(activeDoc.get_Element). Cast<PrintSetting>(). FirstOrDefault(printSetting => printSetting.Name == "MyPrintSettings");
activeDoc.PrintManager.PrintSetup.CurrentPrintSetting = myPs; trans.Commit();
--
Bobby C. Jones
Accepted solutions (1)
775 Views
1 Reply
Reply (1)
Message 2 of 2

BobbyC.Jones
Advocate
Advocate
Accepted solution

A quick perusal through the ADN knowledge base and the answer is found.  Apparently each call to a Document's PrintManager property generates a new PrintManager object.  It needs to be cached and all calls should be made to the cached object.

 

 

PrintManager pm = activeDoc.PrintManager;

pm.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation = PageOrientationType.Portrait;
--
Bobby C. Jones