|
|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
本帖最后由 wangxu_1018 于 2015-7-8 12:02 编辑
: G* D3 Z9 [% Q) Q0 O) W( R; J; h) h' ]0 \9 W7 W' @4 f) p- e
版主及各位朋友:中午好!
3 q v2 p: j( H7 d5 R5 N" o" Q! l
" C" r9 u% \6 n# N3 D, T) G0 _7 Q CAD版本:AutoCAD Electrical 20107 v* {0 I7 G3 @6 l' n
- }5 F- j& M! ?9 L2 N& P; K 我在vb程序中处理dwg打印为pdf时遇到如下问题,希望得到各位的帮助,谢谢!
. ^% _* N5 M+ z3 d 问题如下:
6 x/ b# q$ p! ]8 ]) D7 j 我之前开发了一段程序(见下面嵌入的代码),通过 Acade - DWG To PDF.pc3 打印为pdf文件,生成pdf没有问题,但是生成的pdf文件一直也没有去打印为纸质版,最近需要打印时发现原DWG文件中引用的图片(公司logo)及由Excel中copy到DWG中的表格(好像也是图片了)出现模糊的情况。# X8 q5 u' v" z$ o+ A& T: n
4 Q9 Y* {/ E% f$ X
上述问题不管的手动选取“ Acade - DWG To PDF.pc3”打印机还是程序均有问题。后来尝试手动选取“Adobe PDF”打印,生成的PDF是没有问题。4 B0 Y( r$ k) i, s
, Q5 v3 @- {" s& b* @
后来尝试有程序实现“Adobe PDF” 去打开PDF,但有遇到”仅依靠系统字体;不使用文档字体(N)“的问题。
g- L1 A$ h% u8 o+ x9 h2 j 尝试去修改打印机首选项,但Adobe PDF 打印机的首选项中没有找到关于”仅依靠系统字体;不适用文档字体“的设置(不确定是否版本问题)
) p$ @& ]7 h& _. `( l# i k9 f! I+ q2 \+ [+ {% E6 G+ e3 l
问题汇总:
$ R- Q$ f6 t/ r7 b7 b 1、 “Acade - DWG To PDF.pc3”打印机 是否可以处理图片模糊的问题?
" D4 {, _ B: E. ]9 Z. ?1 p* g 2、 “Adobe PDF” 打印机如何设置字体?& n2 e) E- U( Y6 S: C
注:由于对AutoCAD也只是初学,对很多CAD本身的应用也还不是很熟悉,开发这块就更差了 还希望各位给予帮助。- '---------------------------------------------------------------------------------------5 y% Z4 ?/ F7 G
- ' Procedure : CreatePDF
/ D8 i& x$ \- D" C/ C - ' DateTime : 2013-11-20! b% c9 ~: m* e* P8 B0 i! N: s
- ' Author : xwang. i1 v! D7 B% P4 `
- ' Purpose : CAD中DWG图纸导出PDF文件
0 O9 c7 S2 R6 }; Q0 R' d1 B3 ? - ' param : acadDoc: AcadDocument
+ c' |3 a! G+ Q+ D4 u2 y - ' : filename: DWGFile! @ x& a4 R* [/ Z$ h
- ' : strPdfFile PdfFile
4 {+ ?3 u' ]5 c* C" Z3 X2 \ - ' : ConfigName: Acade - DWG To PDF.pc33 q* K' T. n# G6 s* j9 G
- '---------------------------------------------------------------------------------------
2 E5 v4 n8 @+ H$ b6 q1 i( I' w - Public Function CreatePDF2(acadDoc As AcadDocument, filename As String, strPdfFile As String, ConfigName As String) As Integer; R* Z4 R8 i0 ]% ` s
# h. v k1 A f: T4 Z ^- w0 l8 T- Dim PtConfigs As AcadPlotConfigurations
, Z6 g0 j) D: G - Dim PlotConfig As AcadPlotConfiguration
$ f$ m/ j# h) R' X0 b - Dim PtObj As AcadPlot
+ ^. K) E, x9 J/ X/ u3 L. \& S$ X - Dim BackPlot As Variant
6 u' L j4 Z( l( V' n9 ~. }1 N -
3 [+ y; @+ a; N! `, E. U, t6 f - Dim ent As AcadEntity 'Object
9 {* u" {4 p7 e7 X - Dim blockRef As AcadBlockReference! P' N6 S& _' _+ S' Y# O
- ( e' \' R8 w* {$ D
- On Error GoTo ErrExit- |. P4 x2 L$ H6 z+ p* {
- u4 w, b" t( @1 C
- Debug.Print "CreatePDF ------------------------------------------------->"
& [# k; s. I& Y) v: ^ - Debug.Print "打印机:" & ConfigName
" S/ M6 Q$ ~; o2 w0 _- t - For Each ent In acadDoc.ModelSpace
, F0 ^9 {( ~8 p, q$ Z7 L. O - If TypeOf ent Is AcadBlockReference Then; K1 g: L" n; J9 t1 f& ~
- DoEvents
- E- l+ d0 W/ y% y3 O- Q# O( S - Set blockRef = ent' H, `# Y6 X0 z+ C) l) J
- If blockRef.Name = "ACE A3块" Or blockRef.Name = "ACE A4块" Then
# c2 X3 f8 ?' C; p - : r' B; F8 W9 w8 Y$ S
- Debug.Print "块名称:" & blockRef.Name
2 a) ?' H" C3 [9 L4 e a% r. G - 3 `2 ^+ \: z$ m" K
- '块引用的插入点
; ]- L+ V; _9 r9 s - Dim insertPoint As Variant
& w* d7 \6 D6 v - insertPoint = blockRef.InsertionPoint
# c" Y" O4 v* C% Q* r! Y3 c* } - '放大比例
& r$ K8 d/ l3 j n - Dim xScale, yScale As Integer
* \4 {5 P5 u; n- e8 O2 G% q# l2 H! D - xScale = blockRef.XScaleFactor
! {7 q0 ]8 G! N" B - yScale = blockRef.YScaleFactor W. o: q) O' D
-
' T' |- v) p; B) G/ ~. @' z - acadDoc.ActiveLayout.ConfigName = ConfigName '"Acade - DWG To PDF.pc3"# ^( U0 t v% ]/ G6 V8 A' v
- Set PtObj = acadDoc.Plot
: J. v- ?4 E0 \# Y - Set PtConfigs = acadDoc.PlotConfigurations/ {" }, j* o2 | }- z r# \
- 6 w* Q8 W5 N u6 G, K& y+ B
- PtConfigs.Add "PDF", False8 H) ^6 Y7 W, a2 e' q7 `
- Set PlotConfig = PtConfigs.Item("PDF")
e; J8 |7 L/ z+ L1 O - PlotConfig.StandardScale = acScaleToFit* q# M7 D2 \5 `! M
-
* S2 ^& n4 ^) ^( Y3 n8 J2 V5 y - PlotConfig.ConfigName = ConfigName '"Acade - DWG To PDF.pc3"
6 e) s' P) E" v3 Q" k - 'ANSI_A_(8.50_x_11.00_Inches)* \3 j1 e+ z# y5 T. [* V
- PlotConfig.RefreshPlotDeviceInfo8 C' h! R$ C s% W7 B2 X+ m1 \1 h, Q
/ s! ?4 s" e, ?. N! g- Debug.Print "After打印样式:" & acadDoc.ActiveLayout.StyleSheet8 [: |& s# |. F
- Debug.Print "After图纸尺寸:" & acadDoc.ActiveLayout.CanonicalMediaName
9 u/ B3 s' O- s! ? -
8 @. u1 y3 |" d; {+ Q8 V - acadDoc.ActiveLayout.StyleSheet = "monochrome.ctb" '黑白样式
* e0 T; K; j" B; [8 B$ I# S - : @' o. k: y' G9 V
- '使用图形文件的线宽
' z% u7 v) `, ? U. l3 ~& n" j - PlotConfig.PlotWithLineweights = True
9 C3 Y' p9 q/ y% d2 B+ S1 J! R - '是否启用打印样式
( O$ u9 u6 ^1 }7 l0 g0 S - PlotConfig.PlotWithPlotStyles = True0 v1 g/ }" v$ [1 F; o
3 g( G( E) `9 d6 J& G- R- Z- '宽高基数
6 n8 Q$ T) k t3 X9 a* ?: h: _ - Dim width, height As Double) [9 r9 u1 w2 Z5 q( E
- If blockRef.Name = "ACE A3块" Then/ u5 H7 z5 a3 ]
- width = 420) W) J; Z% w/ ?0 a* D
- height = 297
: S6 |# {6 a; F( N" O - acadDoc.ActiveLayout.PlotRotation = ac90degrees" Q9 W: g6 H" }$ }% |
- acadDoc.ActiveLayout.CanonicalMediaName = "ISO_expand_A3_(297.00_x_420.00_MM)"
5 I3 B) L3 N- ?3 a& P - ElseIf blockRef.Name = "ACE A4块" Then/ _" G% y2 D& j0 K3 n+ L
- width = 210
& y& ?; @0 U7 g - height = 297( S# `5 b- m" T* c
- acadDoc.ActiveLayout.PlotRotation = ac0degrees
6 i; O# o7 ^1 c, r, z' S; N* z - acadDoc.ActiveLayout.CanonicalMediaName = "ISO_expand_A4_(297.00_x_210.00_MM)"2 y9 l/ f2 w) }. u, r% @" W
- End If0 T: Y6 w6 u+ v1 j" f, H1 Z
- 4 J: d: l: |* S' N- I
- '打印区域6 _- }* z: j7 ?$ E) S) g
- Dim UpperRight(0 To 1) As Double, LowerLeft(0 To 1) As Double: j- O. h+ T. ?' z/ ^ R+ y
- LowerLeft(0) = insertPoint(0)7 j' Y9 c/ n3 w6 O! X
- LowerLeft(1) = insertPoint(1)+ N" @* J& H% h
- UpperRight(0) = insertPoint(0) + width * xScale: E4 X8 O M8 X# s3 Y
- UpperRight(1) = insertPoint(1) + height * yScale
- i+ V/ D6 M+ m$ _ -
4 N. o1 E* w! V8 ^0 z6 X - '设置定义要打印的布局范围的坐标& Q6 X! k1 c* E+ D! `5 R1 V
- acadDoc.ActiveLayout.SetWindowToPlot LowerLeft, UpperRight) r2 [9 X0 B- X) ^7 l
- '指定布局或打印配置的类型
. P% D4 i0 |4 {+ ?; r( J5 s4 Z+ o0 I - acadDoc.ActiveLayout.PlotType = acExtents0 @7 \0 N8 a3 Q2 u7 j: H( c; h) U
- ( t- m% n( B1 X2 V. Q$ }+ T, j
- BackPlot = acadDoc.GetVariable("BACKGROUNDPLOT")
% P8 }, X/ G0 o7 m' @# C - acadDoc.SetVariable "BACKGROUNDPLOT", 0
4 u, \8 f: f5 O2 U, M5 t% C - PlotConfig.RefreshPlotDeviceInfo
5 p4 D7 l# m) \1 }& p4 Z1 k& @ - 1 w6 X, w* M# e) f6 I5 B
- Debug.Print "Befor打印样式:" & acadDoc.ActiveLayout.StyleSheet
! w2 {- T; {& i7 O0 F/ k/ D - Debug.Print "Befor图纸尺寸:" & acadDoc.ActiveLayout.CanonicalMediaName
/ L8 \6 ~3 j* {1 p - Debug.Print "图形方向:" & acadDoc.ActiveLayout.PlotRotation$ x0 G d( q9 E: o2 o
- Debug.Print "打印机:" & acadDoc.ActiveLayout.ConfigName N* @2 \( m) }" }# g3 q2 u
- , Y* A; y( H; M# d" @6 K- O
- strPdfFile = strPdfFile 'Replace(acadDoc.FullName, "dwg", "pdf")
6 m( ?6 m2 y& g* v5 d4 Z - Debug.Print "输出位置:" & strPdfFile
8 o2 I' T1 q5 `* o* j& I4 P! ^
5 N; h4 V/ x9 `3 [- 'Now you can use the PlotTofile method/ P$ l0 G) w7 J R2 ?2 a3 ~
- If PtObj.PlotToFile(strPdfFile, PlotConfig.ConfigName) Then
I2 l% x `( w$ l1 H% U - Debug.Print "PDF Was Created"
) V6 B# ~( S2 v w1 m# X - Debug.Print "PDF Was Created"
) H2 `* D" C, D2 b! e( E# z& u - Else
% Y" l9 Q& c' Y9 _8 T1 c9 i z - Debug.Print "PDF Creation Unsuccessful!"
3 U) [' V7 T9 m7 B0 X- { - Debug.Print "PDF Creation Unsuccessful!"! u {. y" n- f- c# D; D. X
- End If% I0 Q& [" f6 O: X5 @# \
- PtConfigs.Item("PDF").Delete% N* g/ q( n# f- o x t& D9 I7 _( A
- Set PlotConfig = Nothing6 A' _' z$ @' E" J8 ~) @
- acadDoc.SetVariable "BACKGROUNDPLOT", BackPlot
. v; c* v: x) f- q; P c -
( S; y3 Y' {7 J1 U% v: e8 N - Debug.Print "CreatePDF ok!"& Z/ ~* s) x# b% [' P2 t
- End If. ^/ R& _1 O; b1 B1 T
- End If( {6 h* c/ m4 @
- DoEvents
& S K' M! T' u( Y - Next ent/ D0 m* z, v( a3 K8 E
- Debug.Print "CreatePDF -------------------------------------------------<"
# n2 h1 H: I/ u7 G; H8 j( r - Exit Function
+ ^( N/ w3 A0 {6 _# G3 Q( W, d -
" C$ m/ O1 x: b* l3 q4 M5 U - ErrExit:% M" V' t: @! m8 k0 s4 n. c% R
- CreatePDF2 = -1
" v1 _# }; X7 _! V - Debug.Print "CreatePDF Error:" & Err.Description
6 R& j" s: u: O# P. Q2 w+ w8 e, Z$ ^ - MsgBox "CreatePDF error:" & Err.Description
* R. X: E/ o+ b' V1 ~ - End Function
复制代码 |
-
|