If you only want to print some text, the PB Print commands can handle that:
PB Printer
If you need something more ambitious, then the best solution (Windows OS only) is:
ABB Klaus Printer Lib
			
			
									
									print api
- 
				IdeasVacuum
 - Always Here

 - Posts: 6426
 - Joined: Fri Oct 23, 2009 2:33 am
 - Location: Wales, UK
 - Contact:
 
Re: print api
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
						If it sounds simple, you have not grasped the complexity.
Re: print api
Hello Louise. This example gets the default printer, configures some presets, and prints some text to it, using Windows API functions:Louise wrote:I want with a new settings to print a text...
...I want to a dialog with the predefined settings to be print.
Code: Select all
If OpenLibrary(0, "winspool.drv")
  defaultPrinterName.s = Space(#MAX_PATH)
  If GetVersion_() & $FF0000   ;Windows 2000/NT/XP
    returnBuffer = #MAX_PATH
    ;for UNICODE use GetDefaultPrinterW
    CallFunction(0, "GetDefaultPrinterA", @defaultPrinterName, @returnBuffer)
  Else   ;Windows 95/98/ME
    GetPrivateProfileString_("WINDOWS", "DEVICE", "", @defaultPrinterName, #MAX_PATH, "Win.Ini")
    defaultPrinterName = StringField(defaultPrinterName, 1, ",")
  EndIf  
  Debug defaultPrinterName
  CloseLibrary(0)
  Define printDriver.s = "WINSPOOL", printerName.s = defaultPrinterName
  Define *sysDEVMODE, *userDEVMODE, *contextDEVMODE.DEVMODE, docInfo.DOCINFO
  
  If OpenPrinter_(printerName, @printerHandle, 0)
    returnBuffer = DocumentProperties_(0, printerHandle, printerName, 0, 0, 0)
    *sysDEVMODE = AllocateMemory(returnBuffer)
    *userDEVMODE = AllocateMemory(returnBuffer)
    DocumentProperties_(0, printerHandle, printerName, *sysDEVMODE, *userDEVMODE, #DM_OUT_BUFFER)
    *contextDEVMODE = *sysDEVMODE
    ClosePrinter_(printerHandle)
    FreeMemory(*sysDEVMODE)
    FreeMemory(*userDEVMODE)
    
    With *contextDEVMODE
      \dmOrientation = #DMORIENT_PORTRAIT
      \dmPaperSize = #DMPAPER_A4
      \dmPrintQuality = #DMRES_DRAFT
      \dmCollate = #DMCOLLATE_TRUE
      \dmCopies = 1     
    EndWith
   
    With docInfo
      \cbSize = SizeOf(DOCINFO)
      \lpszDocName = @"PureBasic Test Print"
      \lpszOutput = #Null
    EndWith  
    
    printerDC = CreateDC_(@printDriver, printerName, 0, *contextDEVMODE)
    jobId = StartDoc_(printerDC, @docInfo)
    StartPage_(printerDC)
      outString.s = "Prints on page 1..."
      TextOut_(printerDC, 200, 200, outString, Len(outString))
    EndPage_(printerDC)
    StartPage_(printerDC)
      outString = "Prints on page 2..."
      TextOut_(printerDC, 200, 200, outString, Len(outString))
    EndPage_(printerDC)
    EndDoc_(printerDC)
    DeleteDC_(printerDC) 
  EndIf    
EndIfTexas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 
						- VB6_to_PBx
 - Enthusiast

 - Posts: 627
 - Joined: Mon May 09, 2011 9:36 am
 
Re: print api
TI-994A wrote:Hello Louise. This example gets the default printer, configures some presets, and prints some text to it, using Windows API functions:Louise wrote:I want with a new settings to print a text...
...I want to a dialog with the predefined settings to be print.Hope you'll find it useful.Code: Select all
If OpenLibrary(0, "winspool.drv") defaultPrinterName.s = Space(#MAX_PATH) If GetVersion_() & $FF0000 ;Windows 2000/NT/XP returnBuffer = #MAX_PATH ;for UNICODE use GetDefaultPrinterW CallFunction(0, "GetDefaultPrinterA", @defaultPrinterName, @returnBuffer) Else ;Windows 95/98/ME GetPrivateProfileString_("WINDOWS", "DEVICE", "", @defaultPrinterName, #MAX_PATH, "Win.Ini") defaultPrinterName = StringField(defaultPrinterName, 1, ",") EndIf Debug defaultPrinterName CloseLibrary(0) Define printDriver.s = "WINSPOOL", printerName.s = defaultPrinterName Define *sysDEVMODE, *userDEVMODE, *contextDEVMODE.DEVMODE, docInfo.DOCINFO If OpenPrinter_(printerName, @printerHandle, 0) returnBuffer = DocumentProperties_(0, printerHandle, printerName, 0, 0, 0) *sysDEVMODE = AllocateMemory(returnBuffer) *userDEVMODE = AllocateMemory(returnBuffer) DocumentProperties_(0, printerHandle, printerName, *sysDEVMODE, *userDEVMODE, #DM_OUT_BUFFER) *contextDEVMODE = *sysDEVMODE ClosePrinter_(printerHandle) FreeMemory(*sysDEVMODE) FreeMemory(*userDEVMODE) With *contextDEVMODE \dmOrientation = #DMORIENT_PORTRAIT \dmPaperSize = #DMPAPER_A4 \dmPrintQuality = #DMRES_DRAFT \dmCollate = #DMCOLLATE_TRUE \dmCopies = 1 EndWith With docInfo \cbSize = SizeOf(DOCINFO) \lpszDocName = @"PureBasic Test Print" \lpszOutput = #Null EndWith printerDC = CreateDC_(@printDriver, printerName, 0, *contextDEVMODE) jobId = StartDoc_(printerDC, @docInfo) StartPage_(printerDC) outString.s = "Prints on page 1..." TextOut_(printerDC, 200, 200, outString, Len(outString)) EndPage_(printerDC) StartPage_(printerDC) outString = "Prints on page 2..." TextOut_(printerDC, 200, 200, outString, Len(outString)) EndPage_(printerDC) EndDoc_(printerDC) DeleteDC_(printerDC) EndIf EndIf
in PureBasic versions v5.44LTS and upwards
i get the ERROR = Structure field not found: dmOrientation.
how can i solve this error ?
Code: Select all
   With *contextDEVMODE
      \dmOrientation = #DMORIENT_PORTRAIT
      \dmPaperSize = #DMPAPER_A4
      \dmPrintQuality = #DMRES_DRAFT
      \dmCollate = #DMCOLLATE_TRUE
      \dmCopies = 1     
    EndWith
PureBasic .... making tiny electrons do what you want !
"With every mistake we must surely be learning" - George Harrison
- VB6_to_PBx
 - Enthusiast

 - Posts: 627
 - Joined: Mon May 09, 2011 9:36 am
 
Re: print api
PureBasic .... making tiny electrons do what you want !
"With every mistake we must surely be learning" - George Harrison
- 
				collectordave
 - Addict

 - Posts: 1310
 - Joined: Fri Aug 28, 2015 6:10 pm
 - Location: Portugal
 
Re: print api
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
						Re: print api
Thanks for sharing the solution.dige wrote:...Structure DEVMODE is now changed...
dm.DEVMODE\dmOrientation
change to:
dm.DEVMODE\Printer\dmOrientation
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 