Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Print several .pdf documents
Hi!

I'm trying to do a Visual Basic program that allows me print all .pdf
documents inside a folder. If there is only one .pdf document inside the
folder my program run propertly, but unfortunately when there are several
.pdf documents it only print the last 2 ones. I supose that it happens
because I send too much information to the printer, but Is there any way of
sending data to the printer and sleeping the program until the printer
finished printing?

My code is this:

temp_path = directory & "\*.pdf"         'Folder where the .pdf are
str_dir = Dir(temp_path, vbNormal)

Do While str_dir <> ""
FilePDF = directoriy & "\" & str_dir
Pdf1.LoadFile ""
DoEvents
Pdf1.LoadFile FilePDF
Pdf1.printAll

str_dir = ""
str_dir = Dir$()

Loop

Thanks a lot

Mary

Report this thread to moderator Post Follow-up to this message
Old Post
Mary
04-27-05 08:55 PM


Re: Print several .pdf documents
Mary wrote:
> I'm trying to do a Visual Basic program that allows me print all .pdf
> documents inside a folder. If there is only one .pdf document inside
> the folder my program run propertly, but unfortunately when there are
> several .pdf documents it only print the last 2 ones. I supose that
> it happens because I send too much information to the printer, but Is
> there any way of sending data to the printer and sleeping the program
> until the printer finished printing?
>
> My code is this:
>
>   temp_path = directory & "\*.pdf"         'Folder where the .pdf are
>   str_dir = Dir(temp_path, vbNormal)
>
>   Do While str_dir <> ""
>     FilePDF = directoriy & "\" & str_dir
>     Pdf1.LoadFile ""
>     DoEvents
>     Pdf1.LoadFile FilePDF
>     Pdf1.printAll
>
>     str_dir = ""
>     str_dir = Dir$()
>
>   Loop

Dunno what that Pdf1 object you have there may be, but it sounds like you've
 found a
limitation with it.  Maybe it has some sort of "wait" functionality?  Anothe
r choice
would be to pass each document to a function like this:

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA
"
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, By
Val
lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long)
 As Long

Public Function PrintDoc(ByVal DocFile As String) As Long
' Uses the "print" verb as defined in the registry
PrintDoc = ShellExecute(0&, "print", DocFile, vbNullString, vbNullString,
vbNormalFocus)
End Function

Later...   Karl
--
Working Without a .NET?
http://classicvb.org/petition



Report this thread to moderator Post Follow-up to this message
Old Post
Karl E. Peterson
04-27-05 08:55 PM


Re: Print several .pdf documents
Karl,
I'm going to stick my nose in here again (where it probably doesn't
belong) and ask a stupid question.  Maybe there's a way to do it in
pure VB code, but I know one can use WMI to monitor the print queue -
with that in mind, if the OP thinks he is overloading the queue,
simply monitor it and not send anything else until it is empty.  ??

Lee

On Wed, 27 Apr 2005 09:33:29 -0700, "Karl E. Peterson" <karl@mvps.org>
wrote:

>Mary wrote: 
>
>Dunno what that Pdf1 object you have there may be, but it sounds like you'v
e found a
>limitation with it.  Maybe it has some sort of "wait" functionality?  Anoth
er choice
>would be to pass each document to a function like this:
>
>   Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExec
uteA"
>(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, B
yVal
>lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long
) As Long
>
>   Public Function PrintDoc(ByVal DocFile As String) As Long
>      ' Uses the "print" verb as defined in the registry
>      PrintDoc = ShellExecute(0&, "print", DocFile, vbNullString, vbNullStr
ing,
>vbNormalFocus)
>   End Function
>
>Later...   Karl


Report this thread to moderator Post Follow-up to this message
Old Post
Lee Peedin
04-27-05 08:55 PM


Re: Print several .pdf documents
Hi Lee --

Monitoring the print queue from VB is a bit involved, but far from impossibl
e...

http://vb.mvps.org/samples/PrnInfo

That sample is timer based, to avoid the issues with infinite waits and
single-threading.  I haven't looked at using WMI for same, though would be i
nterested
in a reference?

This certainly didn't sound like a print queue overflow, though.  More likel
y, the
object in question is getting  with repeated requests.  If the queue
 was at
fault, it likely would be printing the first two, rather than the last two, 
right?
Your idea of pacing the output is along the same lines I was suggesting, tho
ugh, and
would probably serve the same result.

Thanks...   Karl
--
Working Without a .NET?
http://classicvb.org/petition


Lee Peedin wrote:
> Karl,
> I'm going to stick my nose in here again (where it probably doesn't
> belong) and ask a stupid question.  Maybe there's a way to do it in
> pure VB code, but I know one can use WMI to monitor the print queue -
> with that in mind, if the OP thinks he is overloading the queue,
> simply monitor it and not send anything else until it is empty.  ??
>
> Lee
>
> On Wed, 27 Apr 2005 09:33:29 -0700, "Karl E. Peterson" <karl@mvps.org>
> wrote:
> 




Report this thread to moderator Post Follow-up to this message
Old Post
Karl E. Peterson
04-28-05 01:55 AM


Re: Print several .pdf documents
Karl,
Here is a bit of scripting code I used as a model:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set colPrintJobs =  objWMIService.ExecQuery _
("SELECT * FROM Win32_PrintJob")
For Each objPrintJob in colPrintJobs
intTotalJobs = intTotalJobs + 1
intTotalPages = intTotalPages + objPrintJob.TotalPages
If objPrintJob.TotalPages > intMaxPrintJob Then
intMaxPrintJob = objPrintJob.TotalPages
End If
Next
Wscript.Echo "Total print jobs in queue: " & intTotalJobs
Wscript.Echo "Total pages in queue: " & intTotalPages
Wscript.Echo "Largest print job in queue: " & intMaxPrintJob


In my particuliar application I am printing to PDF.  Once the PDF is
complete I immediately email the document.  What I was finding was
that the application most likely finishes way before the PDF document
has left the queue.  So I simply go in a loop and wait for the queue
to empty.  Of course it's a little more involved than that, but you
get the idea. :-)

I'd have to agree that the OP's problem is most likely not an overload
of the queue, but confusion in the queue.

BTW: I've also found that by setting app.title, my document in the
queue and finished PDF uses its value.

Lee

On Wed, 27 Apr 2005 11:26:55 -0700, "Karl E. Peterson" <karl@mvps.org>
wrote:

>Hi Lee --
>
>Monitoring the print queue from VB is a bit involved, but far from impossib
le...
>
>  http://vb.mvps.org/samples/PrnInfo
>
>That sample is timer based, to avoid the issues with infinite waits and
>single-threading.  I haven't looked at using WMI for same, though would be 
interested
>in a reference?
>
>This certainly didn't sound like a print queue overflow, though.  More like
ly, the
>object in question is getting  with repeated requests.  If the queu
e was at
>fault, it likely would be printing the first two, rather than the last two,
 right?
>Your idea of pacing the output is along the same lines I was suggesting, th
ough, and
>would probably serve the same result.
>
>Thanks...   Karl


Report this thread to moderator Post Follow-up to this message
Old Post
Lee Peedin
04-28-05 01:55 AM


Re: Print several .pdf documents
Hi Lee --

That's almost too easy. <g>  How do you control which queue is queried?  Thi
s sample
might prove useful for another task that a friend of mine asked about the ot
her day -
printing multiple PDFs in a particular order.  I really think the only thing
 that he
needs to do is wait until one gets submitted to the queue, before moving on 
to the
next.  Is this (usage/properties) actually documented anywhere?

Thanks...   Karl


Lee Peedin wrote:
> Karl,
> Here is a bit of scripting code I used as a model:
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:" _
>     & "{impersonationLevel=impersonate}!\\" & strComputer &
> "\root\cimv2")
> Set colPrintJobs =  objWMIService.ExecQuery _
>     ("SELECT * FROM Win32_PrintJob")
> For Each objPrintJob in colPrintJobs
>     intTotalJobs = intTotalJobs + 1
>     intTotalPages = intTotalPages + objPrintJob.TotalPages
>     If objPrintJob.TotalPages > intMaxPrintJob Then
>         intMaxPrintJob = objPrintJob.TotalPages
>     End If
> Next
> Wscript.Echo "Total print jobs in queue: " & intTotalJobs
> Wscript.Echo "Total pages in queue: " & intTotalPages
> Wscript.Echo "Largest print job in queue: " & intMaxPrintJob
>
>
> In my particuliar application I am printing to PDF.  Once the PDF is
> complete I immediately email the document.  What I was finding was
> that the application most likely finishes way before the PDF document
> has left the queue.  So I simply go in a loop and wait for the queue
> to empty.  Of course it's a little more involved than that, but you
> get the idea. :-)
>
> I'd have to agree that the OP's problem is most likely not an overload
> of the queue, but confusion in the queue.
>
> BTW: I've also found that by setting app.title, my document in the
> queue and finished PDF uses its value.
>
> Lee
>
> On Wed, 27 Apr 2005 11:26:55 -0700, "Karl E. Peterson" <karl@mvps.org>
> wrote:
> 

--
Working Without a .NET?
http://classicvb.org/petition



Report this thread to moderator Post Follow-up to this message
Old Post
Karl E. Peterson
04-28-05 01:55 AM


Re: Print several .pdf documents
Karl,
Yes this is all documented in a 1287 page book published by MS.
(Microsoft Windows 2000 Scripting Guide) :-)

So far, everything I have tried has worked on XP as well.  The book
also comes with a CD which I have imaged on my laptop (much easier
than carrying around a 1287 page book).  There are several examples of
monitoring an individual queue, if you'd like me to look futher, I'd
be glad to.

Lee

On Wed, 27 Apr 2005 12:10:05 -0700, "Karl E. Peterson" <karl@mvps.org>
wrote:

>Hi Lee --
>
>That's almost too easy. <g>  How do you control which queue is queried?  Th
is sample
>might prove useful for another task that a friend of mine asked about the o
ther day -
>printing multiple PDFs in a particular order.  I really think the only thin
g that he
>needs to do is wait until one gets submitted to the queue, before moving on
 to the
>next.  Is this (usage/properties) actually documented anywhere?
>
>Thanks...   Karl
>
>
>Lee Peedin wrote: 


Report this thread to moderator Post Follow-up to this message
Old Post
Lee Peedin
04-28-05 01:55 AM


Re: Print several .pdf documents
Lee Peedin wrote:
> Karl,
> Yes this is all documented in a 1287 page book published by MS.
> (Microsoft Windows 2000 Scripting Guide) :-)

Wow, I think I found bunches of it online...

Microsoft Windows 2000 Scripting Guide - Monitoring Printers, Print Queues, 
and Print
Jobs
http://www.microsoft.com/technet/sc...s_prn_wtfx.mspx

I'll have to see if I can dig up a copy of that book.  Not sure how it got p
ast me
before.  I think, when it was "fresh", I was still concerned about also supp
ort
9x/NT4, and WMI wasn't as practical.

Thanks...   Karl



> So far, everything I have tried has worked on XP as well.  The book
> also comes with a CD which I have imaged on my laptop (much easier
> than carrying around a 1287 page book).  There are several examples of
> monitoring an individual queue, if you'd like me to look futher, I'd
> be glad to.
>
> Lee
>
> On Wed, 27 Apr 2005 12:10:05 -0700, "Karl E. Peterson" <karl@mvps.org>
> wrote:
> 

--
Working Without a .NET?
http://classicvb.org/petition



Report this thread to moderator Post Follow-up to this message
Old Post
Karl E. Peterson
04-28-05 01:55 AM


Re: Print several .pdf documents
You're quite welcome Karl, and just remember this came from a former
Object Rexx programmer - now an ooRexx programmer. :-)

Lee

On Wed, 27 Apr 2005 12:58:03 -0700, "Karl E. Peterson" <karl@mvps.org>
wrote:

>Lee Peedin wrote: 
>
>Wow, I think I found bunches of it online...
>
>Microsoft Windows 2000 Scripting Guide - Monitoring Printers, Print Queues,
 and Print
>Jobs
>http://www.microsoft.com/technet/sc...s_prn_wtfx.mspx
>
>I'll have to see if I can dig up a copy of that book.  Not sure how it got 
past me
>before.  I think, when it was "fresh", I was still concerned about also sup
port
>9x/NT4, and WMI wasn't as practical.
>
>Thanks...   Karl
>
>
> 


Report this thread to moderator Post Follow-up to this message
Old Post
Lee Peedin
04-28-05 01:55 AM


Re: Print several .pdf documents
On Wed, 27 Apr 2005 07:38:12 -0700, "examnotes"
<Mary@discussions.microsoft.com> wrote:

>Hi!
>
>I'm trying to do a Visual Basic program that allows me print all .pdf
>documents inside a folder. If there is only one .pdf document inside the
>folder my program run propertly, but unfortunately when there are several
>.pdf documents it only print the last 2 ones. I supose that it happens
>because I send too much information to the printer, but Is there any way of
>sending data to the printer and sleeping the program until the printer
>finished printing?

I am suspicious about your PDF Object
- if that is (badly) written in VB (or anything else) it could be
mucking up your Dir() loop

Try getting all the file names into an array
- and then printing them

Report this thread to moderator Post Follow-up to this message
Old Post
J French
04-28-05 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:31 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.