Link to home
Start Free TrialLog in
Avatar of bmilne
bmilne

asked on

Print to file

I am trying to print a document to a file instead of to the printer using VB5.  I tried the "print#1" route, but keep getting file already open, even though I'm using a different file with a different name, etc.  Is there another way I can print a printer document to a file?
ASKER CERTIFIED SOLUTION
Avatar of Bhargava
Bhargava

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of singe
singe

This seemed a little unclear to me even though I know what Bhargava was trying to say. Try following these steps:

1. Declare a variable as an integer

2. Assign a valid file handle to that variable by calling:
 (variable) = FreeFile

Don't forget to open, close, and print using only this file handle, and that each file handle may only be used for one open file. To open multiple files, you will need to get multiple free file handles...

Singe
 let printer document be file_tobe_printed .
you can use following code:

      num1=FreeFile
      open file_tobe_printed For Binary As #num1
      num2=FreeFile
      open new_file For BInary As #num2
      while( Not EOF(num1))
          get  #num1, ,Chunk
          put #num2, .Chumk
       wend
      Close #num2
      Close #num1