Author Topic: Printing PDF or DWF files  (Read 4568 times)

0 Members and 1 Guest are viewing this topic.

Dave R

  • Guest
Re: Printing PDF or DWF files
« Reply #15 on: August 01, 2006, 04:27:59 PM »
Thanks for all the help guys.  Just one last question (I think)...

All the samples in the API are either too vague, or is just completely over my head...
I don't see anything specifically about printing or openning dwf files...
I see where they are iterating through pages and such, but they assume a dwf file is already loaded.
I want my dwf file to be a variable which is set depending on certain code criteria. 

Here is what I think I need from the API sample, I just need to modify it to allow me to either print or open a dwf file with dwfviewer through Access vba.

I agree the API is a little obscure unless you know C++

Quote
I have this.  I assume it is to activate the dwfviewer so I can open my DWF files?????
Dim Viewer As EPlotViewer.IAdEPlotViewer2

No that won't work.

Quote
I don't thing I need this, but I think I probably need something similar???????
Private Sub SetSourcePath(FileName As String)
       'Accept the full path, relative path, FTP or HTTP path.
       CExpressViewerControl1.SourcePath = FileName
End Sub

This will set the path of the active DWF file in the ActiveX control

Quote
Not sure if I need any of this, since it seems like the file is already loaded and just deals after the fact.
Private Sub CExpressViewerControl1_OnEndLoadItem(ByVal bstrItemName As String, ByVal vData As Variant, ByVal vResult As Variant)

Set Viewer = Nothing
Set Viewer = CExpressViewerControl1.DocumentHandler
If bstrItemName = "DOCUMENT" Then
'The document is fully loaded, but the sheets may not have
'been loaded yet.
'At this point, you can access all the sheets in the DWF file.
Call SetToolbarProperties
Call IterateThroughPages

ElseIf bstrItemName = "SHEET" Then
 
'A sheet is finished loading, either as a first sheet upon opening
'the document or as a change of sheets.
Call IterateThroughLayers   

ElseIf bstrItemName = "SPACE" Then

'A 3D DWF sheet has been loaded.
'Currently, the DWF Viewer does not support any APIs for 3D DWFs.
'You can give a message to the user that a 3D DWF has been loaded.
MsgBox "A 3D DWF has been loaded"

End If
End Sub



Not unless you want to respond to the events.


I have attached a sample VB project which does some simple printing with DWF files. If you have VB6 you can open it and see how it works. If not you may be able to open some of the files in Notepad and piece together what you need.

Kheilmann

  • Guest
Re: Printing PDF or DWF files
« Reply #16 on: August 01, 2006, 06:38:46 PM »
Obviously my programming knowledge is limited; however I do not think it is possible to open or print dwf files through Access VBA or any other VBA interface for that matter.

I have found nothing that references openning a DWF file, or allows you to specify any DWF file when printing either...

I could be missing something here, especially since I am limited in my programming knowledge/experience; however it looks as if I will have to convert all my DWF's to some other format that will allow me to open and/or print from Access VBA.  I'm thinking PDF.

Thanks for everyones input...

quicksilver

  • Guest
Re: Printing PDF or DWF files
« Reply #17 on: August 02, 2006, 07:50:16 AM »
I have had this working for a couple of years ago with pdf using a class called Megashell from the other site.  With thanks to them.  It will work with dwf's too.

 
Code: [Select]
Sub openpdf()
    Dim st As String
    st = MegaShell("C:\Documents and Settings\kj\My Documents\Drawing1.pdf", "Print", 3)
End Sub

Code: [Select]
Option Explicit

Declare Function ShellExecute Lib _
"shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal _
lpDirectory As String, ByVal nShowCmd As Long) As Long


Private Declare Function FindExecutable _
Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory _
As String, ByVal lpResult As String) As Long

Code: [Select]
'@~~~~~~~~~~~~ Mega Shell ~~~~~~~~~~~~@
' Designed for AutoCAD 2000/i
'
' FILE VALUES
' Full Path & File name (including extension)
' Directory (see tasks listed for use.)
'
' TASK VALUES
' Edit - Use if strFile is a document
' Explore - use if strFile is a directory
'           or if strFile is vbNullstring
'           (CurDir will open)
' Find - initiates a search for strFile
'        The search begins in the folder
'        That I currently have set to the
'        CurDir, to use this option add an
'        additional argument for a directory
'        to begin searching in and replace
'        the "CurDir" I used with that value.
' Open - strFile can be a document, Exe, or
'        folder.
' Print - strFile must be a document.
' vbNullString - The default action for the
'                strFile type will be used.
'                or if no default, Open will
'                be used.
' Assuming that the application supports
' The specified task for the file type.
'
' WINDOW STATE
' 0 (Hide Window)
' 1 (Show Normal - No Focus)
' 2 (Show Minimized - No Focus)
' 3 (Show Maximized - No Focus)
' 4 (Show but do not set focus)
' 5 (Displays the window in its current state)
' 6 (Minimize and activate the next in Z order)
' 7 (Show Minimized - No focus)
' 8 (Show Window in Current state)
' 9 (Restore Window to original state)
' If the Window is not currently open (and
' chances are that its not) the "current
' state" means the state that is stored in the
' Registry.
'
' Return Values:
' 2 = File Not Found
' 3 = Path Not Found
' 5 = Access Denied
' 27 = Incomplete Association
' 28 = DDE Timed Out
' 29 = DDE Failed
' 30 = DDE Busy
' 31 = No File Association
' 32 = DLL Not Found
' 33+ = Success.
'/////// Interesting fact ///////////
' The success return value is set for
' Compatibility with 16 bit Windows apps.
' It is essentially "faking" a handle to
' The instance of the shelled application.
'////////////////////////////////////
' There are even more details that can be
' covered when we start talking shell
' Execution, and more arguments that can
' Be applied. If you have any questions,
' Feel free to ask!
'
' Comments:
' This is capable of even more by providing
' The optional parameters, but the code is
' At it's generic best like this.
' (Optional parameters apply to EXE files)
' If you are using AutoCAD R14 you have only
' To change the lngHwnd variable from This
' Drawing to the value returned by FindWindow
' If your not sure what I mean, feel free to
' Ask, or visit our partially complete API
' Guide:
' < http://vbdesign.hypermart.net/cadpages/findwindow.htm >

Public Function MegaShell(strFile As String, strTask As String, lngWinState As Long) As Long
  Dim lngRet As Long
  Dim lngHwnd As Long
  On Error GoTo Err_Control
  lngHwnd = 0&
  lngRet = ShellExecute(lngHwnd, strTask, strFile, vbNullString, CurDir, lngWinState)
  MegaShell = lngRet
Exit_Here:
  Exit Function
Err_Control:
  Select Case Err.Number
  'Enter additional cases
  Case Else
    MsgBox Err.Description
  End Select
End Function

Kheilmann

  • Guest
Re: Printing PDF or DWF files
« Reply #18 on: August 02, 2006, 08:56:36 AM »
First of all, thank you for the code. 

OK, now I must apologize.  I think I understand what you sent, sort of, all the declares and Functions and Shells, etc. are way over my head, but I think I understand the overall idea.  However, I keep getting errors....

It seems like the problems have to do with the Declare statements.  Whereever I put them, I get errors...

If I put them in Declaration section I get an error stating they can not be public.  If I move them to a sub or function, the error says the Function is not defined.


quicksilver

  • Guest
Re: Printing PDF or DWF files
« Reply #19 on: August 02, 2006, 09:01:25 AM »
I have them in a module not under a particular form.
Try importing this into your project.
« Last Edit: August 02, 2006, 09:08:07 AM by quicksilver »

Kheilmann

  • Guest
Re: Printing PDF or DWF files
« Reply #20 on: August 02, 2006, 10:46:44 AM »
Thanks QuickSilver,  it works great. 
I have a few issues with my variables but I'll figure that out...

quicksilver

  • Guest
Re: Printing PDF or DWF files
« Reply #21 on: August 02, 2006, 10:57:40 AM »
I am glad that I remembered that it could print.