Preparing for Printing

The common UNIX printing system (Common UNIX Printing System - CUPS) is used to print various files in Linux OS. CUPS enables the user to set up access to printers and manage printing. To set up CUPS and all necessary dependences, use the command:

sudo apt-get install cups

Then follow the steps to add a printer:

  1. Open the CUPS web interface in a browser at http://localhost:631/.

  2. Click Add Printers and Groups, then Add Printer.

  3. Select Host or LPD/LPR Printer and click the Continue button.

  4. Specify the path to the printer in the following format: lpd://<server>/<printer>, where <server> - address and print server port; <printer> - printer name to be added. Click the Continue button.

  5. Fill in the Name box with Latin letters, for example, MyPrinter. Click the Continue button.

  6. In the Create list select the necessary printer type. Click the Continue button, then Add Printer.

After that, the printer is added to the system and can be used.

Printing from Application Code

The Fore code allows the user to print repository objects on printer. Objects that support printing can be cast to the IGxDocument interface. Objects are prepared and printed using the properties and methods of this interface.

Executing the example requires the Drawing and Metabase assemblies are connected to the module. A regular report with the Report identifier is created in repository.

Sub UserProc;
Var
    MB: IMetabase;
    MObj: IMetabaseObject;
    GxDoc: IGxDocument;
    Printer: IGxDocumentPrinter;
Begin
    MB := MetabaseClass.Active;
    MObj := MB.ItemById(
"Report").Edit;
    
// Printer to print
    Printer := GxPrinters.DefaultPrinter As IGxDocumentPrinter;
    
// Print report
    GxDoc := MObj As IGxDocument;
    GxDoc.Print(Printer, -
1, -1"");
End Sub UserProc;

Using the printer graphical context, which can be received in the Graphics property of the IGxDocumentPrinter interface, the user can print various graphics. Images can be obtained from a file, repository document, or drawn directly using program code.

Sub UserProc1;
Var
    Image: IGxImage;
    Printer: IGxDocumentPrinter;
Begin
    
// Printer to print
    Printer := GxPrinters.DefaultPrinter As IGxDocumentPrinter;
    
// Get image from file to be printed
    Image := GxBitmap.FromFile("D:\Work\Image.jpg");
    
// Fill in graphic context and print
    Printer.StartDocument("Image");
    Printer.NewPage;
    Printer.Graphics.DrawImageTransparent(Image, 
NullNullNull);
    Printer.EndDocument;
End Sub UserProc1;

Make sure to connect the Fore and IO assemblies to print images saved in a repository document.

Sub UserProc2;
Var
    MB: IMetabase;
    Doc: IDocument;
    MemStream: IMemoryStream;
    Image: IGxImage;
    Printer: IGxDocumentPrinter;
Begin
    MB := MetabaseClass.Active;
    Doc := MB.ItemById(
"IMG_REPORT").Bind As IDocument;
    
// Printer to print
    Printer := GxPrinters.DefaultPrinter As IGxDocumentPrinter;
    
// Get image
    MemStream := New MemoryStream.Create;
    Doc.SaveToStream(MemStream);
    Image := 
New GxImage.CreateFromStream(MemStream);
    
// Fill in graphic context and print
    Printer.StartDocument("Image");
    Printer.NewPage;
    Printer.Graphics.DrawImageTransparent(Image, 
NullNullNull);
    Printer.EndDocument;
End Sub UserProc2;

See also:

Additional Settings