not able to save print to pdf file

not able to save print to pdf file

2020mme013
Enthusiast Enthusiast
227 Views
1 Reply
Message 1 of 2

not able to save print to pdf file

2020mme013
Enthusiast
Enthusiast

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.

0 Likes
228 Views
1 Reply
Reply (1)
Message 2 of 2

GosponZ
Collaborator
Collaborator

Try this one just change path. You can edit for your need

 

 

'response = MessageBox.Show("Did you change path in this rule?", "Reminder",MessageBoxButtons.YesNo)
'If response = vbNo Then Exit Sub

'iLogicVb.RunRule("SAVE PDF")

'Save PDF with options
'SaveLoc = "C:\"
'FileName = ThisDoc.FileName(True)
'ThisDoc.Document.SaveAs(FileName & (".pdf") , True)
oPath = ThisDoc.Path
PN = iProperties.Value("Project", "Part Number")


'path_and_namePDF = ThisDoc.Pathandname(False)
oFileName = ThisDoc.FileName(False) 'without extension
oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
oDocument = ThisApplication.ActiveDocument
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

 


If oPDFAddIn.HasSaveCopyAsOptions(oDataMedium, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = 1
oOptions.Value("Remove_Line_Weights") = 1
oOptions.Value("Vector_Resolution") = 400
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
'oOptions.Value("Custom_Begin_Sheet") = 1
'oOptions.Value("Custom_End_Sheet") = 4
End If

 

'Set the destination file name
oPath = "c:\"
'oPath = InputBox("Replace Path","New Path")

oDataMedium.FileName = oPath & "\" & PN & ".pdf"
'Publish document
'Confirmation message
MessageBox.Show("PDF SAVED TO: " & oDataMedium.FileName, "PDF Saved", MessageBoxButtons.OK)


On Error Goto handlePDFLock
'Publish document.
Call oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)


'--------------------------------------------------------------------------------------------------------------------


Exit Sub


handlePDFLock:
MessageBox.Show("PDF could not be saved, most likely someone else has it open", "No PDF for you " & ThisApplication.GeneralOptions.UserName & "!")
Resume Next


handleXLSLock:
MessageBox.Show("No XLS", "iLogic")
Resume Next

 



0 Likes