not able to save print to pdf file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, here is my code
Dim oDoc As PartDocument
oDoc = g_inventorApplication.ActiveDocument
Dim oPath As String = System.IO.Path.GetDirectoryName(oDoc.FullDocumentName)
'-----get PDF target folder path-----
Dim oPDFFolder As String = oPath & "\" & " PDF Files"
'-----Check for the pdf folder and create it if it does not exist-----
If Not System.IO.Directory.Exists(oPDFFolder) Then
System.IO.Directory.CreateDirectory(oPDFFolder)
End If
'-----Search for idw's in folder-----
Dim MyDwgFiles As String()
MyDwgFiles = System.IO.Directory.GetFiles(oPath, "*.idw")
'-----Starts the Loop-----
For Each MyDwgFile As String In MyDwgFiles
g_inventorApplication.SilentOperation = True
Dim partDoc As DrawingDocument = g_inventorApplication.Documents.Open(MyDwgFile, False)
Dim CurrentFilename As String = System.IO.Path.GetFileNameWithoutExtension(partDoc.FullDocumentName)
'-----Filename definition-----
Dim oFileName As String = oPDFFolder & "\" & CurrentFilename & ".pdf"
'-----Publish document-----
Dim oDrgPrintMgr As Inventor.DrawingPrintManager = partDoc.PrintManager
oDrgPrintMgr.Printer = "PDFfill"
'oDoc.Interactive = False
'Dim oDrgPrintMgr As DrawingPrintManager
'oDrgPrintMgr = oDoc.PrintManager
oDrgPrintMgr.AllColorsAsBlack = True
oDrgPrintMgr.ScaleMode = Inventor.PrintScaleModeEnum.kPrintBestFitScale
oDrgPrintMgr.PaperSize = Inventor.PaperSizeEnum.kPaperSize11x17
oDrgPrintMgr.Orientation = Inventor.PrintOrientationEnum.kLandscapeOrientation
oDrgPrintMgr.ColorMode = Inventor.PrintColorModeEnum.kPrintColorPalette
oDrgPrintMgr.NumberOfCopies = 1
oDrgPrintMgr.Rotate90Degrees = False
oDrgPrintMgr.AllColorsAsBlack = False
oDrgPrintMgr.RemoveLineWeights = True
oDrgPrintMgr.TilingEnabled = False
oDrgPrintMgr.PrintToFile(oFileName)
oDrgPrintMgr.SubmitPrint()
partDoc.Close(False)
partDoc = Nothing
g_inventorApplication.SilentOperation = False
Next
g_inventorApplication.Documents.CloseAll(True)
'-----Opens PDF Folder-----
Shell("explorer.exe " & oPDFFolder, vbNormalFocus)
In the above code " oDrgPrinter.Printer = "PDFfill"" on this line I am getting the error like "System.Runtime.InteropServices.COMException: 'Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))'"
If I commented out that line then pdf file is not saving at the destination folder. If anyone has idea please solve this problem.