Export Pdf with C#

Export Pdf with C#

Ruffy85
Collaborator Collaborator
3,290 Views
2 Replies
Message 1 of 3

Export Pdf with C#

Ruffy85
Collaborator
Collaborator

Hello Forum,

 

i have some trouble with my addin function for export Pdf.

 

        public void ExporPDF()
        {
            Inventor.Application InvApp = myCad.InvApp;
            // Get the PDF translator Add-In.

            Inventor.TranslatorAddIn PDFAddin = InvApp.ApplicationAddIns.ItemById["{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}"] as Inventor.TranslatorAddIn;

            //Set a reference to the active document (the document to be published).
            Inventor.DrawingDocument oDocument = InvApp.ActiveDocument as Inventor.DrawingDocument;
            Inventor.TranslationContext oContext = InvApp.TransientObjects.CreateTranslationContext();
            oContext.Type = Inventor.IOMechanismEnum.kFileBrowseIOMechanism;


            // Create a NameValueMap object
            Inventor.NameValueMap oOptions = InvApp.TransientObjects.CreateNameValueMap();

            // Create a DataMedium object
            Inventor.DataMedium oDataMedium = InvApp.TransientObjects.CreateDataMedium();


            // Check whether the translator has 'SaveCopyAs' options
            if (PDFAddin.HasSaveCopyAsOptions[oDocument, oContext, oOptions])
            {
                // Options for drawings...
                oOptions.Value["All_Color_AS_Black"] = 1;
                oOptions.Value["Remove_Line_Weights"] = 1;
                oOptions.Value["Vector_Resolution"] = 400;
                oOptions.Value["Sheet_Range"] = Inventor.PrintRangeEnum.kPrintSheetRange;
                oOptions.Value["Custom_Begin_Sheet"] = 2;
                oOptions.Value["Custom_End_Sheet"] = 4;
         
            }

            string filePath = oDocument.FullFileName;
            filePath = filePath.Substring(0, filePath.Length - 4);
            
            
            
            // Set the destination file name
            oDataMedium.FileName = filePath + ".pdf";


            // Publish document.
            PDFAddin.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium);

The Problem with the Lines of Code is, that when i press the Button inside Inventor Addin, an Error that DWF-File cant be published occurs. But the Translater Guid is the correct one for PDF Publishing.

 

I am wondering because that´s the same function as in the api help documentation. And im realy sure that this works for some weeks perfectly.

 

Any ideas?

 

Thats the VBA Code from the API help

 

Public Sub PublishPDF()
    ' Get the PDF translator Add-In.
    Dim PDFAddIn As TranslatorAddIn
    Set PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")

    'Set a reference to the active document (the document to be published).
    Dim oDocument As Document
    Set oDocument = ThisApplication.ActiveDocument

    Dim oContext As TranslationContext
    Set oContext = ThisApplication.TransientObjects.CreateTranslationContext
    oContext.Type = kFileBrowseIOMechanism

    ' Create a NameValueMap object
    Dim oOptions As NameValueMap
    Set oOptions = ThisApplication.TransientObjects.CreateNameValueMap

    ' Create a DataMedium object
    Dim oDataMedium As DataMedium
    Set oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

    ' Check whether the translator has 'SaveCopyAs' options
    If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then

        ' Options for drawings...

        oOptions.Value("All_Color_AS_Black") = 0

        'oOptions.Value("Remove_Line_Weights") = 0
        'oOptions.Value("Vector_Resolution") = 400
        'oOptions.Value("Sheet_Range") = kPrintAllSheets
        'oOptions.Value("Custom_Begin_Sheet") = 2
        'oOptions.Value("Custom_End_Sheet") = 4

    End If

    'Set the destination file name
    oDataMedium.FileName = "c:\temp\test.pdf"

    'Publish document.
    Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
End Sub
If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Accepted solutions (1)
3,291 Views
2 Replies
Replies (2)
Message 2 of 3

bradeneuropeArthur
Mentor
Mentor
Accepted solution

Change this line of code:

 

oOptions.Value["Sheet_Range"] = Inventor.PrintRangeEnum.kPrintSheetRange;

TO


oOptions.Value["Sheet_Range"] = PrintRangeEnum.kPrintAllSheets;

The range is created afterwards from 2 to 4.

 

The other question:

The message of DWF is correct this is lets say because inventor uses the same translator for the PDF.

So this will display DWF

 

look in the left side bottom of inventor when creating pdf. there you will also see that the DWF is processed... (StatusBar Text)

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 3

Ruffy85
Collaborator
Collaborator

That works thanks.

 

But another question is there an Namevaluemap option to Export all Sheets in separate Files?

 

or can i only solve this issue with iteration through all sheets in oDoc.Sheets?

 

Thanks for help

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes