Community
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?
So I found a workaround. I don't know if this is a good idea or not, maybe someone can tell me how it should be done.
Instead of
printManager.PrintSetup.Save();
I do this instead:
printManager.PrintSetup.SaveAs("tempSettings");
It feels a bit hacky but seems to work for now at least.
Can't find what you're looking for? Ask the community or share your knowledge.