Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VB to print a PDF file 2

Status
Not open for further replies.

jh0401

Computer
Apr 8, 2002
32
US
Does anyone have an example of using visual basic to drive
Acrobat Distiller or Acrobat PDFWriter to print a file to a specific location?

Thanks,
JOSH
 
Replies continue below

Recommended for you

There is a tool called ACG PDF and Mail Library. Works very well.
 
Here's the code to get SolidWorks to make a PDF file in the same location as SolidWorks drawing if anyone is interested.

Put this in a module and call from VB app:

GENERAL DECLARATIONS
Option Explicit
Const vbPRORPortrait As Long = 1
Const vbPRORLandscape As Long = 2
Const vbPRPSLetter As Long = 1
Const vbPRPSLetterSmall As Long = 2
Const vbPRPSTabloid As Long = 3
Const vbPRPSLedger As Long = 4
Const vbPRPSLegal As Long = 5
Const vbPRPSStatement As Long = 6
Const vbPRPSExecutive As Long = 7
Const vbPRPSA3 As Long = 8
Const vbPRPSA4 As Long = 9
Const vbPRPSA4Small As Long = 10
Const vbPRPSA5 As Long = 11
Const vbPRPSB4 As Long = 12
Const vbPRPSB5 As Long = 13
Const vbPRPSFolio As Long = 14
Const vbPRPSQuarto As Long = 15
Const vbPRPS1_H14 As Long = 16
Const vbPRPS11x17 As Long = 17
Const vbPRPSNote As Long = 18
Const vbPRPSEnv9 As Long = 19
Const vbPRPSEnv10 As Long = 20
Const vbPRPSEnv11 As Long = 21
Const vbPRPSEnv12 As Long = 22
Const vbPRPSEnv14 As Long = 23
Const vbPRPSCSheet As Long = 24
Const vbPRPSDSheet As Long = 25
Const vbPRPSESheet As Long = 26
Const vbPRPSEnvDL As Long = 27
Const vbPRPSEnvC3 As Long = 29
Const vbPRPSEnvC4 As Long = 30
Const vbPRPSEnvC5 As Long = 28
Const vbPRPSEnvC6 As Long = 31
Const vbPRPSEnvC65 As Long = 32
Const vbPRPSEnvB4 As Long = 33
Const vbPRPSEnvB5 As Long = 34
Const vbPRPSEnvB6 As Long = 35
Const vbPRPSEnvItaly As Long = 36
Const vbPRPSEnvMonarch As Long = 37
Const vbPRPSEnvPersonal As Long = 38
Const vbPRPSFanfoldUS As Long = 39
Const vbPRPSFanfoldStdGerman As Long = 40
Const vbPRPSFanfoldLglGerman As Long = 41
Const vbPRPSUser As Long = 256
' Defined in swconst.bas
Const swPrintPaperSize As Long = 0
Const swPrintOrientation As Long = 1
Const SWPrinter As String = "Acrobat PDFWriter"



Sub PDF()
Dim swApp100 As Object 'SldWorks.SldWorks
Dim swModel100 As Object 'SldWorks.ModelDoc2
Dim swDrwDoc As Object 'SldWorks.DrawingDoc
Dim swSheet As Object 'SldWorks.sheet
Dim NumSheet As Long
Dim PathName As String
Dim PrintFileName As String
Dim SheetName As String
Dim Errors As Long
Dim i As Long

Set swApp100 = CreateObject("SldWorks.Application")
Set swModel100 = swApp100.ActiveDoc
Set swDrwDoc = swModel100

' strip off SolidWorks file extension (.sld???)
PathName = swModel100.GetPathName
PathName = Left(PathName, Len(PathName) - 7)

'go back to the first sheet
NumSheet = swDrwDoc.GetSheetCount
For i = 0 To NumSheet - 1
swDrwDoc.SheetPrevious
Next i


For i = 0 To NumSheet - 1
' generate print filename based on sheet number
PrintFileName = PathName + "_Sheet-" + Trim(Str(i))
swDrwDoc.ForceRebuild
swModel100.PrintOut2 i + 1, i + 1, 1, False, SWPrinter, 0#, True, PrintFileName
swDrwDoc.SheetNext
Next i

Set swDrwDoc = Nothing

End Sub



Thanks,

Josh

YOU MUST HAVE ADOBE ACROBAT NOT JUST THE READER - INSTALL
THE PDFWRITER or DISTILLER
 
Josh

any luck with printing pdfs from VB? I looked at the ACG product but it is for Access rather than VB (not being an expert perhaps there's a way to use the MDE but unsure). I don't want to create a pdf, all I want to do is send the pdf to a nominated printer without user interaction with either the adobe reader dialog or print dialog.

(sidenote: I used to do this by shelling from VB with the command:

acrord32 /t "pdffilename.pdf" "printername"

however, the reader now runs minimised with version 5 and stays open rather than in hidden context. This means it prints once but if you invoke again it fails unless you close the first instance of the reader.This method was never satisfactory as there was no guarantee that the shell would work)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top