Printing a Pos Receipt in Vb.net

  • Thread starter Thread starter madmabs
  • Start date Start date
M

madmabs

Guest
Hello guys I have a question and its on this project am working on . I have developed the application and I wish for the application to print out receipts via a pos printer.

I can generate and preview the receipt which turns up fine and I can send it directly to the printer, but when I send it to the printer all the characters are all scattered on the paper roll and there isn't any alignment as compared to when I try previewing it.

Note: am using a star printer (SP742), the system communicates well with printer, although I used I used a Generic/Text only to driver the printer which still runs it well.


Here is what I have in code to generate the receipt and send it directly to the Pos Printer.


PrivateSubpreparedlgprint()




' Print immediately.


' Make a PrintDocument object.


DimPrint_Document AsPrintDocument= PreparePrintDocument()


' Print immediately.


Print_Document.Print()



EndSub


'creating the print format


PrivateFunctionPreparePrintDocument() AsPrintDocument


'this functions prepares and handle the print format, size and structure and print document object


'Make the printDocument Object


DimPrint_Document AsNewPrintDocument


Using(Print_Document)


Dimmm2hin AsDouble= 25.4 * 100


'mm2hin - This Function Translates Millimeters to Half inches


DimpkCustomSize1 AsNewPaperSize("Snap Paper", CInt(80 / mm2hin), 0)


'paper size is set for any measurment my paper was 80mm wide with no end...


Dimmargins AsNewMargins(CInt(5 / mm2hin), CInt(5 / mm2hin), 0, CInt(10 / mm2hin))


'sets the margins t0 5mill left and right and 10mill at the top


Print_Document.PrinterSettings.DefaultPageSettings.Margins = margins


Print_Document.PrinterSettings.PrinterName = "EPSON TM-T70 Receipt"


Print_Document.DocumentName = "Ticket"


Print_Document.PrinterSettings.DefaultPageSettings.PaperSize = pkCustomSize1

 


AddHandlerPrint_Document.PrintPage, AddressOfprint_Printpage


EndUsing


'install the printpage event handler


'Return the Object


ReturnPrint_Document


EndFunction


then I created a private function setting up the page alignments and position of the contents


PrivateSubprint_Printpage(ByValsender AsObject, ByVale AsSystem.Drawing.Printing.PrintPageEventArgs)

companyPhone1Height = Convert.ToSingle(CompanyPhone1.GetHeight)


DimTextbox1font AsNewDrawing.Font("Tahoma", 14, Drawing.FontStyle.Bold)




DimxPos AsSingle= 0 '(horizontal positioning/alignment)


DimxPoscenter AsSingle= 0 '(for centering text)


DimyPos AsSingle= 20 '(vertial positioning/alignmemt margin with a 70units start off in this case for the image or logo)


DimSize AsSystem.Drawing.SizeF'


DimxPosmargin AsSingle= 15 '(horizontal positioning/alignment margins)



Size = e.Graphics.MeasureString(companyNameText1, CompanyName1)

 




xPoscenter = ((e.PageBounds.Width * e.Graphics.PageScale) / 2) - (Size.Width / 2)




 


e.Graphics.DrawString(companyNameText1, CompanyName1, Drawing.Brushes.Black, xPoscenter, yPos)





yPos = CSng(yPos + Size.Height * 1.0)


Size = e.Graphics.MeasureString(CompanyNameText2, CompanyName2)


'Now lets center this text


xPoscenter = ((e.PageBounds.Width * e.Graphics.PageScale) / 2) - (Size.Width / 2)


'Now this line draws the text as string and sets a font to use


e.Graphics.DrawString(CompanyNameText2, CompanyName2, Drawing.Brushes.Black, xPoscenter, yPos)




yPos = CSng(yPos + Size.Height * 1.0







Size = e.Graphics.MeasureString(CompanyAddText1, CompanyAdd1)


'Now lets center this text


xPoscenter = ((e.PageBounds.Width * e.Graphics.PageScale) / 2) - (Size.Width / 2)


'Now this line draws the text as string and sets a font to use


e.Graphics.DrawString(CompanyAddText1, CompanyAdd1, Drawing.Brushes.Black, xPoscenter, yPos)




yPos = CSng(yPos + Size.Height * 1.0)


............ and so on


EndSub

So what am I doing wrong , why are the characters scattered all over the page, why are they not aligned on the roll like when I preview it


Thanks in advance


ade

Continue reading...
 
Back
Top