Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

How to print PDF-files from within a VB application...? 2

Status
Not open for further replies.

lehu

Technical User
Nov 21, 2000
4
0
0
SE
Hello everyboby,
I'm trying to build a small application for printing PDF-files.
But I can't figure out how to print more than one file silently in the
background. I'm a VB beginner.
Maybe there is some *.ocx that will help me do the trick...

Any suggestions?

//Leif
 
Have you tried usiing the acrobat distiller? It converts PS to PDF and It can be setup to run in the background.

To do it you will need to install a "dummy PS printer driver". Set "dummy PS driver" to print to file. Then in VB you print to the "dummy PS printer". The distiller picks up the output and creates the PDF.

I use a similar setup for log dumps.
-Pete
 
But when I tried to do this it keeps promptiomg for a file name to save as.
Is there a way we can bypass that manual step thro code
anu challa
 
Question: Are you trying to print PDF to printer or are you trying to create PDF file using PDFWriter (as virtual printer)?

In the first case, I can't help you much. I think you can invoke the Windows Print API to route PDF directly to any printer. VB should be able to do it. I've used WinBatch Print function too.

In the second case, check WIN.INI file (or Windows registry) and look for section Acrobat PDFWriter. You should see line for PDFFileName. You can insert name of file to be used for creating PDF. This will eliminate the pop-up that asks for file name every time you want to create a PDF.
 
IN VB (you may need a newer version(VB6.0 maybe 5.0) Create a form with the Adobe OCX. Then install the PDF form on here in the OCX. Use VB to call up the different forms.
Email me if I can help you more.
hbaileyhp@fssa.state.in.us
 
Baily may be correct. I am using VB6. The nice thing about distiller is it preserves any links your document had, say a table of contents or whatever.
-Pete
 
Hi BaileyHP,
I am also trying to build an application (VB) to print multiple pdf files. Since i am new to Adobe and VB, can you please share some sample code so that i can get started.

thanks,

Kiran
 
I have that same issue...I'm trying to print to using the Acrobat Distiller...it works very well but prompts the user for a storage location for saving the PDF file. Users are making errors and mis-naming the files. I need this functionality to be automatic in VBA (Working in Access97) Any easy answers? Thanks for the help.
 
Hi Leif,

Can you post a sample of the code you are using to print at least one file into .pdf file silently in the background. I need to print a Crystal Report into .pdf file from VB6 application. Please help.


thank you
20132
 
Hello,

U try this with "ACG PDF & Mail" Component.

Regards
Eswar
 
Sorry to take so long. You simply need to input the reference to the acrobat page in your vb. create the form in vb, select the page you wish to view, the use the vb code to view the form.
 
This is a question to ejfrench: can you please post a sample of the code on how to print an Access report to .pdf or .ps file using VBA.

THank you.

20132
 
this is to 20132...as a couple of folks have said above, you need to install acrobat distiller and set it up as a printer, it will then show up in the printer list. Printing the report without having the Adobe file dialog box show up is trickier. I have code at work that I could share...but I find it much easier to just use Microsoft Snapshot format. Very easy (and cheap) to code using the OutputTo command in VBA. No "distiller" type program is needed since the ability to create snapshot files comes with Access. Users reading the snapshots will need snapshot viewer but it's installed by default if they have Access and free from Microsoft website if they don't. The drawback is that snapshot files don't have the functionality that Acrobat does...no searching, annotating, text copying, etc. But for simple printing from an electronic version it's really handy and so easy to code.
 
Hi ejfrench,
Thank you very much for your comments. I do have a need to print it to both .pdf and snapshot format. I clearly understand I will need an Acrobat Distiller.
Therefore, I would appreciate you sharing the code with me.
 
Adobe5 and VB6 are NOT compatable. You have to have a PSPrinter to connect the two fo them. This creates a .ps extention from a word doc. You have to call the distiller to convert to a PDF. I use a VB program to read an excel spreadsheet, if pub col = yes then I open word, call the PSPrinter, the distiller and post to the web. Here is a section of code for that process. Just as a side note, do you realize that VB6 is not compatable with VB5? If you are upgrading to VB6 from 5 you may loose some of your dll's depending on the dll being used. There is a download on the MS site to correct this problem, look at: "
Public Sub ConvertFiles()
'open word, create ps, launch distiller,clean out "IN"
On Error GoTo ErrorHandler
Dim intCounter, intFileCounter As Integer
Dim Wor As Object
Dim Dist As ACRODISTXLib.PdfDistiller 'calls distiller.
Dim Doc As Word.Document
Dim Wrd As Word.Documents
Dim optionsFile As String
Dim w As Word.Application


Set Wor = CreateObject("Word.Application")
Set Wrd = Wor.Documents



Word.ActivePrinter = "HP LaserJet 5/5M PostScript"
lblAction = "Converting files"
ProgressBar.Max = intFlyerCounter

For intCounter = 1 To intFlyerCounter
DoEvents
ProgressBar.Value = intCounter
If Record(intCounter).strPublish = "Yes" Then
For intFileCounter = 1 To Record(intCounter).intNumberOfFiles
txtActions = txtActions & "Converting " & Record(intCounter).aryFileNames(intFileCounter) & vbCrLf
txtActions.SelStart = Len(txtActions) 'at the end of the sreadsheet, will show an error, its at EOF
Set Doc = Wrd.Open(strFrom & Record(intCounter).aryFileNames(intFileCounter))

Doc.PrintOut 0, 0, 0, OutputFileName:="\\folderForThePSFile\In\" & Mid(Record(intCounter).aryFileNames(intFileCounter), 1, 8)

If (pdfDist Is Nothing) Then
Set pdfDist = New PdfDistiller
pdfDist.bSpoolJobs = True
End If


optionsFile = "Print.joboptions"
pdfDist.FileToPDF "\\forThePSFile\In\" & Mid(Record(intCounter).aryFileNames(intFileCounter), 1, 8), "\\forThePDF\Out\", optionsFile

txtActions = txtActions & Record(intCounter).aryFileNames(intFileCounter) & " converted" & vbCrLf
txtActions.SelStart = Len(txtActions)
Wrd.Close
Next
End If
Next
txtFilesUploaded = intNumberOfFilesCopied
lblAction = "Finished converting files"
ProgressBar.Value = 0
Wor.Quit

Kill "\\clears out the in folder\In\*.*"
'This is going to be a kill stmnt to clean out the "IN" folder
Exit Sub
ErrorHandler:
If Err.Number = 462 Or Err.Number = -2147023173 Or Err.Number = -2147023170 Or Err.Number = -2147417848 Then
'errors generated by Acrobat
Resume Next
End If
txtActions = txtActions & "ConvertFiles" & vbCrLf & "Error Number: " & Err.Number & vbCrLf & "Error msg: " & Err.Description & vbCrLf & Err.Source & vbCrLf
txtActions.SelStart = Len(txtActions)
Resume Next
End Sub

**************************************
this section belongs in a module
**************************************
Private Const ACROBAT_APP = "Software\Adobe\Adobe Acrobat\5.0\InstallPath"
Private Const OPTIONS_EXT = ".joboptions"
Public pdfDist As PdfDistiller
Private bWorking As Boolean
hope it helps, MS and Adobe really should be ashamed of their selves.
 
To stop the Distiller from prompting for filenames do the following:

Right-click on the distiller printer and choose properties.
Click on "Printing Preferences"
Choose the tab named "Adobe PDF Settings"
Remove the selections for "Prompt for the PDF filename" and "View Result In Acrobat"

And make sure that the PDF-Port is set to somewhere generic instead of the default path to your own documents (in the "Ports" tab on the main properties window, select "Add Port" and choose "PDF Port" and point it at the dir of your choosing).

Cheers :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top