• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Printing ?

Hi Friends,

   I have table called tbPrintDesign and tbLine. The structure of the table is as follows

tbLine
_______

  * LineNumber
  * Data To Print  // what data should be printed in that Line Number.

tbPrintDesign
_____________

  * LineNumber
  * LinesPerInch ( LPI )
  * CharacterPerInch ( CPI )
  * LayoutOfData

 I have to get the data from tbLine table, it's respective layout( How to print ) from tbPrintDesign table and show a preview to the end user. If the user says print it should print the document. Please Note : I cannot use Microsoft Word.

 

0
Arvindtn
Asked:
Arvindtn
  • 4
  • 3
1 Solution
 
mark2150Commented:
Ok, from what I gather you're trying to make a dynamic data printer. You've got a definition table and live data tables.

The printer in VB can be treated as a plotter. If you set the .Scale property you can define the print region in units of your choosing. LPI and CPI don't have direct meaning. You can position the print cursor using .PrinterX/Y. When you want to move down to a new line simply add the spacing from the LPI to the .PrinterY like this:

LPISpace = 1 / LPI
OldY = Printer.CurrentY
Printer.Print "This is some text"
Printer.CurrentY = OldY + LPISpace

CPI really has little meaning when you're using proportionally spaced fonts. You either have to use Courier or some other mono-spaced font or you can determine the space that a specific text object needs by using the .TextWidth or .TextHeight properties.

Now I don't know if you're having data extraction issues as well, but this should get you headed in the right direction as far as printing goes.

M

0
 
AndySulzCommented:
Use Crystal Reports.
0
 
ArvindtnAuthor Commented:
i want to do it without crystal reports
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mark2150Commented:
Ok, so follow my example and generate your own report. Set up the printer's .scale and you can position yourself with .CurrentX/Y and print text with Printer.Print RS!Field.

If you need to, say, center a line of text then you can use the .TextWidth property to find out how wide your text is:

Txt = trim( "" & RS!SomeField )
Printer.CurrentX = ColumnN - (Printer.TextWidth(Txt) / 2)
Printer.Print Txt

For Right justified, simply leave off the "/ 2"

Use .Line to draw lines and boxes. All will be denominated in units you've set when you set the .Scale property.

If you need additional pages you can generate them with .Page and you can watch the .CurrentY to tell when you're getting near the bottom of the page.

Finally end the report with .EndDoc

M

0
 
ArvindtnAuthor Commented:
How will i show the preview then Mark, Will it work in a LinePrinter. Because iam trying it in a Laser printer but the client will use Line Printer Only.
Also is there any method to find whether the printer is ON / OFF, Paper is present in the Printer, etc. The Printer could either be on a Network or directly connected to my machine.

 
0
 
mark2150Commented:
If you pass the print routine a PictureBox as a parameter, it'll render to the picture box just like it'll render to the printer.

PUBLIC SUB Render( Obj AS Object )
....
END SUB

When you call it with:

DIM MyObj AS Object

Set MyObject = PictureBox1
Call Render( MyObject )

Now it gives you preview. You want hardcopy? Change to:

Set MyObject = Printer
Call Render( MyObject )

You don't have to worry about the details of the printer. No matter what printer or it's paper status or how it's connected your print routine remains unchanged. Remember your app is printing to a *LOGICAL* device - NOT a PHYSICAL one. The *LOGICAL* printer is the SAME no matter what the internal details of the physical printer are. It is the OS's job to convert the data you sent to the logical printer to whatever form is needed by your specific printer.

Your app doesn't need to know or care anything significant about the printer.

You pop the Printer function of the CommonDialog control to allow the user to select what printer they want the job to go to. It matters not if the printer is on a LAN, printing to a file, dot matrix, laser, or what. Once the user has given the go ahead by making a printer selection you set the .SCALE property to convert the page's dimensions to units you like to work in and start hammering out the print commands. When you're done the .EndDoc method signals the OS to convert the logical page your app has created into whatever form is required for the target printer. Your app can be happily continuing on while the print job queues and develops a life of it's own.

M

0
 
ArvindtnAuthor Commented:
Thanks for your hints Mark, You gave me a path to approach the problem. Iam giving you the points only for that.

I had one problem which i had sorted out. The problem was in assigning Height and Width to a font. I did that using CreateFont().


I had solved the problem and it is working perfectly. I thank everybody for trying to help me out.

Bye
Arvind

0
 
mark2150Commented:
Always glad to help.

M
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now