|
|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
本帖最后由 wangxu_1018 于 2015-7-8 12:02 编辑 ' y( B$ U/ Y: `2 E# ?( }7 G
* M- O1 d" ], i
版主及各位朋友:中午好!' F8 C- l2 P; L/ Y( A
7 h% ?/ K+ a+ n' {
CAD版本:AutoCAD Electrical 2010
% k: c% p+ D" g& z; K- _8 Z) b# k# ` s* e( C. J
我在vb程序中处理dwg打印为pdf时遇到如下问题,希望得到各位的帮助,谢谢!
. h2 W7 u# b! x7 { 问题如下:
, K$ {* I+ P. c0 e8 g' a 我之前开发了一段程序(见下面嵌入的代码),通过 Acade - DWG To PDF.pc3 打印为pdf文件,生成pdf没有问题,但是生成的pdf文件一直也没有去打印为纸质版,最近需要打印时发现原DWG文件中引用的图片(公司logo)及由Excel中copy到DWG中的表格(好像也是图片了)出现模糊的情况。
0 `* I% t/ ^6 Z( C+ T0 h/ L
" |9 v9 ]5 X9 o/ x 上述问题不管的手动选取“ Acade - DWG To PDF.pc3”打印机还是程序均有问题。后来尝试手动选取“Adobe PDF”打印,生成的PDF是没有问题。' e# r1 V8 T6 I' T7 r- G) O8 b
* ]3 N5 l) T, J- `1 s4 r! G
后来尝试有程序实现“Adobe PDF” 去打开PDF,但有遇到”仅依靠系统字体;不使用文档字体(N)“的问题。
3 [: E% z) W' y" X9 F3 c/ H 尝试去修改打印机首选项,但Adobe PDF 打印机的首选项中没有找到关于”仅依靠系统字体;不适用文档字体“的设置(不确定是否版本问题); g B' a" U6 U8 A( @6 e$ K1 b
) p( P- } T' V) q z' m 问题汇总:
4 V6 R, K# \+ o$ ] 1、 “Acade - DWG To PDF.pc3”打印机 是否可以处理图片模糊的问题?' Z8 g. O' L8 z2 p1 z
2、 “Adobe PDF” 打印机如何设置字体? i2 F9 X4 g0 c7 Z+ D
注:由于对AutoCAD也只是初学,对很多CAD本身的应用也还不是很熟悉,开发这块就更差了 还希望各位给予帮助。- '---------------------------------------------------------------------------------------# o' i+ H- @+ _' J" o& ? f
- ' Procedure : CreatePDF
, y7 h* j: D: N; A. D7 G - ' DateTime : 2013-11-20 g. u) w. E! L5 }* N
- ' Author : xwang: z- j; g; f9 J, c$ g! i
- ' Purpose : CAD中DWG图纸导出PDF文件& I' n- O' Z9 H' {) S# C
- ' param : acadDoc: AcadDocument' A, M8 i. O1 F/ H0 C
- ' : filename: DWGFile
- M3 D8 N+ l: U5 h - ' : strPdfFile PdfFile
, d) u- R( M- u* ~ - ' : ConfigName: Acade - DWG To PDF.pc3
( A" { o( ?0 Y. Z/ M - '---------------------------------------------------------------------------------------
; A W0 c/ b2 R$ _$ C1 H U - Public Function CreatePDF2(acadDoc As AcadDocument, filename As String, strPdfFile As String, ConfigName As String) As Integer
# D3 y$ C# c: A7 G2 j, o' |* Q5 t+ e - . U3 y* u+ y; b @9 X) E
- Dim PtConfigs As AcadPlotConfigurations3 Y7 e+ S( o. r, `& q! I* ], r
- Dim PlotConfig As AcadPlotConfiguration" M6 D* x2 [! N# T/ k% C$ R1 n
- Dim PtObj As AcadPlot* [& ]" r% ~- @2 f3 X
- Dim BackPlot As Variant/ o1 c9 y9 s7 W3 S9 K1 ?
-
4 v5 N; \2 u4 o6 ? - Dim ent As AcadEntity 'Object
2 t+ M$ y0 y0 Y2 {, b. C, |* g - Dim blockRef As AcadBlockReference
& j9 Q4 a8 ~/ X7 R3 J! Y [' K - 6 ~1 b% B( p9 B: f
- On Error GoTo ErrExit, }% q' x2 x3 |5 i u0 ]; A
+ _( K/ T7 c" Y/ ^5 O: {6 c- Debug.Print "CreatePDF ------------------------------------------------->"
9 t4 k6 _3 C1 Q& ?3 P - Debug.Print "打印机:" & ConfigName7 H) {" `9 P9 L: F
- For Each ent In acadDoc.ModelSpace
, W/ N [7 ]. R2 R- v3 r - If TypeOf ent Is AcadBlockReference Then
- i5 B! ^4 b* q- j5 V I# L. F - DoEvents, x5 ^# e! K* _1 E! {, A/ o$ i
- Set blockRef = ent W3 G" s% l q0 \
- If blockRef.Name = "ACE A3块" Or blockRef.Name = "ACE A4块" Then
& g! ~. Q4 i% a: I - 7 P1 q! N9 N' y6 {/ S7 U+ J. F
- Debug.Print "块名称:" & blockRef.Name7 i A/ b3 ?+ m1 A @2 r! u: H7 _
-
0 J! l y7 u! m5 X. Q - '块引用的插入点
" e& Z! x: k* R- m) M% o( ^ - Dim insertPoint As Variant
( a$ o; p) e' Y1 ` h - insertPoint = blockRef.InsertionPoint
, I- {& ^7 n8 V0 f# f" J' M - '放大比例
. s4 y, b7 N: O& S# Z+ S5 h - Dim xScale, yScale As Integer+ @% k3 a( g8 h7 e2 \
- xScale = blockRef.XScaleFactor
7 s/ j- X3 b" F4 r0 q# V. X# o Q# Y - yScale = blockRef.YScaleFactor; _# S, M, ~! Q
- $ ~6 M2 ?7 d1 R, H( N
- acadDoc.ActiveLayout.ConfigName = ConfigName '"Acade - DWG To PDF.pc3". z8 n% K7 G: n, |% [
- Set PtObj = acadDoc.Plot
& {1 z7 w1 n1 R: G6 N# c) n+ t$ d - Set PtConfigs = acadDoc.PlotConfigurations
, a; o6 ]5 G/ ?! t" p8 `
- E2 `$ @; y3 M/ y2 a9 j- PtConfigs.Add "PDF", False c. q: Z* E; v1 r9 q
- Set PlotConfig = PtConfigs.Item("PDF")+ w* P- {$ D/ v4 ]. p6 h
- PlotConfig.StandardScale = acScaleToFit; M6 A: {7 C9 H
- - z4 q8 q {; [: H- ^+ r5 ]
- PlotConfig.ConfigName = ConfigName '"Acade - DWG To PDF.pc3"
% T$ m: U. C5 }/ U; {2 W - 'ANSI_A_(8.50_x_11.00_Inches)
2 F3 K0 d" ?) h8 I U$ ] - PlotConfig.RefreshPlotDeviceInfo
) m% w# p* [" n" F
' s3 D0 E0 V [) V3 d8 l. g- Debug.Print "After打印样式:" & acadDoc.ActiveLayout.StyleSheet
& u4 P2 I% X9 c% z - Debug.Print "After图纸尺寸:" & acadDoc.ActiveLayout.CanonicalMediaName
2 h F4 M9 W r; P5 q: r/ w3 |* ` -
3 _3 l9 b: O7 R* v" k' E# ~( a - acadDoc.ActiveLayout.StyleSheet = "monochrome.ctb" '黑白样式8 ]& h3 Z9 k$ U1 k* t
- 4 a( |1 h A P/ J; [
- '使用图形文件的线宽
& T" j7 D2 H* L* _# @$ Q& y - PlotConfig.PlotWithLineweights = True0 z: _. i0 }7 V1 r2 B7 E
- '是否启用打印样式% n, j5 v q/ k5 t5 Z8 H& e/ i
- PlotConfig.PlotWithPlotStyles = True
9 P I9 Z( V$ g: L
7 {( s* ]: n4 N- '宽高基数
+ ?: z* `7 r( _ - Dim width, height As Double' h* D' `; T$ G6 i, Z; D
- If blockRef.Name = "ACE A3块" Then
4 L+ r8 g* i+ f' X. o' [ - width = 420
/ }* i: d) H J2 e - height = 297: N2 m2 o- A3 K. F3 N
- acadDoc.ActiveLayout.PlotRotation = ac90degrees5 Y W( D0 J0 x" k
- acadDoc.ActiveLayout.CanonicalMediaName = "ISO_expand_A3_(297.00_x_420.00_MM)"
# i; q' j3 Y6 U9 X - ElseIf blockRef.Name = "ACE A4块" Then- e+ |9 b- `& c6 {) v: A4 g& J
- width = 210
: f' ?& J$ ?# |. ~ L - height = 297
. W" s4 x" U$ u$ q, Y! a5 { - acadDoc.ActiveLayout.PlotRotation = ac0degrees
2 J& I2 e: {2 k0 b2 f( L% p - acadDoc.ActiveLayout.CanonicalMediaName = "ISO_expand_A4_(297.00_x_210.00_MM)"6 I& o2 h. W4 l7 g. B3 H
- End If+ \2 e* @! g6 Y+ T5 H# O
-
' w1 [' h3 x8 Z - '打印区域+ [' m/ Y/ n5 u. S3 E4 ~% ]4 u2 F5 e; z
- Dim UpperRight(0 To 1) As Double, LowerLeft(0 To 1) As Double9 U3 o; k/ I6 Z
- LowerLeft(0) = insertPoint(0)% \5 L$ K* t$ ^2 l8 F$ f
- LowerLeft(1) = insertPoint(1)
" E1 i! U& Y U8 G4 g - UpperRight(0) = insertPoint(0) + width * xScale
4 }+ ^" E, d3 ?, i' `4 L& Z, [ - UpperRight(1) = insertPoint(1) + height * yScale
) g% b* P) U, }, j/ ]( f! x2 ~ - ' S O3 B& T1 o6 F
- '设置定义要打印的布局范围的坐标4 B# J% n8 `3 y7 C3 U$ |
- acadDoc.ActiveLayout.SetWindowToPlot LowerLeft, UpperRight
; k1 q& I6 }! R9 [ - '指定布局或打印配置的类型1 k( ^3 n3 ]& G2 h5 G- S5 c& T
- acadDoc.ActiveLayout.PlotType = acExtents
# K+ n; | d) X! Q9 T, K% g( q -
& m; m6 i, f2 q; I4 t - BackPlot = acadDoc.GetVariable("BACKGROUNDPLOT")
) `2 g, u/ W7 X* Y6 { - acadDoc.SetVariable "BACKGROUNDPLOT", 0
& v" |4 M: I) q" i - PlotConfig.RefreshPlotDeviceInfo
9 {- H& {2 B1 R- A -
- u% d+ _! s9 I; k7 w - Debug.Print "Befor打印样式:" & acadDoc.ActiveLayout.StyleSheet: R. \# M( Y2 S4 S
- Debug.Print "Befor图纸尺寸:" & acadDoc.ActiveLayout.CanonicalMediaName
7 l0 m5 x& H* j- C* M! _# m9 C/ \* h - Debug.Print "图形方向:" & acadDoc.ActiveLayout.PlotRotation
' [2 I. I- L+ n, g. k, P - Debug.Print "打印机:" & acadDoc.ActiveLayout.ConfigName
6 r, c# P3 k) x9 j% I8 f -
8 @9 h2 M/ h0 j - strPdfFile = strPdfFile 'Replace(acadDoc.FullName, "dwg", "pdf")$ U: S1 K* v; n; c+ K: M* W: f
- Debug.Print "输出位置:" & strPdfFile
( ~$ G0 E( y% c3 U
/ j& N1 R& z. Z- 'Now you can use the PlotTofile method% Z$ n# s `% q. A4 n* {
- If PtObj.PlotToFile(strPdfFile, PlotConfig.ConfigName) Then
, O! D/ Q/ t7 R6 r8 h - Debug.Print "PDF Was Created". L7 w7 R- I4 S0 P; l, S0 i' ^
- Debug.Print "PDF Was Created"
: y* P, }4 ^) r& }0 R+ ]/ B# w - Else
, m j5 j8 R$ s5 p - Debug.Print "PDF Creation Unsuccessful!"
+ V7 m: b, g0 [* }2 b4 {: @ - Debug.Print "PDF Creation Unsuccessful!"
1 a. O8 T9 P; r- ? - End If
! d. M) e. \$ t - PtConfigs.Item("PDF").Delete
* L5 d) z0 n" R) L: ?) X - Set PlotConfig = Nothing
. H" o/ S* q* z$ E - acadDoc.SetVariable "BACKGROUNDPLOT", BackPlot
+ E7 L1 z. `8 t( x9 f+ E -
, R$ N; C. a( h5 x+ F4 Q - Debug.Print "CreatePDF ok!"
5 ?* S& M: z2 c9 n0 ?1 Z - End If- |4 V+ `/ N* I9 X9 M
- End If+ V' O. [" I/ v
- DoEvents) ^, g6 g9 j' t) |
- Next ent
9 |5 X/ b5 U4 p. _% ?( Z, Q - Debug.Print "CreatePDF -------------------------------------------------<"$ l( ?) X2 `7 M" \$ X
- Exit Function, T' V$ y; {/ A) I' |/ \
-
) H# i3 `+ o2 T7 N1 J - ErrExit:
9 {3 p* ^! c5 `3 y& @7 K2 C - CreatePDF2 = -1% G9 Y/ ]' F6 _) ^
- Debug.Print "CreatePDF Error:" & Err.Description/ \9 \, G4 U; Q- y8 _' ?" k
- MsgBox "CreatePDF error:" & Err.Description
- Y0 ]9 A9 V8 \3 Y. m - End Function
复制代码 |
-
|