Solved

.PrintOut with Background:=True on HP 5Si garbles intermittently Times Roman chracters

Posted on 2006-06-27
14
470 Views
Last Modified: 2012-08-14
Hi,

I have a VB.NET application that calls Word to Open, Print, and Close files.  I use the following code to print out the files:

objWord.ActiveDocument.PrintOut(Background:=True, Range:=Word.WdPrintOutRange.wdPrintAllDocument, Item:=Word.WdPrintOutItem.wdPrintDocumentContent, Collate:=True, PageType:=Word.WdPrintOutPages.wdPrintAllPages, Copies:=CShort(txtNumCopies.Text))

The porblem is that when "Background:=True" some of the print outs get their Times Roman sections garbled (characters all printed at start of a line or are just missing).

Using "Background:=False" solves the problem, but this greatly increases the time to print a document which is unacceptable.

Note that I have also tried the following that does not help (in between Prinout call and Close call):

            Do While objWord.Application.BackgroundPrintingStatus > 0
                System.Windows.Forms.Application.DoEvents()
                Wait(1)
            Loop

And I have tried settign the printer options to "Dowload Fonts", "Raster", and all optimizations turned "off".

So anyone have any suggestions?
0
Comment
Question by:rmundkowsky
14 Comments
 
LVL 15

Expert Comment

by:cquinn
ID: 16999647
Check your printer drivers - I have had similar problems with HP printers that were using the PCL6 drivers - when they were changed back to PCL5e drivers, the problems went away
0
 

Author Comment

by:rmundkowsky
ID: 17003553
Nope.  Just installed the PCL5e driver and tried it.  Same problem.
0
 
LVL 20

Expert Comment

by:dopyiii
ID: 17004697
I assume that the document prints okay if you don't open it via code (e.g. open the document in Word and print it)?  Also, is it just one document or is it any document?  Also, what version of Word are we working with?

If it still doesn't print right in normal Word operation, I'd recommend the steps outlined in this article (a couple of which you've already tried): http://support.microsoft.com/kb/291344/EN-US/
0
 

Author Comment

by:rmundkowsky
ID: 17006851
Hi,

Yes, the document/s print fine in Word, either if you Open and Print them or Select and Print via Explorer.

Using Word 2003.  I am not at the Office so I can not tell you the Service Pack right now.

The problem is only intermittent.  So if I print 10 documents using my code then 5 (randomally selected) documents will have the problem.  Also note that this problem occurs where every the application is deployed.  I am not sure if it occurs only with 5 Si (and MX), but I do know that these have had the problem.

On a side note, I was think about the font that does not have the problem, I believe it make be a bitmapped version of Arial

I'll see if any of the suggestions from your link pan-out.
0
 
LVL 20

Expert Comment

by:dopyiii
ID: 17009008
That's going to be a tough one to figure out.  But you probably already knew that :)  Intermittent Word problems are the worst, especially when they occur everywhere, to everyone in random situations.  You said that they print fine in a non-code session, but are they printed enough to know for sure?

I know this will sound like a cop-out, but I really think the printer driver has something to do with this.  Is there any other printer that you can use to test it out?
0
 

Author Comment

by:rmundkowsky
ID: 17011922
No, not a cope out.  But I am pretty sure it is not the printer driver at this point, because:

1) The error does not occur using my code if "Background:=False"
2) Print multiple documents via Select/Print via Explorer does not cause the error. (FYI, the error occurs at least one in a batch of 20 prints and Explorer allow ~70 per batch)
3) I have tried to print with all kinds of different printer settings: font not being substitued, with being substitued, as True Types as bnitmaps, download soft fonts, via the Postscript driver, via the PCL driver, GL & raster, lower resolution (300 dpi)

And today, I noted that the Arial fonts that are fine in printouts are also True Type.

So It seems to be a bug in VBA, MS Word or .NET.  

I am thinking my next try at a solution is to port the application from Net 1.1 to 2.0.

0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:rmundkowsky
ID: 17014498
Well, found an interesting fact.  If I open the Word file and save it in a different folder then the problem still occurs, but if I open it and save it with a different name then the problem is fixed.  So I am convinced that the document is corrupted some how.  I think I start looking into how it was created.
0
 
LVL 20

Expert Comment

by:dopyiii
ID: 17014849
Is there anything weird in the path and/or filename?
0
 

Author Comment

by:rmundkowsky
ID: 17015647
Nope.  My guess is Word does some formatting, parsing, or something when it thinks it is saving a file with changes.
0
 

Author Comment

by:rmundkowsky
ID: 17021258
Ok, found a fix.

Based on this: http://groups.google.com/group/microsoft.public.word.docmanagement/browse_thread/thread/ccb13abe9c8c2dea/6b3d8284a5f7fe81?lnk=st&q=hp+word+2003+squished+text&rnum=2&hl=en#6b3d8284a5f7fe81

I found that removing the Word temporary files in between printing files fixes the problem.  So code like this in the print loop makes it work:

                        Dim _Files As String()
                        Dim f As String
                       
                        _Files = Directory.GetFiles(System.IO.Path.GetTempPath())
                        For Each f In _Files
                            Try
                                File.Delete(f)
                            Catch ex As Exception
                            End Try

                        Next
0
 
LVL 20

Expert Comment

by:dopyiii
ID: 17025493
I'm glad you got it working!
0
 

Author Comment

by:rmundkowsky
ID: 17205485
Well, I found that my fix did not totally corrct the problem.  I am still working the issue.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17232209
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now