|
|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
本帖最后由 wangxu_1018 于 2015-7-8 12:02 编辑
7 X: @( O, ~/ g+ J( |5 Z" ~( @
2 k2 A2 M$ f) F版主及各位朋友:中午好!, g8 e2 P) a9 H' s$ P" e
]" m1 s* N0 r! g8 q9 H
CAD版本:AutoCAD Electrical 2010+ T# Q D3 t l' V5 P: B, [$ H4 g
" b; U2 v0 B( N8 q 我在vb程序中处理dwg打印为pdf时遇到如下问题,希望得到各位的帮助,谢谢!/ ^+ V" @$ v5 ^7 U
问题如下:
Z$ F" `" N0 { t1 o# S 我之前开发了一段程序(见下面嵌入的代码),通过 Acade - DWG To PDF.pc3 打印为pdf文件,生成pdf没有问题,但是生成的pdf文件一直也没有去打印为纸质版,最近需要打印时发现原DWG文件中引用的图片(公司logo)及由Excel中copy到DWG中的表格(好像也是图片了)出现模糊的情况。
6 b% k, y: ~6 q- {% g
3 g2 f+ i. x" X |7 _ r. ^& d 上述问题不管的手动选取“ Acade - DWG To PDF.pc3”打印机还是程序均有问题。后来尝试手动选取“Adobe PDF”打印,生成的PDF是没有问题。
# J! {- M" }! t
. U2 O4 X. A6 I# T$ M. b9 C 后来尝试有程序实现“Adobe PDF” 去打开PDF,但有遇到”仅依靠系统字体;不使用文档字体(N)“的问题。 h0 s! P' q) R7 U; L1 \. l
尝试去修改打印机首选项,但Adobe PDF 打印机的首选项中没有找到关于”仅依靠系统字体;不适用文档字体“的设置(不确定是否版本问题)
/ s7 g O. b7 s% q
4 Q5 o4 V& `( |5 g: r 问题汇总:: ]7 J$ ?0 G: O6 [
1、 “Acade - DWG To PDF.pc3”打印机 是否可以处理图片模糊的问题?
0 c! L- b6 k: ^1 \0 P0 I 2、 “Adobe PDF” 打印机如何设置字体?+ ]% a' o" C' c
注:由于对AutoCAD也只是初学,对很多CAD本身的应用也还不是很熟悉,开发这块就更差了 还希望各位给予帮助。- '---------------------------------------------------------------------------------------/ z& K* \: k: j6 v ]9 F- V
- ' Procedure : CreatePDF: b4 {% r8 f: g8 o) R& `
- ' DateTime : 2013-11-208 g N' A( l2 Y( ]
- ' Author : xwang
7 q/ Z& v5 K0 Y9 [& N) W3 o9 w - ' Purpose : CAD中DWG图纸导出PDF文件
( l o5 j) l" w( d( O7 L" n - ' param : acadDoc: AcadDocument
' l/ I, V% i) }" ~1 I9 i1 c, i* m - ' : filename: DWGFile
9 ]$ p# g+ O k" T! v8 Q - ' : strPdfFile PdfFile
/ A3 E& C% L( r: N6 N5 I. \ t. r" n - ' : ConfigName: Acade - DWG To PDF.pc3- ^$ p/ A: N* n' u& u# j+ v; |; ]2 F
- '--------------------------------------------------------------------------------------- `: n. |/ ?, F" Y* [% Q% l, \
- Public Function CreatePDF2(acadDoc As AcadDocument, filename As String, strPdfFile As String, ConfigName As String) As Integer2 {7 w% A% g# ?' X6 a" U" m# [# ~
& G6 k6 i. g7 E- y- Dim PtConfigs As AcadPlotConfigurations4 q4 e% K: V2 c% H& H4 x; o% p
- Dim PlotConfig As AcadPlotConfiguration2 H! o3 K- Q% b+ p% V
- Dim PtObj As AcadPlot
) b) L! Z* _. m$ r/ G, | - Dim BackPlot As Variant
* p y$ f) t3 e4 u - $ T: l, Q) |8 A( Y% t1 j3 D7 c% Q1 A
- Dim ent As AcadEntity 'Object; A3 x: ?2 H6 H* f
- Dim blockRef As AcadBlockReference
5 ]. H" G# ^ u, g. e6 ^8 W! v - 6 [; f+ P2 t1 U0 b% j5 z+ t: \
- On Error GoTo ErrExit
8 }- f( v* p; j7 {6 N - 7 A$ N% V& c4 s ?( \% W" P
- Debug.Print "CreatePDF ------------------------------------------------->"8 o' v5 Q9 @+ f" g" b" _
- Debug.Print "打印机:" & ConfigName% F/ P9 }5 Y o! _' Y" t9 @
- For Each ent In acadDoc.ModelSpace
* P6 J/ g; V0 T: s2 a. D - If TypeOf ent Is AcadBlockReference Then
8 t8 e2 o+ W; b/ h - DoEvents
$ J4 f0 o" i) \+ n# S" _, @8 e - Set blockRef = ent: E. K' X: s% v' |, K
- If blockRef.Name = "ACE A3块" Or blockRef.Name = "ACE A4块" Then$ m2 |- [, {' E- `) Y
- 1 \9 R! h1 @1 |2 a, A `& L4 Q
- Debug.Print "块名称:" & blockRef.Name
0 Z. N* n) {1 G* q3 p+ n -
$ E4 o2 D" l3 T+ }9 ?" I+ ]$ k( Z - '块引用的插入点+ n0 ?) d$ S( T) X; Q- k+ |$ {
- Dim insertPoint As Variant- G& p9 m( E9 Z; H
- insertPoint = blockRef.InsertionPoint
% ?1 f/ D. p9 l) M9 I8 b - '放大比例8 g4 r+ N. E3 d% O3 J- D: Y
- Dim xScale, yScale As Integer
4 i9 f5 D" k# o - xScale = blockRef.XScaleFactor. _7 Q+ G/ J! f6 h- i! _* `: {4 h
- yScale = blockRef.YScaleFactor& k2 U/ b# t9 d8 |: O
-
, Z7 m; c* p7 p* s - acadDoc.ActiveLayout.ConfigName = ConfigName '"Acade - DWG To PDF.pc3"
. }7 @( j) }' }! b* Y - Set PtObj = acadDoc.Plot
: X9 d, p* a8 i/ q( u( I. x/ k' } - Set PtConfigs = acadDoc.PlotConfigurations
# v" a8 V( K- s' O7 m - 4 l3 t( W: Y4 C# r: E8 X( t- g! s
- PtConfigs.Add "PDF", False
* x% R9 l1 P; F8 Y; } - Set PlotConfig = PtConfigs.Item("PDF")
, E5 R, N1 X/ T7 ^7 \' A! m - PlotConfig.StandardScale = acScaleToFit+ v p; V1 ]9 F8 M! \4 s" ^) U3 |
- 8 O6 y4 j/ W' x3 I+ q
- PlotConfig.ConfigName = ConfigName '"Acade - DWG To PDF.pc3"
# _8 U. z d+ I: ~ - 'ANSI_A_(8.50_x_11.00_Inches)
% v+ x$ L1 D) V* ] - PlotConfig.RefreshPlotDeviceInfo
( `# ^* S* W0 B- a2 j - 2 _5 p" R/ d# L1 B
- Debug.Print "After打印样式:" & acadDoc.ActiveLayout.StyleSheet2 m8 E: X, D9 }9 }
- Debug.Print "After图纸尺寸:" & acadDoc.ActiveLayout.CanonicalMediaName
6 m$ ^% c% p3 [# Y) t* f -
/ H5 E" b6 A, _0 ~ - acadDoc.ActiveLayout.StyleSheet = "monochrome.ctb" '黑白样式5 I4 p7 ?$ \- y7 u% g8 ~1 H- a
- 8 d. e- F' O) v7 V# F- i; g8 N
- '使用图形文件的线宽
7 S. ~3 u- _ F - PlotConfig.PlotWithLineweights = True2 Q* X1 o% @' \: u
- '是否启用打印样式
$ v$ k2 h2 N- p4 d# G# b - PlotConfig.PlotWithPlotStyles = True
6 Q* ~- P' Z: C2 L. X+ Q+ {- B
1 p; s' x+ Y2 t; ^- '宽高基数5 t2 z7 \( h- s* A; \9 H7 H2 T
- Dim width, height As Double T, M6 L& x7 Q2 j1 H. H6 i: Y
- If blockRef.Name = "ACE A3块" Then) L3 S" M8 ?! M3 S, @
- width = 420& e3 a5 A1 I& q. T3 R" S' o, Z
- height = 297/ \' Q( l7 {6 X$ u* A! @
- acadDoc.ActiveLayout.PlotRotation = ac90degrees
% k N+ T6 c! g) t2 _" A - acadDoc.ActiveLayout.CanonicalMediaName = "ISO_expand_A3_(297.00_x_420.00_MM)"8 T' c3 _+ g# q0 T% @& a( U
- ElseIf blockRef.Name = "ACE A4块" Then S/ M: n+ a7 ~8 u
- width = 210: |* P* K/ s5 |3 ~! J; ^
- height = 297
9 C9 y. a# K: p- M4 {; @& t) d* O - acadDoc.ActiveLayout.PlotRotation = ac0degrees
" P- V; L2 ^$ C; {, _ - acadDoc.ActiveLayout.CanonicalMediaName = "ISO_expand_A4_(297.00_x_210.00_MM)"
# I: g6 h0 L+ E! F0 x5 \. k. ? - End If
3 V4 T2 q9 {3 ~/ Q) @! y+ G -
- R' }; d8 `9 H6 c5 q! ]* Q - '打印区域
4 ]2 S8 H7 s7 Z2 D( h* v - Dim UpperRight(0 To 1) As Double, LowerLeft(0 To 1) As Double
8 O9 l! V4 ]: B' V - LowerLeft(0) = insertPoint(0)% |9 A2 b+ a- z2 Z3 x
- LowerLeft(1) = insertPoint(1)
# r5 N c) W1 N1 D/ G1 { - UpperRight(0) = insertPoint(0) + width * xScale: m* W) ?; _6 _# R' s% v
- UpperRight(1) = insertPoint(1) + height * yScale8 H$ S: D" `7 K4 U4 Q6 s* U2 C
-
$ d) C! x& \7 }3 [2 M - '设置定义要打印的布局范围的坐标
0 M" R+ ]) l+ N1 l - acadDoc.ActiveLayout.SetWindowToPlot LowerLeft, UpperRight
, F9 ^( l: g5 F5 R/ \ - '指定布局或打印配置的类型8 c& \0 N$ N2 e4 u
- acadDoc.ActiveLayout.PlotType = acExtents1 S, z7 p7 J) {9 G) y3 w
- % @! k* v3 ` `( C: `2 s2 y) P
- BackPlot = acadDoc.GetVariable("BACKGROUNDPLOT")
{4 I7 O$ t# c% c" Y - acadDoc.SetVariable "BACKGROUNDPLOT", 05 M: k( @3 T! F9 s& K* p- G! o4 k
- PlotConfig.RefreshPlotDeviceInfo8 G4 Y/ p) }7 J3 m
- " |) q" Y+ ~* Q$ g# j
- Debug.Print "Befor打印样式:" & acadDoc.ActiveLayout.StyleSheet
3 D( j9 l0 g$ [. L/ a - Debug.Print "Befor图纸尺寸:" & acadDoc.ActiveLayout.CanonicalMediaName
3 T; Y% ]2 U, ~2 D - Debug.Print "图形方向:" & acadDoc.ActiveLayout.PlotRotation
# C5 d5 N( m" T* W9 v0 K6 g5 B - Debug.Print "打印机:" & acadDoc.ActiveLayout.ConfigName
7 J' ]/ X$ e; a- K: ] -
) B$ S- {5 O, X) z0 A. b - strPdfFile = strPdfFile 'Replace(acadDoc.FullName, "dwg", "pdf")
+ {" m2 c7 m7 [ - Debug.Print "输出位置:" & strPdfFile
1 ^5 b8 P4 U1 ~# M( Z1 u - ' K( t9 q; E' @- A& W' `# N9 o9 O
- 'Now you can use the PlotTofile method
F! ?9 l% `) Z' _ - If PtObj.PlotToFile(strPdfFile, PlotConfig.ConfigName) Then8 w8 k4 F/ t0 w. R# E
- Debug.Print "PDF Was Created"
! m2 x& b* c8 [, Q+ l: X+ Z8 C6 ^ - Debug.Print "PDF Was Created"! Q' t7 q* L" t4 j0 @- G$ G) t
- Else, n& w, L4 F N. C$ P4 w& ~
- Debug.Print "PDF Creation Unsuccessful!"/ l- R/ h, N" Y- G
- Debug.Print "PDF Creation Unsuccessful!"0 V$ @( K: H% k: y, u4 ~
- End If5 M% [! y& W8 D& E" ]
- PtConfigs.Item("PDF").Delete1 E: N7 x0 P8 Z0 v) ]! P7 s
- Set PlotConfig = Nothing
" J" @0 E+ b3 F% t1 k6 C5 J - acadDoc.SetVariable "BACKGROUNDPLOT", BackPlot# e! `/ g+ D8 X5 l0 B- o5 \9 v
-
+ c [; y, J2 {1 M6 k - Debug.Print "CreatePDF ok!"7 M% ^- S& O, ^: A5 P
- End If9 H: W3 _- R" {7 A' a u% `! d: K% G
- End If. j) ]0 b$ B- }* P/ t8 }5 e! O* n
- DoEvents1 c9 [$ z# _4 f; Y0 s% P
- Next ent& w* o2 s% F5 n8 p p( z7 _- v
- Debug.Print "CreatePDF -------------------------------------------------<"
+ ~6 {+ Z( P O3 o% q: h - Exit Function: `, k z* O- [& i
-
* ]/ X4 d5 e+ g* T - ErrExit:8 [/ u, h" P9 ]5 c% C) ^
- CreatePDF2 = -1- a3 i- ^( a9 [8 J' s) ]
- Debug.Print "CreatePDF Error:" & Err.Description
- i. ^8 y6 }! h. `$ ~ - MsgBox "CreatePDF error:" & Err.Description6 p7 W* I' t9 G$ L- X6 U
- End Function
复制代码 |
-
|