|
|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
本帖最后由 wangxu_1018 于 2015-7-8 12:02 编辑
* ~5 z' E! f" v3 R3 @1 S
3 C) d! z/ u+ l, W版主及各位朋友:中午好!! D, M7 p5 B* v2 z; E; a
/ _# |. S8 R4 P
CAD版本:AutoCAD Electrical 2010' J9 [* {$ @4 Q& v, G
2 W# e0 g) J" K3 ^2 z; W0 Y 我在vb程序中处理dwg打印为pdf时遇到如下问题,希望得到各位的帮助,谢谢!1 ^+ {/ v/ w2 D6 t; |
问题如下:; x& K9 C$ {( m% k
我之前开发了一段程序(见下面嵌入的代码),通过 Acade - DWG To PDF.pc3 打印为pdf文件,生成pdf没有问题,但是生成的pdf文件一直也没有去打印为纸质版,最近需要打印时发现原DWG文件中引用的图片(公司logo)及由Excel中copy到DWG中的表格(好像也是图片了)出现模糊的情况。$ V6 ~& B9 p" Z$ N. A: z r
' m8 A* p7 A P" M$ S% u
上述问题不管的手动选取“ Acade - DWG To PDF.pc3”打印机还是程序均有问题。后来尝试手动选取“Adobe PDF”打印,生成的PDF是没有问题。
% `# w f( X5 w o! ^4 I; l ?, n
! T* |% w' h% c+ _' c7 }0 M# y 后来尝试有程序实现“Adobe PDF” 去打开PDF,但有遇到”仅依靠系统字体;不使用文档字体(N)“的问题。% N _0 h/ ]" K, A4 d" U2 X+ G
尝试去修改打印机首选项,但Adobe PDF 打印机的首选项中没有找到关于”仅依靠系统字体;不适用文档字体“的设置(不确定是否版本问题)
3 i; K) W# ^) o+ F) }: [. y6 e0 C/ C# ^/ q5 u n
问题汇总:+ g5 Y5 L9 X3 Z& \$ M9 g; e
1、 “Acade - DWG To PDF.pc3”打印机 是否可以处理图片模糊的问题?
# v* L- t7 p$ A: [( } 2、 “Adobe PDF” 打印机如何设置字体?: L9 o6 ?( h. p6 ]4 T
注:由于对AutoCAD也只是初学,对很多CAD本身的应用也还不是很熟悉,开发这块就更差了 还希望各位给予帮助。- '---------------------------------------------------------------------------------------9 \; Z3 }2 H" r( m- d
- ' Procedure : CreatePDF" |: s9 w- _% O5 }" V
- ' DateTime : 2013-11-202 L. v1 ^. g }9 M
- ' Author : xwang: o3 q: P7 F# f
- ' Purpose : CAD中DWG图纸导出PDF文件+ M. ~1 b3 O3 X. m- s
- ' param : acadDoc: AcadDocument
# T0 w; X- q6 V; W5 M4 U; Y# Y - ' : filename: DWGFile" S5 k$ r* @! d; o' M
- ' : strPdfFile PdfFile
+ ~$ s1 D4 p' K0 L! p& O: |4 N' {/ N - ' : ConfigName: Acade - DWG To PDF.pc3
$ n* t7 ~0 t- i" _' z1 w2 s4 u - '---------------------------------------------------------------------------------------
3 Z- _# A( S; {% R, N - Public Function CreatePDF2(acadDoc As AcadDocument, filename As String, strPdfFile As String, ConfigName As String) As Integer
! e1 D( X" l8 @9 _4 c
9 j, E5 {# C/ y5 i/ a- Dim PtConfigs As AcadPlotConfigurations8 l0 r, ?- ~3 q# w9 i8 I6 h
- Dim PlotConfig As AcadPlotConfiguration
& Y3 t& T, _# D, S* o - Dim PtObj As AcadPlot/ Z/ r2 Z( [8 t! D. ~% W* j# B" N
- Dim BackPlot As Variant) t n5 ^3 I6 \& K" z
-
- h7 b* B( _2 @) h - Dim ent As AcadEntity 'Object
, ]0 D# J0 O6 ?0 N, S - Dim blockRef As AcadBlockReference* _8 x8 b r, p3 e% w
-
% ^7 d; `# }1 x7 G! t - On Error GoTo ErrExit
$ K% o3 C. [9 f+ `$ H0 q
3 ^8 h9 S& p5 i9 o" X, a- Debug.Print "CreatePDF ------------------------------------------------->"
9 T; r6 I4 l! @ - Debug.Print "打印机:" & ConfigName
# b( a& P3 _- B! i$ ~' o8 C - For Each ent In acadDoc.ModelSpace1 `2 Q# g; y) _/ |1 h p y! M
- If TypeOf ent Is AcadBlockReference Then( z$ P+ g5 J5 ^" T
- DoEvents7 x6 P' h2 u3 Y: Z6 l2 U; M
- Set blockRef = ent
3 ]( y- S0 ^( f - If blockRef.Name = "ACE A3块" Or blockRef.Name = "ACE A4块" Then7 d# c8 B( H7 P7 S% o# }' Y7 C
. _' O( M- ]/ h8 o* Y- Debug.Print "块名称:" & blockRef.Name1 I/ _0 W$ a# D
- 4 y6 I0 V2 r _5 J5 Q- a; n
- '块引用的插入点) t0 W" D, J! Z9 L& l9 z- R3 ]2 F
- Dim insertPoint As Variant& i. a; @0 T2 G$ ]6 S
- insertPoint = blockRef.InsertionPoint
# c2 @7 d5 P& S+ j - '放大比例# x4 O+ `+ B: i5 g
- Dim xScale, yScale As Integer
, E8 w3 X( k. f$ f9 o - xScale = blockRef.XScaleFactor9 }1 @7 L, E2 C9 f/ X. ~4 K
- yScale = blockRef.YScaleFactor
0 ?' m- h2 t5 ?) ^% ` -
; P1 M/ p. ?4 f9 k- V5 | - acadDoc.ActiveLayout.ConfigName = ConfigName '"Acade - DWG To PDF.pc3"
( d& J1 W+ J) _- F/ E - Set PtObj = acadDoc.Plot" R) Z; G7 U) f, a- ^, v
- Set PtConfigs = acadDoc.PlotConfigurations
# L- F* }$ p' H9 h1 H& _0 \" u# V
. a% _! U! O$ @! r* r& _- PtConfigs.Add "PDF", False; b/ P! A' v: G, N
- Set PlotConfig = PtConfigs.Item("PDF")
3 v; S* M; m( }6 I% }. a' h" Y0 s/ b - PlotConfig.StandardScale = acScaleToFit+ f% W' ~3 _6 F% O% ]8 q5 T3 E
-
! V. _7 _) y0 y5 V- ?: E - PlotConfig.ConfigName = ConfigName '"Acade - DWG To PDF.pc3"
9 t, z; l: b2 I7 U. d4 u - 'ANSI_A_(8.50_x_11.00_Inches): [" S- C, X" G% \4 Z. T
- PlotConfig.RefreshPlotDeviceInfo
% S2 J) C" H' X6 G# S% t5 [: T - _" b; j8 R _1 a
- Debug.Print "After打印样式:" & acadDoc.ActiveLayout.StyleSheet
) Q8 u1 }2 K0 G: N6 M - Debug.Print "After图纸尺寸:" & acadDoc.ActiveLayout.CanonicalMediaName
( V8 J" s7 u( k1 ~2 ~1 ] -
1 G. @4 z$ @! ]) l - acadDoc.ActiveLayout.StyleSheet = "monochrome.ctb" '黑白样式
: J: y3 r2 I* N" W1 b& M - . ~: j5 t1 |' @; ~
- '使用图形文件的线宽+ x+ H; A( ~2 F' V
- PlotConfig.PlotWithLineweights = True
: K: v) b- I+ v, v" ]& J - '是否启用打印样式
, v# G% b, X; J8 K - PlotConfig.PlotWithPlotStyles = True/ p4 i5 C' y+ j# q8 O
- 1 \: D5 n8 E; ~+ W$ x1 I8 a
- '宽高基数
2 Q* U1 Z8 U1 Z5 }& s; o - Dim width, height As Double1 r! w! y1 e G+ k
- If blockRef.Name = "ACE A3块" Then
' {' j: p, d# Q" x: H; L - width = 4204 \* j( q: U% O/ R/ U2 A3 W" m
- height = 297
/ f; `9 o. l. r# t% M - acadDoc.ActiveLayout.PlotRotation = ac90degrees
) M" ~) y6 L8 d% R! y - acadDoc.ActiveLayout.CanonicalMediaName = "ISO_expand_A3_(297.00_x_420.00_MM)": }8 Z/ [1 d4 E5 X. H2 N; c
- ElseIf blockRef.Name = "ACE A4块" Then
, F7 f7 t! ~( q4 H - width = 210
& m; W* I" V) z - height = 297
& D. F4 f+ F$ M, A - acadDoc.ActiveLayout.PlotRotation = ac0degrees! ^* Z0 o% l+ _
- acadDoc.ActiveLayout.CanonicalMediaName = "ISO_expand_A4_(297.00_x_210.00_MM)"6 ^6 L1 a1 @+ D6 ]6 A) Y% z, r
- End If# Z: |2 y$ {- B t; Y! N3 O. g
-
1 d( y. H' L+ L1 L" f - '打印区域6 _$ [7 [' C1 J1 s9 d% W9 g
- Dim UpperRight(0 To 1) As Double, LowerLeft(0 To 1) As Double1 _+ G" x$ r% C: q$ G) B
- LowerLeft(0) = insertPoint(0)
& Z. ^3 w/ Q: R6 m - LowerLeft(1) = insertPoint(1)
! V g8 n# Q8 j8 _* K d+ W2 ~; j - UpperRight(0) = insertPoint(0) + width * xScale! v' o0 i! @+ t
- UpperRight(1) = insertPoint(1) + height * yScale
# {; e, q$ p( a+ I6 L - * S1 \' d- |! D% s$ m! s
- '设置定义要打印的布局范围的坐标# B( ` [5 x7 R5 a( C5 M% j
- acadDoc.ActiveLayout.SetWindowToPlot LowerLeft, UpperRight
8 t: l0 J; N9 x4 I9 k% ^4 C8 k - '指定布局或打印配置的类型. ~* P0 v1 m/ O( ]* p; g& k
- acadDoc.ActiveLayout.PlotType = acExtents
3 n. H" b, ]6 ?+ \/ @4 ^3 \ -
% B( ?. Y" l6 V- x( d* j - BackPlot = acadDoc.GetVariable("BACKGROUNDPLOT"); r) e1 e# e" K: R$ M& N- {
- acadDoc.SetVariable "BACKGROUNDPLOT", 0
6 O7 `% j7 ]. U - PlotConfig.RefreshPlotDeviceInfo
" ~& I$ Z* e$ b6 _9 Z2 q -
! m$ z- m! f- b - Debug.Print "Befor打印样式:" & acadDoc.ActiveLayout.StyleSheet% r2 b( a* D5 s8 n F9 P% v1 ^
- Debug.Print "Befor图纸尺寸:" & acadDoc.ActiveLayout.CanonicalMediaName0 q3 X- L' z9 r$ Y! R$ f( H" O: }
- Debug.Print "图形方向:" & acadDoc.ActiveLayout.PlotRotation
4 Z1 w n5 F0 l- h9 o - Debug.Print "打印机:" & acadDoc.ActiveLayout.ConfigName$ c4 e% ^! [( {& t
- : G7 x9 l" K6 W1 \0 p# z9 M5 P
- strPdfFile = strPdfFile 'Replace(acadDoc.FullName, "dwg", "pdf")
0 {! P% j# w/ b7 S; C - Debug.Print "输出位置:" & strPdfFile
v/ y0 Q+ ~# g G. O+ R( M4 ~
: b% M1 P4 V3 J1 a1 k- j- O4 |- 'Now you can use the PlotTofile method
2 Z5 g% d X% ]7 K0 T) U - If PtObj.PlotToFile(strPdfFile, PlotConfig.ConfigName) Then7 M! X O9 e. n. X
- Debug.Print "PDF Was Created"
, o+ x5 m& `3 b; w/ B' b - Debug.Print "PDF Was Created"
5 K+ p( F6 x7 N/ I: w: ] - Else; g7 ` A& v' X U: b
- Debug.Print "PDF Creation Unsuccessful!"
, ~; q% r2 S( ~( M+ l" {( F - Debug.Print "PDF Creation Unsuccessful!"! U' B; o; s9 m
- End If
8 @+ W9 X! o* G& [0 F+ D - PtConfigs.Item("PDF").Delete
) W% N7 x( @9 P q/ z - Set PlotConfig = Nothing2 p8 h5 y& c7 b2 B( X
- acadDoc.SetVariable "BACKGROUNDPLOT", BackPlot7 N7 ?5 \; p2 X" }
- ) `% Y1 }( O+ c. q
- Debug.Print "CreatePDF ok!"
, Z1 z) z7 a/ V9 s3 \ k9 r" Y* r - End If' a/ y/ c y5 B7 O5 ~7 G* @# T
- End If O/ k( H# K4 H7 `1 b, a# T
- DoEvents
0 @; t& G5 J5 f; Y& ?) C6 t* s - Next ent% [, D1 H3 t+ `/ X+ g
- Debug.Print "CreatePDF -------------------------------------------------<"
; d9 Z# \: k5 F5 F6 U - Exit Function0 H$ c P! u7 e. D8 S+ S0 O& z
- % g, x0 K; H# S
- ErrExit:
2 V/ ~/ G7 h* b/ g* A - CreatePDF2 = -1
. s# ~ \/ c3 Y0 e, X x - Debug.Print "CreatePDF Error:" & Err.Description, g3 |5 _2 ?3 ?/ i
- MsgBox "CreatePDF error:" & Err.Description
; F% E" g1 O! X& b0 i& `- Z: X' ^ - End Function
复制代码 |
-
|