Inventor API VB.Net PDF Translator creates unusable files

Inventor API VB.Net PDF Translator creates unusable files

J_Dumont
Advocate Advocate
429 Views
1 Reply
Message 1 of 2

Inventor API VB.Net PDF Translator creates unusable files

J_Dumont
Advocate
Advocate

I'm using Inventor 2017 and I created a VB.Net addin that iterates through an assembly, finds drawings, and uses the PDF Translator to create to PDF Files.

However, the pdf files are unusable.

 

Attached are files that were created from the translator and one from INventor directly.

 

Here is the code that creates the pdf files.

 

Public Sub PublishPDF(ByRef DrawingFName As String)

Dim DrawingDocument As Document = invApp.Documents.Open(DrawingFName, False)

Dim PDFAddIn As Inventor.TranslatorAddIn
PDFAddIn = invApp.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
Dim oContext As Inventor.TranslationContext
oContext = invApp.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oOptions As Inventor.NameValueMap
oOptions = invApp.TransientObjects.CreateNameValueMap
Dim oDataMedium As Inventor.DataMedium
oDataMedium = invApp.TransientObjects.CreateDataMedium

If PDFAddIn.HasSaveCopyAsOptions(DrawingDocument, oContext, oOptions) Then
oOptions.Value("All_Color_AS_Black") = My.Settings.PDFAllColorsAsBlack
oOptions.Value("Remove_Line_Weights") = My.Settings.PDFLineweight
oOptions.Value("Vector_Resolution") = My.Settings.PDFVectorResolution
oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets
End If

Dim oDrawName As String ' Use to store drawing filename. Remove path, extension and replace with PDFFoldername and pdf extension
oDrawName = PDFFolderName + "\" + System.IO.Path.GetFileNameWithoutExtension(DrawingFName) + ".pdf"

oDataMedium.FileName = oDrawName

Call PDFAddIn.SaveCopyAs(DrawingDocument, oContext, oOptions, oDataMedium)
DrawingDocument.Close()

End Sub

 

 

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

tonythm
Advocate
Advocate

Hi @J_Dumont 

 

Public Sub PublishPDF_2()
    Dim oWkbk As Workbook
    Set oWkbk = ThisWorkbook
    Dim oSheet As Worksheet
    Set oSheet = oWkbk.ActiveSheet
    Dim oInv As Inventor.Application
    Set oInv = GetObject(, "Inventor.Application")
    Dim oDoc As Document
    Set oDoc = oInv.ActiveDocument
    Dim oDrawing As DrawingDocument
    Set oDrawing = oInv.ActiveDocument
    Dim mpath As String
        mpath = LEFT(oDoc.File.FullFileName, InStrRev(oDoc.File.FullFileName, "\"))
    'Set file name
    Dim oFileName As String
        oFileName = LEFT(oDrawing.DisplayName, Len(oDrawing.DisplayName) - 4)
    Call oDoc.SaveAs(mpath & oFileName & ".pdf", True)
    oWkbk.Save
End Sub
0 Likes