I'm attaching some of the code. I didn't include it all since it might be a bit much to sort through especially if it doesn't apply to the issue. The CreatePDF(bb, 1) subroutine is what is failing to consistently write out a full PDF page.
Dim strFile As String
Dim strFile2 As String
Dim strFile3 As String
Dim i As Integer
Dim dd As Autodesk.AutoCAD.Interop.Common.AcadPlotConfiguration
Dim aa As Autodesk.AutoCAD.Interop.AcadDocument
Try
Export = False
strFile = strNewFolder & "\tmp_Stage1_" & VB.Left(objAutocad.ActiveDocument.Name, Len(objAutocad.ActiveDocument.Name) - 4)
'objAutocad.Preferences.OpenSave.CreateBackup = False
System.Windows.Forms.Application.DoEvents()
Dim bb As Autodesk.AutoCAD.Interop.AcadDocument
bb = objAutocad.ActiveDocument
aa = objAutocad.Documents.Open(Label4.Text)
dd = aa.PlotConfigurations.Item("PDF")
'dd = objAutocad.ActiveDocument.PlotConfigurations.Item("PDF")
bb.Layouts.Item("Model").CopyFrom(dd)
strFile = bb.Name
Application.DoEvents()
Application.DoEvents()
Application.DoEvents()
Application.DoEvents()
'Dim di As Date
'di = Now
'Do While DateDiff(DateInterval.Second, di, Now) < 2
' Application.DoEvents()
'Loop
Dim Plotresult As Integer
' SetAttr(BACKGROUNDPLOT = 1)
CreatePDF(bb, 1)
Try
Catch ex As Exception
blnHasErrors = True
CreateLog(strLogFile, "Custom Error: " & ex.Message)
End Try
System.Windows.Forms.Application.DoEvents()
Do While Dir(Label7.Text & strFile.Substring(0, strFile.Length - 4) & "*.pdf") = ""
Application.DoEvents()
Loop
strFile3 = Dir(Label7.Text & strFile.Substring(0, strFile.Length - 4) & "*.pdf")
Application.DoEvents()
strFile2 = strNewFolder & "\tmp_Stage1_" & strFile.Substring(0, strFile.Length - 4)
Thread.Sleep(3000)
Application.DoEvents()
System.IO.File.Move(Label7.Text & strFile3, strFile2 & ".pdf")
'Rename(Label7.Text & strFile3, strFile2 & ".pdf")
'Rename(Label7.Text & strFile.Substring(0, strFile.Length - 4) & " Model (1).pdf", strFile2 & ".pdf")
Application.DoEvents()
Application.DoEvents()
Application.DoEvents()
UpdatePDF(strFile2 & ".pdf")
Application.DoEvents()
Application.DoEvents()
Application.DoEvents()
Export = True
Try
bb.Close(False)
Catch ex As Exception
End Try
Catch ex As Exception
blnHasErrors = True
lblCurrentFile.ForeColor = Color.Red
CreateLog(strLogFile, "Export: Error Exporting File: (" & strOldFile & ") - " & ex.Message)
End Try
Try
aa.Close(False)
Catch ex As Exception
CreateLog(strLogFile, "Export: Closing ACAD: (" & strOldFile & ") - " & ex.Message)
End Try
Try
dd = Nothing
Catch ex As Exception
CreateLog(strLogFile, "Export: Closing ACAD: (" & strOldFile & ") - " & ex.Message)
End Try
GC.Collect(1)
End Function
Private Sub CreatePDF(ByVal bb As Autodesk.AutoCAD.Interop.AcadDocument, ByVal PlotResult As Integer)
Dim backPlot As Integer
backPlot = objAutocad.ActiveDocument.GetVariable("BACKGROUNDPLOT")
Try
objAutocad.ActiveDocument.SetVariable("BACKGROUNDPLOT", 0)
PlotResult = bb.Plot.PlotToDevice()
Catch ex As Exception
CreateLog(strLogFile, "Custom Error: " & ex.Message)
End Try
End Sub