export drawing to pdf

export drawing to pdf

Anonymous
Not applicable
5,019 Views
20 Replies
Message 1 of 21

export drawing to pdf

Anonymous
Not applicable

Hi I'm using Autocad 2018. Currently we are using PrintToPDF dll to Convert the drawing to PDF. but is is very slow. We want to use AutoCAD built in functionality to save drawing in pdf format and then publish it.

Can anyone suggest how can i do it using C# or Vb code.

Please provide code sample. 

0 Likes
5,020 Views
20 Replies
Replies (20)
Message 2 of 21

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

you can use the plot-api and use "DWG to PDF.pc3" as driver/setting.

There are a lot of threads in the www showing the plot functionality, e.g. like this >>>help/docu<<<

 

Good luck, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 21

Anonymous
Not applicable

Hi i want to use "AutoCAD PDF (High Quality Print).pc3" to create pdf from drawing. Can you please suggest someting. If possible provide some code sample.

0 Likes
Message 4 of 21

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

one step more in search results and I found that >>>click<<< for how to use a special PC3 file.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 21

Anonymous
Not applicable

HI,

I can change the device name by

ThisDrawing.ActiveLayout.ConfigName = "AutoCAD PDF (High Quality Print).pc3" but not Getting any Idea how to generate pdf through default AutoCAD pdf generation.

0 Likes
Message 6 of 21

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

can you use AutoCAD manually and create a plot to that pc3?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 7 of 21

Anonymous
Not applicable

I can save drawing layout in pdf format manually by using AutoCAD 2018 export functionality. And there we also have option to select peer printer to "AutoCAD PDF (High Quality Print)".

Can you suggest some api so that i can use its internal export feature. Although i can see ThisDrawing.Export() function is available, but is does not support PDF.

0 Likes
Message 8 of 21

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> Can you suggest some api so that i can use its internal export feature

As shown in the links (pointing to ready to use samples), please use the PLOT functionality to create PDF's files from your content.

PLOT can be done by API

Export to PDF not (AFAIK)

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 9 of 21

Anonymous
Not applicable

I can set the plot and device name like ThisDrawing.ActiveLayout.ConfigName = "AutoCAD PDF (High Quality Print).pc3", but don't know which method to call to generate pdf for current layout.

0 Likes
Message 10 of 21

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> but don't know which method to call to generate pdf

Look to

 

ThisDrawing.Plot

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 11 of 21

Anonymous
Not applicable

ThisDrawing.Plot is throwing exception and saying "no document". I also tried with setting BACKGROUNDPLOT to disabled, but got no luck.

ThisDrawing.Plot.PlotToFile("c:\temp\" + filename + ".pdf", plotConfig.ConfigName) throwing exception as ThisDrawing.Plot has error. Not able to get how to resolve this.

 

 

0 Likes
Message 12 of 21

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> ThisDrawing.Plot is throwing exception and saying "no document"

Is a document active? Does "ThisDrawing" point to that active document?

 

Can you please show the complete code (all around your plot settings and plot itself) + the drawing you try to plot.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 13 of 21

Anonymous
Not applicable

Yes ThisDrawing is active.

dwg.ActiveLayout.ConfigName = "AutoCAD PDF (High Quality Print).pc3"

dwg.ActiveLayout.PlotType = AcPlotType.acLayout

dwg.ActiveLayout.StandardScale = AcPlotScale.acScaleToFit

Dim plotConfig = dwg.PlotConfigurations

Dim ptcon = plotConfig.Add("PDF")

ptcon.ConfigName="AutoCAD PDF (High Quality Print).pc3"

dwg.SetVariable("BACKGROUNDPLOT", 0)

ptcon.RefreshPlotDeviceInfo()

Dim bool = dwg.Plot.PlotToFile("c:\temp\" + filename + ".pdf", ptcon.ConfigName)

 

Here "dwg" is active drawing referes to ThisDrawing. I have also tried with ThisDrawing as well instead with "dwg" but getting same error.

 

dwg.Plot is throwing exception, says no document

0 Likes
Message 14 of 21

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

that code is working fine on my side in AutoCAD VBA (changes done, especially avoiding late bindung and doing a clean declaration of variables)

 

Const tPlotFileName As String = "C:\TEMP\PDFTEST.PDF"

Public Sub testPDF()
   Dim dwg As AcadDocument
   Set dwg = ThisDrawing
   
   dwg.ActiveLayout.ConfigName = "AutoCAD PDF (High Quality Print).pc3"
   dwg.ActiveLayout.PlotType = AcPlotType.acLayout
   
   dwg.ActiveLayout.StandardScale = AcPlotScale.acScaleToFit
   
   Dim plotConfigs As AcadPlotConfigurations
   Set plotConfigs = dwg.PlotConfigurations
   
   Dim ptcon As AcadPlotConfiguration
   Set ptcon = plotConfigs.Add("PDF")
   ptcon.ConfigName = "AutoCAD PDF (High Quality Print).pc3"
   
   Call dwg.SetVariable("BACKGROUNDPLOT", 0)
   
   Call ptcon.RefreshPlotDeviceInfo
   
   Dim tBool As Boolean
   tBool = dwg.Plot.PlotToFile(tPlotFileName)
End Sub

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 15 of 21

Anonymous
Not applicable

It is not working on my side. Is there any issue with version. I'm working on AutoCAD 2018 and using same version of Interop library.

0 Likes
Message 16 of 21

Anonymous
Not applicable

It is not working on my side. Is there any issue with version. I'm working on AutoCAD 2018 and using same version of Interop library.

 

 Plot = 'DirectCast(dwg, Autodesk.AutoCAD.Interop.AcadDocumentClass).Plot' threw an exception of type 'System.Runtime.InteropServices.COMException'

0 Likes
Message 17 of 21

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> Plot = 'DirectCast(dwg, Autodesk.AutoCAD.Interop.AcadDocumentClass).Plot' threw

>> an exception of type 'System.Runtime.InteropServices.COMException'

That is not a VBA-code, try my code with VBA, if that works then you can use debug to compare the variables between VBA and your VisualStudio project.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 18 of 21

Anonymous
Not applicable

This is what I am hope this helps.

Private PageSetup As String
Private PSCurrent As String


Sub CreatePDF(DWG As AcadDocument)

'********************************************************
'*** import pagesetup and set current pagesetup START ***
'********************************************************
If TB_pdf = True Then
    If OBimperial = True Then
        PageSetup = "N:\Drafting Standard\Templates\Title Blocks\Fabrication\11x17-IMP-2016_r2.dwg"
        PSCurrent = "11x17 PDF-I"
    Else
        PageSetup = "N:\Drafting Standard\Templates\Title Blocks\Fabrication\11x17-Metric-2016_r2.dwg"
        PSCurrent = "11x17 PDF-M"
    End If
    
    DWG.SendCommand ("tilemode 0" & vbCr) ' change drawing to paperspace
    DWG.SendCommand "(load ""N:/Drafting Standard/Tools and Blocks/Lisp/DEL_PAGESETUPS.lsp"") " 'load Lisp
    DWG.SendCommand "DEL_PAGESETUPS" & vbCr 'run lisp to purge all existing pagesetup
    
    DWG.SendCommand ("filedia 0" & vbCr) ' Disable openfile panel
    DWG.SendCommand ".-psetupin" & vbCr & PageSetup & vbCr & "*" & vbCr & vbCr & vbCr 'import all pagesetup
    DWG.SendCommand ("filedia 1" & vbCr) ' enable openfile panel
    
    Dim oPlotConfig As AcadPlotConfiguration
    Set oPlotConfig = DWG.PlotConfigurations(PSCurrent) 'set "11x17 PDF-#" to current
    DWG.ActiveLayout.CopyFrom oPlotConfig

'******************************************************
'*** import pagesetup and set current pagesetup END ***
'******************************************************

'***********************************
'*** EXPORT DRAWING TO PDF START ***
'***********************************
Dim objFile As Object
Dim FileName As String
Dim releasePDF

FileName = Left(lbFrameName, InStrRev(lbFrameName, ".") - 1)
    
    releasePDF = PReleaseFolderInput.Text & "\" & FileName & ".pdf"
    DWG.SendCommand ("DXEVAL 0" & vbCr) ' disable automatic table update
    DWG.SendCommand ("filedia 0" & vbCr) ' disable openfile panel
    DWG.SendCommand ("-EXPORT" & vbCr + "P" & vbCr + "A" & vbCr + releasePDF & vbCr) ' EXPORT DRAWING TO PDF
    DWG.SendCommand ("filedia 1" & vbCr) ' enable openfile panel
    DWG.SendCommand ("DXEVAL 12" & vbCr) ' enable automatic table update
End If
'*********************************
'*** EXPORT DRAWING TO PDF END ***
'*********************************
End Sub
0 Likes
Message 19 of 21

Anonymous
Not applicable

Hi, this is what I am using and seem to work fine for me. Hope this helps

 

Private PageSetup As String
Private PSCurrent As String

Sub CreatePDF(DWG As AcadDocument)

'********************************************************
'*** import pagesetup and set current pagesetup START ***
'********************************************************
If TB_pdf = True Then
    If OBimperial = True Then
        PageSetup = "N:\Drafting Standard\Templates\Title Blocks\Fabrication\11x17-IMP-2016_r2.dwg"
        PSCurrent = "11x17 PDF-I"
    Else
        PageSetup = "N:\Drafting Standard\Templates\Title Blocks\Fabrication\11x17-Metric-2016_r2.dwg"
        PSCurrent = "11x17 PDF-M"
    End If
    
    DWG.SendCommand ("tilemode 0" & vbCr) ' change drawing to paperspace
    DWG.SendCommand "(load ""N:/Drafting Standard/Tools and Blocks/Lisp/DEL_PAGESETUPS.lsp"") " 'load Lisp
    DWG.SendCommand "DEL_PAGESETUPS" & vbCr 'run lisp to purge all existing pagesetup
    
    DWG.SendCommand ("filedia 0" & vbCr) ' Disable openfile panel
    DWG.SendCommand ".-psetupin" & vbCr & PageSetup & vbCr & "*" & vbCr & vbCr & vbCr 'import all pagesetup
    DWG.SendCommand ("filedia 1" & vbCr) ' enable openfile panel
    
    Dim oPlotConfig As AcadPlotConfiguration
    Set oPlotConfig = DWG.PlotConfigurations(PSCurrent) 'set "11x17 PDF-#" to current
    DWG.ActiveLayout.CopyFrom oPlotConfig

'******************************************************
'*** import pagesetup and set current pagesetup END ***
'******************************************************

'***********************************
'*** EXPORT DRAWING TO PDF START ***
'***********************************
Dim objFile As Object
Dim FileName As String
Dim releasePDF

FileName = Left(lbFrameName, InStrRev(lbFrameName, ".") - 1)
    
    releasePDF = PReleaseFolderInput.Text & "\" & FileName & ".pdf"
    DWG.SendCommand ("DXEVAL 0" & vbCr) ' disable automatic table update
    DWG.SendCommand ("filedia 0" & vbCr) ' disable openfile panel
    DWG.SendCommand ("-EXPORT" & vbCr + "P" & vbCr + "A" & vbCr + releasePDF & vbCr) ' EXPORT DRAWING TO PDF
    DWG.SendCommand ("filedia 1" & vbCr) ' enable openfile panel
    DWG.SendCommand ("DXEVAL 12" & vbCr) ' enable automatic table update
End If
'*********************************
'*** EXPORT DRAWING TO PDF END ***
'*********************************
End Sub
0 Likes
Message 20 of 21

Anonymous
Not applicable

Thanks for suggestions. Below code is working.

 

    DWG.SendCommand ("DXEVAL 0" & vbCr) ' disable automatic table update
    DWG.SendCommand ("filedia 0" & vbCr) ' disable openfile panel
    DWG.SendCommand ("-EXPORT" & vbCr + "P" & vbCr + "A" & vbCr + releasePDF & vbCr) ' EXPORT DRAWING TO PDF
    DWG.SendCommand ("filedia 1" & vbCr) ' enable openfile panel
    DWG.SendCommand ("DXEVAL 12" & vbCr) ' enable automatic table update

 

I have one more query. Can you please suggest how to pass PDF Preset value in Export command. I have to set it to "AutoCAD PDF (High Quality Print).pc3".

Currently it is taking default "AutoCAD PDF (General Documentation).pc3".

I can set it from Save as PDF popup and then it will work, when i rerun the code, but by setting from UI, it will work on my machine only. I have to write code for all the users, so it must be from code change.

I am using AUTOCAD 2018.

 

Please suggest.

 

0 Likes