In this post, you’ll learn how to print documents from Android devices using Winsoft, a powerful Android printing library that supports Delphi, and how to do so using Windows Application Development.
- Introduction
Printing Library is a useful library for establishing a printer connection between an Android device and a local / server printer. The Library uses Android Print and PrintHelper API.
2. Components in the Demo and what they do
The Demo contains tab control with four tab items. Each tab item opens four different screens – one with TImageViewer, one with TWebBrowser, the third one with simple TLabel and the last one empty. All of the four tab items contain the Print button, which on their OnClick event call certain method, depending on the tab item. Every button executes similar code, setting Canvas and Paint settings. All of them call the same PrintPdfDocument procedure, which is actually the main of the Printing Library. The method itself sets needs three parameters to be passed – JPdfDocument, JobName, which is string, and Color. The Color is set with default value, so it’s not mandatory. In the next code you will find short preview of the executed code on the button click.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<em>// create PDF document</em> Document := TJPdfDocument.JavaClass.init; <em>// create page 1</em> PageInfo := TJPageInfo_Builder.JavaClass.init(100, 100, 1).create; Page := Document.startPage(PageInfo); Canvas := Page.getCanvas; Paint := TJPaint.JavaClass.init; Paint.setARGB($FF, 0, 0, $FF); Canvas.drawText(StringToJString('Hello, world!'), 10, 50, Paint); Document.finishPage(Page); <em>// create page 2</em> PageInfo := TJPageInfo_Builder.JavaClass.init(100, 100, 2).create; Page := Document.startPage(PageInfo); Canvas := Page.getCanvas; Paint := TJPaint.JavaClass.init; Paint.setARGB($FF, $FF, 0, 0); Canvas.drawLine(10, 10, 90, 10, Paint); Paint.setStrokeWidth(1); Paint.setARGB($FF, 0, $FF, 0); Canvas.drawLine(10, 20, 90, 20, Paint); Paint.setStrokeWidth(2); Paint.setARGB($FF, 0, 0, $FF); Canvas.drawLine(10, 30, 90, 30, Paint); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
PageInfo := TJPageInfo_Builder.JavaClass.init(ImageViewer.Bitmap.Width + 20, ImageViewer.Bitmap.Height + 20, 3).create; Page := Document.startPage(PageInfo); Surface := TBitmapSurface.Create; try Surface.Assign(ImageViewer.Bitmap); JavaBitmap := TJBitmap.JavaClass.createBitmap(Surface.Width, Surface.Height, TJBitmap_Config.JavaClass.ARGB_8888); if SurfaceToJBitmap(Surface, JavaBitmap) then begin Canvas := Page.getCanvas; Canvas.drawBitmap(JavaBitmap, 10, 10, Paint); end; finally Surface.Free; end; Document.finishPage(Page); <em>// print PDF document</em> PrintPdfDocument(Document, 'pdf document'); |
To get a better idea of what the Demo does, check out the short video below with the Demo in action on Android phone:
You can download the Demo from the link, attached below:
https://winsoft.sk/download/aprinting.zip
Find out more about the WINSOFT Android printing library for Delphi.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition