Error message on save print setup: The <In-Session> print setup cannot be saved.
I'm trying to write a pdf-printer with the following code:
using (var transaction = new Transaction(doc, "Print settings")) { transaction.Start(); try { var printManager = doc.PrintManager; var currentPrintSettings = printManager.PrintSetup.InSession; printManager.SelectNewPrintDriver(printSettings.SelectedPrinter); printManager.PrintToFile = true; var printParams = printManager.PrintSetup.CurrentPrintSetting.PrintParameters; printParams.PaperSize = GetPaperSize(printManager.PaperSizes, printSettings.SelectedPaperSize); printParams.PageOrientation = GetOrientation(printSettings.SelectedOrientation); printParams.ColorDepth = GetColor(printSettings.SelectedColor); printParams.ZoomType = ZoomType.Zoom; printParams.Zoom = Convert.ToInt32(printSettings.SelectedZoomLevel); printParams.HiddenLineViews = HiddenLineViewsType.VectorProcessing; printParams.PaperPlacement = PaperPlacementType.Center; printParams.HideCropBoundaries = true; printParams.HideReforWorkPlanes = true; printParams.HideScopeBoxes = true; printParams.HideUnreferencedViewTags = false; printParams.MaskCoincidentLines = false; printParams.ViewLinksinBlue = false; printParams.ReplaceHalftoneWithThinLines = false; printManager.PrintSetup.Save(); foreach (var sheet in elementlist) { var fileLocation = $@"{folderDialog.SelectedPath}\{sheet.Name}.pdf"; DeleteFile(fileLocation); printManager.PrintToFileName = fileLocation; printManager.SubmitPrint(sheet) } transaction.RollBack(); } catch (Exception ex) { transaction.RollBack(); TaskDialog.Show("Error", ex.Message); }
Sometimes this works, but sometimes I get the error message "The <In-Session> print setup cannot be saved.".
What am I doing wrong?
Link copied