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

0 Members and 1 Guest are viewing this topic.

Kheilmann

  • Guest
Printing PDF or DWF files
« on: July 27, 2006, 03:09:57 PM »
All I want to do is print.  The question is do I need to open the file with the appropriate app first?  With excel I set the Variable...
Dim Xobj as Excel.Application
Set Xobj = Createobject("Excel.Application")
etc. etc.
Do I do the same with DWF and/or PDF files?
Also, do I need any references?  I've seen several for both, but am not sure which if any to load...???

Currently all my Cad files are saved as dwf for external use, so my question above is more in that direction; however, if I need to, I will start exporting them out as PDF's instead of dwf's.

Thanks in advance for your help....


Dnereb

  • Guest
Re: Printing PDF or DWF files
« Reply #1 on: July 27, 2006, 03:52:28 PM »
Some of the latest versions of PDF printers support VB(A) exposure.
I've helped someone out on that subject a few weeks ago at work.
Luckily for me and not for you I'm on a holiday the coming 2,5 weeks so i can't give you the sample code.
I seem to remember it was PDFcreator or maybe Cutepdf (don't think so)
If you install it and look in the list of referencesyou can find it with some educated guessing.
to find to string I would go for"pdfcreator.application" or however it's described in the reference list
On the other hand do you need to late bind?
you can run it silent in background setting a default directory and so on.

Dave R

  • Guest
Re: Printing PDF or DWF files
« Reply #2 on: July 27, 2006, 03:56:57 PM »
Not sure about PDF files as I haven't tried automating printing for them, however, you can automate the printing of DWF files if you add the appropriate references. You can download the API help for the DWF viewer from Autodesk. That will get you started with some examples.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Printing PDF or DWF files
« Reply #3 on: July 27, 2006, 04:33:50 PM »
do you want code to print dwf and or pdf from autocad?  I have both
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Kheilmann

  • Guest
Re: Printing PDF or DWF files
« Reply #4 on: July 27, 2006, 06:23:57 PM »
I'm actually running my code from Access.  I know there may be some differences, hopefully it would not be too difficult.

I figured there is some reference that needs to be loaded, after that it should not be that big a deal I assume.

I can't imagine the code being anymore than a few lines.

I will download the API help Dave R recommended, and see what I can come up with...
If I have any questions I know where to find you.  :)

Thanks for your help...

Kheilmann

  • Guest
Re: Printing PDF or DWF files
« Reply #5 on: July 31, 2006, 05:23:56 PM »
OK, I have 3 references loaded for DWF (viewer, selection, and shellext).  I assume I need dwfviewer. but I am not sure.

Dwfviewer.application does not seem to be available when declaring my variable.
Also, setting my variable WhipObj to a dwfviewer document seems to also not be available.
Am I missing something?
Do I need an AutoCAD reference also?

Oh, and the Library is 1.0 for all 3 dwf references.  Not sure if that is the latest or not.  Would it make a difference?

Thanks in advance for your help...


CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Printing PDF or DWF files
« Reply #6 on: July 31, 2006, 05:59:48 PM »
i have never tried to print from Access, but this is how I do it from Autocad
Code: [Select]
Public Sub StandardsPDF()
    Dim Layout As AcadLayout, strfile As String
    strfile = ThisDrawing.Path & "\" & (Left(ThisDrawing.Name, (Len(ThisDrawing.Name)) - 4)) & ".pdf"
    Set Layout = ThisDrawing.ActiveLayout
    Layout.RefreshPlotDeviceInfo
    Layout.ConfigName = "HPDSH"
    Layout.PLOTTYPE = acExtents
    Layout.PlotRotation = ac0degrees    'Rotate to 90 for long sheets
    Layout.StyleSheet = "STANDARDS.ctb"
    'Layout.CanonicalMediaName = "Tabloid"
    Layout.CanonicalMediaName = "Letter"
    Layout.PaperUnits = acInches
    Layout.StandardScale = ac1_1
    'Layout.StandardScale = acScaleToFit
    Layout.ShowPlotStyles = False
    ThisDrawing.Plot.NumberOfCopies = 1
    Layout.CenterPlot = True
    Layout.RefreshPlotDeviceInfo
    ThisDrawing.Plot.PlotToDevice
    'ThisDrawing.Plot.PlotToFile strfile
    Set Layout = Nothing
    ThisDrawing.Close (True)
End Sub
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Kheilmann

  • Guest
Re: Printing PDF or DWF files
« Reply #7 on: July 31, 2006, 06:56:49 PM »
I could be wrong, but it looks as if you are actually creating the DWF's.
I want to print DWF files that have already been created and saved to a network location.

I've pretty much hit a road block. 
There was a glimmer of hope on adesk forums but the frm I needed to load to get the code was a VB6 frm and apparently I can not load that into a VBA editor.  Not sure if it would help anyway, but it seems to be the best shot I have of figuring this out as of right now....

I'll keep looking.
I appreciate any help you guys can offer...


quicksilver

  • Guest
Re: Printing PDF or DWF files
« Reply #8 on: August 01, 2006, 08:09:56 AM »
Try opening the VB form in notepad.  You should be able to read the code and cut and paste from there into vba.

Dave R

  • Guest
Re: Printing PDF or DWF files
« Reply #9 on: August 01, 2006, 08:27:52 AM »
Kevin -

See the attached screenshot. You need all these references for accessing the DWF API.

OK, I have 3 references loaded for DWF (viewer, selection, and shellext).  I assume I need dwfviewer. but I am not sure.

Dwfviewer.application does not seem to be available when declaring my variable.
Also, setting my variable WhipObj to a dwfviewer document seems to also not be available.
Am I missing something?
Do I need an AutoCAD reference also?

Oh, and the Library is 1.0 for all 3 dwf references.  Not sure if that is the latest or not.  Would it make a difference?

Thanks in advance for your help...



CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Printing PDF or DWF files
« Reply #10 on: August 01, 2006, 10:48:29 AM »
sorry, i misunderstood you.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Printing PDF or DWF files
« Reply #11 on: August 01, 2006, 10:51:27 AM »
I forget which thread it was, but somebody posted a link to a blog at adesk that was talking about dwf.  The guy that runs that blog, emailed me back and gave me a link for dwf toolkit.  Im trying to find that for you
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Dave R

  • Guest
Re: Printing PDF or DWF files
« Reply #13 on: August 01, 2006, 12:28:44 PM »
Cmdr -

The DWF toolkit is more for applications that need to read and write the DWF directly. Kevin wants to be able to print DWFs using Access VBA. This can be done using the free DWF viewer from Autodesk and the viewer's API. Autodesk's website has the API Doc along with some examples of using it, one of which includes printing.

http://usa.autodesk.com/adsk/servlet/index?id=823771&siteID=123112
http://autodesk.blogs.com/between_the_lines/2005/06/dwf_toolkit_7_w.html


Kheilmann

  • Guest
Re: Printing PDF or DWF files
« Reply #14 on: August 01, 2006, 02:52:00 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 have this.  I assume it is to activate the dwfviewer so I can open my DWF files?????
Dim Viewer As EPlotViewer.IAdEPlotViewer2

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

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


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.