Universal Document Converter
Product Overview
Download
Purchase
Tutorials
Developer Solutions
Support Service
About fCoder SIA


      Site search
   


      Popular conversions
PDF to JPG converter
Convert Word to PDF
Convert PDF to TIFF
Autocad to PDF converter
Convert Word to JPG
Powerpoint to PDF converter
Printing to PDF
Convert Excel to PDF
Convert DJVU to PDF
Convert Web Page to PDF

      Video tutorials
Show tutorial



Main page>Developer Solutions>Examples>Visual Basic.NET>AutoCAD Drawings to PDF

Converting AutoCAD Drawings to PDF for Visual Basic.NET


'----------------------------------------------------------------------
' 1) Autodesk AutoCAD 2000 or above should be installed and activated on your PC.
'
' 2) Universal Document Converter 5.2 or above should be installed, too.
'
' 3) Open your project in Microsoft Visual Basic.NET.
'
' 4) In Visual Basic main menu press "Project->Add Reference...".
'
' 5) In "Add Reference" window go to "COM" tab and double click into
'    "Universal Document Converter Type Library".
'----------------------------------------------------------------------

Private Sub PrintACADToPDF(ByVal strFilePath As String)
    ' Define constants
    Const acExtents = 1
    Const acScaleToFit = 0
    Dim nBACKGROUNDPLOT, nFILEDIA, nCMDDIA As Long
    Dim objUDC As UDC.IUDC
    Dim itfPrinter As UDC.IUDCPrinter
    Dim itfProfile As UDC.IProfile
    Dim objACADApp As Object
    Dim itfDrawing As Object
    Dim itfLayout As Object
    Dim itfActiveSpace As Object
    Dim AppDataPath As String
    Dim ProfilePath As String
    objUDC = New UDC.APIWrapper
    itfPrinter = objUDC.Printers("Universal Document Converter")
    itfProfile = itfPrinter.Profile
    ' Use Universal Document Converter API to change settings of converterd document
    ' Load profile located in folder "%APPDATA%\UDC Profiles".
    ' Value of %APPDATA% variable should be received using Environment.GetFolderPath method.
    ' Or you can move default profiles into a folder you prefer.          
    AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
    ProfilePath = Path.Combine(AppDataPath, "UDC Profiles\Drawing to PDF.xml")            
    itfProfile.Load(ProfilePath)
    itfProfile.OutputLocation.Mode = UDC.LocationModeID.LM_PREDEFINED
    itfProfile.OutputLocation.FolderPath = "C:\Out"
    itfProfile.PostProcessing.Mode = UDC.PostProcessingModeID.PP_OPEN_FOLDER
    ' Run AutoCAD as COM-server
    On Error Resume Next
    objACADApp = CreateObject("AutoCAD.Application")
    ' Open drawing from file
    itfDrawing = objACADApp.Documents.Open(strFilePath, False)
    ' Change AutoCAD preferences for scaling the drawing to page
    If itfDrawing.ActiveSpace = 0 Then
        itfActiveSpace = itfDrawing.PaperSpace
        itfLayout = itfActiveSpace.Layout
    Else
        itfActiveSpace = itfDrawing.ModelSpace
        itfLayout = itfActiveSpace.Layout
    End If
    itfLayout.PlotType = acExtents
    itfLayout.UseStandardScale = True
    itfLayout.StandardScale = acScaleToFit
    itfLayout.CenterPlot = True
    nBACKGROUNDPLOT = itfDrawing.GetVariable("BACKGROUNDPLOT")
    nFILEDIA = itfDrawing.GetVariable("FILEDIA")
    nCMDDIA = itfDrawing.GetVariable("CMDDIA")
    Call itfDrawing.SetVariable("BACKGROUNDPLOT", 0)
    Call itfDrawing.SetVariable("FILEDIA", 0)
    Call itfDrawing.SetVariable("CMDDIA", 0)
    itfDrawing.Plot.QuietErrorMode = True
    ' Plot the drawing
    Call itfDrawing.Plot.PlotToDevice("Universal Document Converter")
    ' Restore AutoCAD default preferences
    Call itfDrawing.SetVariable("BACKGROUNDPLOT", nBACKGROUNDPLOT)
    Call itfDrawing.SetVariable("FILEDIA", nFILEDIA)
    Call itfDrawing.SetVariable("CMDDIA", nCMDDIA)
    ' Close drawing
    Call itfDrawing.Close(False)
    itfDrawing = Nothing
    ' Close Autodesk AutoCAD
    Call objACADApp.Quit()
    objACADApp = Nothing
End Sub


© fCoder SIA About fCoder SIA | Privacy Policy | Site Map