Exported PDF impossible to open

Exported PDF impossible to open

dibujocad
Enthusiast Enthusiast
640 Views
5 Replies
Message 1 of 6

Exported PDF impossible to open

dibujocad
Enthusiast
Enthusiast

Hi everyone,

I wrote a VBA code to export drawings to PDFs using "drawing print manager".

In the code, I call the method "drawingPrintManager.PrintToFile(FilePath)" to save automatically the exported PDF in an specific folder and with an specific name, since it's the only way I found to manage it.

However, when I try to open the created PDF, it appears a window where it's said that the file is damaged and it's impossible to open it. 

I've read some posts about this topic in this forum, where it's said that this issue happens because "PrintToFile" method creates a Postscript file instead of a PDF file.

Is it possible to solve this issue or to convert this Postscript file into a PDF with VBA code? 

I realized that this issue doesn't happen, when I select manually the folder and the name of the PDF file. But I'd like to avoid this step, and doing it automatically instead.

I've also read that using translator Add-In could be a solution, but it doesn't allow me to print in Grayscale or selecting paper size as options.

 

Thanks in advance!

 

 

0 Likes
641 Views
5 Replies
Replies (5)
Message 2 of 6

Ralf_Krieg
Advisor
Advisor

Hello

 

Install a free PDF tool like PDFCreator which installs a dedicated PDF Printer and print to this one. Otherwise you have to install Ghostscript and use a shell with something similar to

ps2pdf input.ps output.pdf

and invent the wheel for the x-th time.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 6

pball
Mentor
Mentor

You will likely be better off using the export to PDF feature. The code below is directly from the Inventor API help file.

 

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
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 4 of 6

dibujocad
Enthusiast
Enthusiast

Hi,

thanks for your reply.

But it doesn't work printing with PDFCreator. I tried it and I can't still open the created PDF files.

Do you use the same method "PrintToFile(file path)"?

0 Likes
Message 5 of 6

dibujocad
Enthusiast
Enthusiast

Hi,

Thanks for your reply.

The files aren't damaged using the Translator Add-In to export to PDF, however as I wrote before, it doesn't allow me to print in gray colour or selecting paper size.

0 Likes
Message 6 of 6

Ralf_Krieg
Advisor
Advisor

Hello

 

Don't use PrintToFile. Print to the Printer PDFCreator installs.

 

Or, if you use the Translator Addin set this option to print black&white

oOptions.Value("All_Color_AS_Black") = 1

R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes