Some programmatically generated PDFs render incorrectly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
We have a dedicated Windows 10 workstation with a NVIDIA RTX A4500 GPU that we use to programmatically open Inventor drawings and save a copy of all the sheets to PDF, for storage into our PLM tool. Some drawings end up having malformations with some of their views in the PDF. For example, the masked view should have pink shading but in the PDF the shading is missing, or bubbles have multiple numbers printed on top of each other like this:
We generate the PDFs similar to the "Export to PDF API Sample" in the API documentation.
We have Graphics Setting set to Quality on the Hardware tab in the Application Options.
The workstation is on our network and its display/video goes out to a KVM Over IP. However, we typically use RDP to connect to it. The Windows user session is initiated via RDP to the workstation upon reboots. The PDFs generate correctly if we leave an RDP session open with the workstation. The issue is consistent only with some drawings, and only while an RDP session is not active with the workstation. Many drawings with bubbles and shading render correctly while nobody is connected to the workstation. Our process is run via a scheduled task configured like this:
This is our code simplified to show the essentials for what we are doing. We launch Inventor with the application shown (foreground) and we use the SilentOperation mode to prevent pop-ups from stalling the processing.
string drawingPath = @"C:\Users\enguser\Downloads\12345.idw";
// open Inventor
Type invAppType = Type.GetTypeFromProgID("Inventor.Application");
Application app = (Application)Activator.CreateInstance(invAppType);
app.Visible = true;
// prevents Resolve Link and other prompts
app.SilentOperation = true;
// open drawing
Document doc = app.Documents.Open(drawingPath, true);
// create PDF
// create context
TranslationContext tContext = app.TransientObjects.CreateTranslationContext();
tContext.Type = IOMechanismEnum.kFileBrowseIOMechanism;
// setup options
NameValueMap options = app.TransientObjects.CreateNameValueMap();
options.Add("Publish_All_Sheets", true);
// set the destination file name
DataMedium dataMedium = app.TransientObjects.CreateDataMedium();
dataMedium.FileName = @"C:\Users\enguser\Downloads\12345.pdf";
// create the PDF
translator.SaveCopyAs(doc, tContext, options, dataMedium);
We've tried connecting the workstation to a dedicated monitor to rule out the KVM causing the problem, but we can reproduce the issue (again, with certain drawings known to exhibit the behavior).
We've tried generating the PDFs this way, but we can still reproduce the issue:
// assumes Inventor is already running with a drawing open
Application app = (Application)Marshal.GetActiveObject("Inventor.Application");
Document activeDoc = app.ActiveDocument;
// create PDF
string outputFile = @"C:\Users\enguser\Downloads\12345.pdf";
activeDoc.SaveAs(outputFile, true); // Set the second argument to true to export to a PDF format
We started having the issue around the time we upgraded to Inventor 2020 I think. We've since upgraded Inventor a few times and are on 2023 at the moment, and we've upgraded the hardware and OS (Windows 7 to 10) but still see the issue.
Autodesk support has been unable to assist us because they don't support custom code, so they recommended we ask the community for help...