|
|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
本帖最后由 wangxu_1018 于 2015-7-8 12:02 编辑
. U; b' h4 W C$ e6 j8 i, P9 U Z% h- \
版主及各位朋友:中午好!* K( ]5 H( L: x3 \* \
8 ^, A2 m5 I4 s6 f
CAD版本:AutoCAD Electrical 2010
, ]) J# T; K2 U2 H/ S9 z I* N
+ j8 }8 x2 f9 O, p 我在vb程序中处理dwg打印为pdf时遇到如下问题,希望得到各位的帮助,谢谢!* n$ `: T. X2 r( \; X! B! X
问题如下:, `( d+ Q* z; w/ p6 G
我之前开发了一段程序(见下面嵌入的代码),通过 Acade - DWG To PDF.pc3 打印为pdf文件,生成pdf没有问题,但是生成的pdf文件一直也没有去打印为纸质版,最近需要打印时发现原DWG文件中引用的图片(公司logo)及由Excel中copy到DWG中的表格(好像也是图片了)出现模糊的情况。5 m1 Q5 e. {# s
' m+ B/ N. c+ ]5 ^( H: p) b7 s
上述问题不管的手动选取“ Acade - DWG To PDF.pc3”打印机还是程序均有问题。后来尝试手动选取“Adobe PDF”打印,生成的PDF是没有问题。
5 b6 t6 Z$ K- H6 W5 O; s$ T6 D- p: k0 l" d% k, m2 e
后来尝试有程序实现“Adobe PDF” 去打开PDF,但有遇到”仅依靠系统字体;不使用文档字体(N)“的问题。
& ?& R5 D# @" v4 K2 z9 ~6 s 尝试去修改打印机首选项,但Adobe PDF 打印机的首选项中没有找到关于”仅依靠系统字体;不适用文档字体“的设置(不确定是否版本问题)9 f- @6 j2 z% m6 `& z' i
' G8 {" I( ]4 ]1 T/ E: ?
问题汇总:
1 }& r! D" u @1 \" W! g 1、 “Acade - DWG To PDF.pc3”打印机 是否可以处理图片模糊的问题?! K4 w6 S7 \" N1 o% V
2、 “Adobe PDF” 打印机如何设置字体?
2 P! U2 E3 b( f/ D0 Q4 \ 注:由于对AutoCAD也只是初学,对很多CAD本身的应用也还不是很熟悉,开发这块就更差了 还希望各位给予帮助。- '---------------------------------------------------------------------------------------, [/ h F9 i& e0 @9 Q
- ' Procedure : CreatePDF
5 C1 D. \7 s; y4 s2 \$ ? K+ R4 z - ' DateTime : 2013-11-20
% W$ n- N- m* o" e: U& Z - ' Author : xwang! ]$ |8 g% ]% ?! _
- ' Purpose : CAD中DWG图纸导出PDF文件 Q0 U- _4 @2 r0 m# n T6 z3 `8 J
- ' param : acadDoc: AcadDocument
% ^7 U/ T. E7 T* I* K3 w$ W - ' : filename: DWGFile$ e4 c; y6 D6 g" e) l
- ' : strPdfFile PdfFile2 B0 D/ M) A" S g
- ' : ConfigName: Acade - DWG To PDF.pc3
6 y# S: I/ f. _& P/ m+ z - '---------------------------------------------------------------------------------------
) Z2 w3 z, F( u - Public Function CreatePDF2(acadDoc As AcadDocument, filename As String, strPdfFile As String, ConfigName As String) As Integer
" z" T7 S# c& N( J& v
/ Z) B$ P$ S5 j: m$ H* Y. n- Dim PtConfigs As AcadPlotConfigurations
3 N) A9 l/ `! `! N. A - Dim PlotConfig As AcadPlotConfiguration! S+ ^5 g+ X- i0 X8 }
- Dim PtObj As AcadPlot, j9 k+ D3 J' U
- Dim BackPlot As Variant
- O' ^' B4 n) G( Y -
% \' T* ?7 Y5 }3 [ - Dim ent As AcadEntity 'Object
3 |7 N+ x1 c: B! w; g. y. V - Dim blockRef As AcadBlockReference
8 N4 F- Y7 Z: l. F -
% H" \% l' }7 b: y' B% ?; E Y - On Error GoTo ErrExit
; y+ l- _) r. w% v+ l k$ ?$ x - 6 A* Y) b; Z$ v: z8 a- m
- Debug.Print "CreatePDF ------------------------------------------------->"- i" i- ?. M/ T, ~# a: l: n! E
- Debug.Print "打印机:" & ConfigName6 r7 A! B% z, p( P; J+ _5 S
- For Each ent In acadDoc.ModelSpace1 ?) N" a% b( s7 r$ p
- If TypeOf ent Is AcadBlockReference Then
; Q+ J4 q2 K- e% B - DoEvents
" W9 d; v$ Z# c - Set blockRef = ent5 s" l) m( S$ s, H9 |. ~" h' @
- If blockRef.Name = "ACE A3块" Or blockRef.Name = "ACE A4块" Then
: z' }6 o4 I* H/ i0 G' [: O
# |& N' O- y4 _% l) [5 R- Debug.Print "块名称:" & blockRef.Name% n b" a' X% X& e1 W5 [
- 5 M' X2 ]2 s1 u( s
- '块引用的插入点
' k |4 t. o' b, `0 o$ N - Dim insertPoint As Variant+ p2 u9 s) l4 ]2 o$ P: q9 ^
- insertPoint = blockRef.InsertionPoint
: v! b( t$ N4 U7 O - '放大比例
6 v0 n3 S8 M0 N+ @ - Dim xScale, yScale As Integer
+ U; F) ]6 Q4 L* J. S - xScale = blockRef.XScaleFactor
! V- I' [) l% o6 j+ \ - yScale = blockRef.YScaleFactor
% a' Y; \: s; o0 h# W - 8 {& I" _" Y2 i
- acadDoc.ActiveLayout.ConfigName = ConfigName '"Acade - DWG To PDF.pc3"
1 e! D6 b8 O5 _+ C L6 c" G - Set PtObj = acadDoc.Plot0 C9 L/ I. I1 Q7 I. d" P" _
- Set PtConfigs = acadDoc.PlotConfigurations2 h" Z/ ?# S# l
- * h9 n6 \: O- k" u9 C) ~
- PtConfigs.Add "PDF", False) m. [4 D& Z) i
- Set PlotConfig = PtConfigs.Item("PDF")
- R8 F3 r) |' U( ?" R - PlotConfig.StandardScale = acScaleToFit
8 Y+ {! M/ [# r# g9 P - / H1 [, e8 Q$ |7 I3 C, ^: P
- PlotConfig.ConfigName = ConfigName '"Acade - DWG To PDF.pc3"! A9 x9 N: k' n) J& @ O# }
- 'ANSI_A_(8.50_x_11.00_Inches), S& t4 g3 V& ~$ V' b
- PlotConfig.RefreshPlotDeviceInfo
7 K5 M+ q. N' s {# g' U" v6 n1 m - ' Y/ Q) e: B. `8 u. i- y
- Debug.Print "After打印样式:" & acadDoc.ActiveLayout.StyleSheet
* P5 H- n) x1 c: E - Debug.Print "After图纸尺寸:" & acadDoc.ActiveLayout.CanonicalMediaName
" ^6 h& N0 |3 o% j6 u - # P8 ]2 w( w3 ^/ m+ n& |% t' s& {
- acadDoc.ActiveLayout.StyleSheet = "monochrome.ctb" '黑白样式
( M# l; D* ~+ a* y) L& t6 q
T9 D l2 x/ C' a$ {- '使用图形文件的线宽3 S' t3 Q! B R) n
- PlotConfig.PlotWithLineweights = True" O5 W$ k. }4 F/ `' R- i" G5 P
- '是否启用打印样式
- V5 u0 W6 X1 m! t8 H8 r9 F - PlotConfig.PlotWithPlotStyles = True, C# u% d, q+ S1 |! F7 s
- ) ? G+ R) J; Q/ Q( H
- '宽高基数
' _1 t% c4 Q5 @- | - Dim width, height As Double$ @2 m1 \4 R- k- M) V
- If blockRef.Name = "ACE A3块" Then
0 O# ~5 W" p4 {8 v) c0 O - width = 4206 l* R" X- j# m+ G" f* f$ l
- height = 297
( |" C& x a5 k% O0 E0 b" e) W - acadDoc.ActiveLayout.PlotRotation = ac90degrees9 C- C/ [6 V8 e! K3 X
- acadDoc.ActiveLayout.CanonicalMediaName = "ISO_expand_A3_(297.00_x_420.00_MM)"9 r/ D# R, ~5 `3 o: S
- ElseIf blockRef.Name = "ACE A4块" Then% X+ L, A; V X; P! R- r
- width = 210" ]% Q# o4 n6 a+ d
- height = 297
5 t5 [6 v4 l! ^& X6 |7 p# | - acadDoc.ActiveLayout.PlotRotation = ac0degrees
8 e$ n3 X0 V6 t# w- M$ G. v. ] - acadDoc.ActiveLayout.CanonicalMediaName = "ISO_expand_A4_(297.00_x_210.00_MM)": @! e9 ~ ?% k; K) o( m' R7 | h
- End If# s D4 T; k; x3 u) E4 F. _! A
-
4 U5 g# {+ K+ A* J8 D - '打印区域* S# x1 e2 r* A5 S$ Q4 f
- Dim UpperRight(0 To 1) As Double, LowerLeft(0 To 1) As Double0 D" G& \0 ^5 l" ]* |
- LowerLeft(0) = insertPoint(0)
5 p2 O4 L0 n, Z0 }5 |, c9 g - LowerLeft(1) = insertPoint(1)
1 T9 m/ p5 x; |& m6 O& i. L - UpperRight(0) = insertPoint(0) + width * xScale3 K# q+ e! a. |6 m) D3 @
- UpperRight(1) = insertPoint(1) + height * yScale
; V1 J6 W" M1 i0 T - ) c! H+ q8 V0 D$ H A& {) h5 D* v
- '设置定义要打印的布局范围的坐标0 B ~6 H) k9 n& W; z
- acadDoc.ActiveLayout.SetWindowToPlot LowerLeft, UpperRight
$ y; B5 e* U1 A& `3 i - '指定布局或打印配置的类型
8 P6 i; N4 r$ X& y3 [" j$ l2 `8 N - acadDoc.ActiveLayout.PlotType = acExtents
) x( Y2 [: `8 K: k2 ~ -
3 I8 d- Q+ w1 B5 o) ^! |3 r# j - BackPlot = acadDoc.GetVariable("BACKGROUNDPLOT")
" m2 w& S+ O- P6 o: T6 f - acadDoc.SetVariable "BACKGROUNDPLOT", 08 B- `, P% z8 {# K \" w
- PlotConfig.RefreshPlotDeviceInfo
6 ^( \* P' C* u, Y# ? - ; o/ A: W! {: \ @& D4 _
- Debug.Print "Befor打印样式:" & acadDoc.ActiveLayout.StyleSheet$ P; ]' M& a2 N! n9 ^8 O+ O
- Debug.Print "Befor图纸尺寸:" & acadDoc.ActiveLayout.CanonicalMediaName
' h! \9 A6 @6 o; s - Debug.Print "图形方向:" & acadDoc.ActiveLayout.PlotRotation
- f* [; c7 f4 a/ }" H - Debug.Print "打印机:" & acadDoc.ActiveLayout.ConfigName
4 R1 f8 m, l7 Z/ H6 o. ?+ d; a8 V+ n -
: G7 ]! y: F/ t9 c5 l - strPdfFile = strPdfFile 'Replace(acadDoc.FullName, "dwg", "pdf")
; g D5 S0 b1 n9 ?7 i0 a4 k5 X - Debug.Print "输出位置:" & strPdfFile% q4 Z, x% Y: X+ s2 M# ~4 l
- 5 N6 @; j& X1 S& T! x6 B# w9 b. u; p; q
- 'Now you can use the PlotTofile method
" ?: u W" K) W3 I8 ~/ \ - If PtObj.PlotToFile(strPdfFile, PlotConfig.ConfigName) Then
$ D! z5 K+ }8 u/ u! `+ m2 D - Debug.Print "PDF Was Created"1 E C4 J2 O. N2 D0 U7 ^; u
- Debug.Print "PDF Was Created"
4 }& n9 J5 [4 a' X - Else
@3 G. K D/ l7 S& |, j - Debug.Print "PDF Creation Unsuccessful!"$ Q# C a. i; s9 V* \" ^- Q
- Debug.Print "PDF Creation Unsuccessful!"( S& P9 d5 `, d j6 J8 x/ E' E' r
- End If1 k9 c$ X8 ]5 X* m7 u# k, S
- PtConfigs.Item("PDF").Delete
- f3 T( ~& C, t( \' |5 v6 i7 D - Set PlotConfig = Nothing
# G# F' c4 m- c4 R1 v - acadDoc.SetVariable "BACKGROUNDPLOT", BackPlot
6 _( u0 H8 w7 R) M - + P4 v! I+ C# j% A! H; x! p- q
- Debug.Print "CreatePDF ok!"
" ^& I0 {) h1 ~+ y1 N# z3 T - End If& g a0 V( |' n3 t
- End If
- v. l% _/ g( @- E - DoEvents5 A, M1 _2 U( v& L' h3 Q
- Next ent
+ b* r2 s& o. A7 G! ~# k - Debug.Print "CreatePDF -------------------------------------------------<"
# z. q2 x2 r$ X4 H o6 T7 O. w - Exit Function$ c9 [+ \# i" Q- C8 e8 Z
-
0 k d- U( t- u* G- y- O$ q - ErrExit:* B$ V5 p6 ?8 [4 B9 U; ~
- CreatePDF2 = -1
2 U5 @# S9 g) w) a2 X4 p$ @% C - Debug.Print "CreatePDF Error:" & Err.Description
* G$ w B& s4 f( L - MsgBox "CreatePDF error:" & Err.Description) |2 m& h/ N' p/ j6 x
- End Function
复制代码 |
-
|