Subject Re: Printing to pdf
From Bernard Mouille <mouille258@orange.fr>
Date Tue, 11 Dec 2018 09:45:00 -0500
Newsgroups dbase.getting-started
Attachment(s) Test.txt

Hello Charlie,

You can try the basic sample with PDFCreator.
Regards,
Bernard.

Charlie Wrote:

> Hi.. I\'m trying to print a report to pdf using a pdf converter.  (It shows up in the printer options).  I\'m using output 1 which is to printer.  Should I be using another output option?  It seems to print and creates a pdf file but the file is blank.
>
> Thanks much for any help!!!




/* Example : print a report.


dBase version      : dBASE PLUS 9.51 Runtime  b2426 (11/24/2014-EN141124)
Windows version    : Microsoft Windows 7 Professionnel  build 7601 32 bits
PDFCreator version : PDFCreator Free v3.3.0 Build 2468

*/

local cError
local PDFCreatorQueue
local fullPath
local printJob
local appPrinterName
local r

//set procedure to \_Programmes\dBase\_Lib\_Lib.cc additive

cError          = "OK"
PDFCreatorQueue = null
fullPath        = set( "directory" ) + "\_Result.pdf"
printJob        = null
r               = null

bd_ferase( fullPath )
bd_ferase( "_Result.txt" )
set alte to _Result.txt
set alte on
? "dBase version   :", Version( 1 )
? "Windows version :", bd_WindowsVersion()
?
? "Directory       :", set( "directory" )
? "_app.printer    :", _app.printer.printerName
? "Default Printer :", bd_GetDefaultPrinter()
?

appPrinterName = _app.printer.printerName
_app.printer.printerName = "PDFCreator"



PDFCreatorQueue := bd_CreateObject( "PDFCreator.JobQueue" )
if PDFCreatorQueue == null
   return
endif

? "Initializing PDFCreator queue..."
PDFCreatorQueue.Initialize()
? "Printing a report."

r = new TestReport()
r.output = 1
r.pagetemplate1.textlabel1.text = "Test print a report in pdf wirh PDRCreator."
r.render()

? "Waiting for the job to arrive at the queue..."
if not PDFCreatorQueue.WaitForJob( 30 )
   ? "*** The print job did not reach the queue within 30 seconds."
   cError := "The print job did not reach the queue within 30 seconds."
endif

if cError == "OK"
   ? "Currently there are " + bd_lstr( PDFCreatorQueue.Count() ) + " job(s) in the queue."
   ? "Getting job instance."
   printJob := PDFCreatorQueue.NextJob()
   printJob.SetProfileByGuid( "DefaultGuid" )
   ? 'Converting under "DefaultGuid" conversion profile'
   printJob.ConvertTo( fullPath )
   if not printJob.IsFinished() or not printJob.IsSuccessful()
      ? "*** Could not convert the file : " + fullPath
      cError := "Could not convert the file : " + fullPath
   endif
endif

if cError == "OK"
   MsgBox( "Job finished successfully." )
else
   MsgBox( cError )
endif

? "Releasing the PDFCreator object."
if PDFCreatorQueue <> null
   PDFCreatorQueue.ReleaseCom()
endif

// Restore the dBase printer default.
_app.printer.printerName = appPrinterName

?
? "Directory       :", set( "directory" )
? "_app.printer    :", _app.printer.printerName
? "Default Printer :", bd_GetDefaultPrinter()
?
set alte off
set alte to

PDFCreatorQueue := null
printJob        := null
r               := null

return

class TestReport of REPORT

    with (this.printer)
       printerSource = 2
       duplex = 1
       orientation = 1
       printerName = "PDFCreator"
       paperSource = 15
       paperSize = 9
       resolution = 0
       color = 2
       trueTypeFonts = 3
    endwith

    this.PAGETEMPLATE1 = new PAGETEMPLATE(this)
    with (this.PAGETEMPLATE1)
       height = 16837.0
       width = 11905.0
       marginTop = 1080.0
       marginLeft = 1080.0
       marginBottom = 1080.0
       marginRight = 1080.0
       gridLineWidth = 0
    endwith

    this.PAGETEMPLATE1.STREAMFRAME1 = new STREAMFRAME(this.PAGETEMPLATE1)
    with (this.PAGETEMPLATE1.STREAMFRAME1)
       height = 11592.0
       left = 360.0
       top = 1365.0
       width = 9360.0
       form.STREAMFRAME1 = form.pagetemplate1.streamframe1
    endwith

    this.PAGETEMPLATE1.TEXTLABEL1 = new TEXTLABEL(this.PAGETEMPLATE1)
    with (this.PAGETEMPLATE1.TEXTLABEL1)
       height = 300.0
       left = 855.0
       top = 630.0
       width = 1080.0
       text = "Textlabel1"
       form.TEXTLABEL1 = form.pagetemplate1.textlabel1
    endwith

    this.firstPageTemplate = this.form.pagetemplate1
    this.form.pagetemplate1.nextPageTemplate = this.form.pagetemplate1

endclass

// Tools functions.

// Open an Ole COM program.
function bd_CreateObject( cOle, lMsgBox )
   local oOle
   if argcount() < 2
      lMsgBox = true
   endif
   try
      oOle = new OLEAutoClient( cOle )
   catch ( Exception e )
      if lMsgBox
         msgbox( "Fail Ole COM : " + cOle, "Open an Ole COM", 16 )
      endif
      return null
   endtry
   return oOle

// Erase a file.
procedure bd_fErase( cFile )
   if new file().exists( cFile )
      new file().delete( cFile )
   endif
   return

// Get the default printer.
function bd_GetDefaultPrinter()
   local oLocator
   local Items
   local oWMI
   local cReturn
   local i
   oLocator = new OleAutoClient( "WbemScripting.SWbemLocator" )
   oWMI     = oLocator.ConnectServer( ".", "root\cimv2" )
   Items    = oWMI.ExecQuery( 'Select * from Win32_Printer' )
   cReturn = ""
   for i = 0 to Items.count - 1
      if Items[ i ].Default
         cReturn := Items[ i ].Name
         exit
      endif
   endfor
   oLocator := null
   Items    := null
   oWMI     := null
   return cReturn

// Convert a number in string without space before.
function bd_lstr( nNum, nInt, nDec )
   if argcount() < 2
      nInt := 16
   endif
   if argcount() < 3
      nDec := 0
   endif
   return ltrim( str( nNum, nInt, nDec ) )

// Return the Windows version in a string.
function bd_WindowsVersion()
   local oLocator
   local oSys
   local oWMI
   local cReturn
   oLocator  = new OleAutoClient( "WbemScripting.SWbemLocator" )
   oWMI      = oLocator.ConnectServer( ".", "root\cimv2" )
   oSys      = oWMI.ExecQuery( 'Select * from Win32_OperatingSystem' )
   cReturn   = oSys[ 0 ].Caption + " build " + oSys[ 0 ].BuildNumber
   oLocator := null
   oSys     := null
   oWMI     := null
   return cReturn



Warning: Unknown: write failed: No space left on device (28) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0