Home >>>                                                               Our Products Purchase Contact Us FAQ
           
 

  FAQ

How do you display PDF files in a PowerBuilder application.

Printing from Word

Fax Programs

Printing DW to Epson TM

Adobe PDFWriter call from EAS PB component

Print an excel sheet though PB 7.0.3

How do I change printers in the code without prompting the user?

Can I specify a printer (other than default) on the fly and print a report on it?

How do I save a datawindow in the same format as I see it?

How do I replace the PB7 "PrintSetup" with a dialog that will enhance functionality so that the cancel button on the printsetup dialog can be recognized and not start print functions?

How do I change the printer either by prompting the user OR do it behind the scene without prompting the user and make that the default printer of the application so that anything you print after that should print to what the user selected OR you defined as the application printer?

Will the print app let users select which pages they want to print out of a datawindow instead of printing the whole thing?

How to send fax automatically?

When I use DW SaveAs and  when the file is exported, the format of the column is not the one I set in the create statement, instead it is using the data source format. 

PDF Driver


How do you display PDF files in a PowerBuilder application

If you have a pdf file and want to launch Acrobat Reader outside of PB, then
you can simply use the following:


1) Declare as an external function:
function ulong ShellExecuteA(ulong hwnd, String lpOperation, String lpFile,
String lpParameters, String lpDirectory, long nShowCmd) library
"shell32.dll"


2) Call the function with the pdf file name as an argument

String ls_Null
String ls_Pdf = 'c:\mypdffile.pdf'

SetNull (ls_Null)
ShellExecuteA (Handle (Parent), ls_Null, ls_PDF, ls_Null, ls_Null, 1)

 

 

Printing from Word

ls_connect = "word.application.8" // whatever
IF ole_object.ConnectToNewObject(ls_connect) = 0 THEN
ole_object.Documents.open(ls_filename)
ole_object.Visible=FALSE
ole_object.ActiveDocument.printout(0) // txt
ole_object.quit(0) // do not save
ole_object.DisconnectObject()
end if

OR You can display the commands by within WORD, tools, record then edit a macro, .

Fax Programs

WinFax Pro 10.0 is extremly easy to control from powerbuilder - and
with price around $40 it's good way to go. They have fully documented API's. Check out http://www.symantec.com/winfax/ for details.
For FAX take a look at faxman & faxman jr at www.data-tech.com
I have used it with PB 7 to send faxes. It works great. It comes with a 10,000 user license. It also comes with PB samples.

 

Printing DW to Epson TM

Either use
retp = dw_3.Print()

OR If you need tighter control over printer check codes and send them to printer
/// example for cash drawer send sequence "~h82"
long Job
Job = PrintOpen( )
PrintDefineFont(Job, 1, "16 cpi", &
-10, 400, Default!, AnyFont!, FALSE, FALSE)
PrintSetFont(job,1)
Print(Job, "~h82")
PrintClose(Job)

Adobe PDFWriter call from EAS PB component

PDFWriter does not work when called from an NT service. PDF Writer only works with a logged on account. If you try to call the PDF Writer from EAServer when it is running as a service it won't work because the service isn't running under the guise of a user.

PDF Converter, which you can find at http://www.amyuni.com/pdfpd.htm#pdfconvdesc. " is only about $100, and it works just fine.

 

Print an excel sheet though PB 7.0.3

Record a macro in Excel to see what it does for printing. It comes
out with:
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

 

How do I change printers in the code without prompting the user?

Utility at www.powerwhizz.com. You can accomplish this by calling functions in the Non-visual userobject provided to get and set default printer. This also calls windows API to change the default printer. 

1. You can prompt the user or call the function in the code to print to a specific printer and then print your report to that printer.

2. When you are done printing this report you can switch to another printer and then print to that printer 

Useful functions:

  • Get the Printers information into the DW/DS

            inv_printer.of_GetPrinters(Datawindow dw)

            inv_printer.of_GetPrinters(Datastore ds)

  •  Get the Default Printer Name:

s_printer = inv_printer.of_GetDefaultPrinterName()

Returns the default printer name in the format: 

"printer name,driver,port "

E.g. HP LaserJet 5P/5MP PostScript,PSCRIPT,FILE:

  • Set the Default Printer for Windows:

inv_printer.of_SetDefaultPrinterName(s_printer)

  • Set the OS Default printer to the one passed in as argument:

You can either pass just the "printer name" or "printer name,driver,port "

E.g. Printer Name = "HP LaserJet 5P/5MP PostScript"

Printer name,driver,port = "HP LaserJet 5P/5MP

PostScript,PSCRIPT,FILE:"

 

Can I specify a printer (other than default) on the fly and print a report on it?

You can specify a different printer on the fly for your reports or datawindows either by prompting the user with a friendly GUI or in the code. Utility at www.powerwhizz.com. Powerhwhizz accomplishes this by switching the OS default printer for the time the DW/DS is being printed and then switches the OS default printer to the original printer. In PB 8, it does not switch the OS default printers to print to non-default printers.

 

How do I save a datawindow in the same format as I see it?

If you want to save in WYSWYG format, the only way it can be done is if the report is in NOT in composite format. If it is a nested report and has columns that are type DDDW then you will see the (id) values like saving in text format.

The only option to save the report in WYSWYG format is either in PowerBuilder PSR or Acrobat ADOBE PDF format. You need to have the Adobe PDF Writer installed to print in PDF format.

Using Powerwhizz Printer utility you can print in PDF format with/without prompting the user for filename. The other benefit of this utility is that it works on Win 95/98/NT. The default OS printer is changed during this operation but is reset once the print is complete so the change is transparent to the user.

How do I replace the PB7 "PrintSetup" with a dialog that will enhance functionality so that the cancel button on the printsetup dialog can be recognized and not start print functions?

Utility at www.powerwhizz.com.The "Printer Selection Values" commandbutton on the third tabpage "Print window" does returns the values the user selected in the Print window and does not print. You can also detect whether the user clicked OK or Cancel. The printer attributes are returned in the structure.

 

How do I change the printer either by prompting the user OR do it behind the scene without prompting the user and make that the default printer of the application so that anything you print after that should print to what the user selected OR you defined as the application printer?

Utility at www.powerwhizz.com.There are several ways of implementing this. One way to do it is: 

You declare one instance variable in your n_cst_appmanager

- Type string is_applicationPrinter

If the user is going to be prompted then after the user selects the printer once populate the is_applicationPrinter instance variable with the Printer name the user selected.

If the user is NOT going to be prompted and you know what printer to print to you don't even need to maintain this instance variable. You can just populate the structure with the printername and b_hideWindow boolean set to true..Check the next step.

Later, whenever the user wants to print to that Printer without prompting the user to select a printer, you populate the following attributes of the s_printdialogattribute Structure

- boolean b_hidewindow = True (required to hide the window)

- string s_printer = is_applicationPrinter OR Printer Name to which you would like to Print (required to print to a specific printer)

Additional Attributes (OPTIONAL):

E.g.

- integer i_papersource (optional if you want the user to always print to a specific paper source. In this case you will have to maintain another instance)

- integer i_papersize(optional if you want the user to always print to a specific paper size. In this case you will have to maintain another instance)

- boolean b_landscapeorientation (optional if you want the user to always print in a specific orientation)

You can specify additional attributes in the structure to customize this further. After populating the structure you can call the function in n_pwhizzPrinter NVO to print a DW/DS

- of_Print (datawindow adw, s_printdialogattribute as_attrib)

- of_Print (datastore ads, s_printdialogattribute as_attrib)

 

Will the print app let users select which pages they want to print out of a datawindow instead of printing the whole thing?

Yes! it can print Odd, Even or the pages you specify.Utility at www.powerwhizz.com.

 

How to send fax automatically?

Check FAXMan at http://www.data-tech.com/Products/FaxMan/faxman.htm
 
It is a fully programmable FAX driver that gives you control over every aspect of the Fax process.

It depends, what kind of faxing program you are going to use. I've the
solution for the Symantec WinFax Pro 9 (I think it's a better faxing program
for now, but it just mine mind ;-) ).
So, normaly, you have to use OLE or DDE to set some properties in the fax
program, and next you have to print the document you want to fax through the
fax driver...

First of all, you have to download an SDK for the WinFax
ftp.symantec.com/misc/americas/rps/winfax/sdk/wfxsdk.zip  
ftp.symantec.com/misc/americas/rps/winfax/sdk/wfxsdk.pdf 

The PDF file contains (almost) whole documentation about the ole objects in
WinFax...

Here is some code for the begining... Be sure you are calling the Sleep
funciton. You will not
find it in the documentation, but without it your code will not work
propertly....



First, make this local external function declaration:

Subroutine Sleep (ulong dwMilliseconds) Library "KERNEL32.DLL"

OleObject lole_send
long ll_ret

lole_send = CREATE OleObject
ll_ret = lole_send.ConnectToNewObject("WinFax.SDKSend")
if ll_ret <> 0 then
MessageBox("Error!","Couldn't connect to the WinFax OLE server (return code
" + string(ll_ret) + "). Please check your WinFax installation!",StopSign!)
return
end if
// Now some settings
lole_send.LeaveRunning() // in the SDK documentation they recomended to
do this...

lole_send.ResetGeneralSettings()
lole_send.RemoveAllRecipients()

lole_send.SetNumber(as_number)
lole_send.SetTime(string(RelativeTime(now(),3600),"hh:mm:ss")) // Setting
the send time on hour after this moment

if lole_send.AddRecipient() <> 0 then
MessageBox("Error","Error adding recipient!",StopSign!)
lole_send.DisconnectObject()
DESTROY lole_send
return
end if

lole_send.SetPreviewFax(0) // We don't want to notify user, do we?
lole_send.SetUseCover(0) // Turning off the cover sending
lole_send.ShowCallProgess(0) // We don't want to notify user, do we?

lole_send.SetPrintFromApp(1) // Set this, if you want to send a fax via
printing
// form application.
Otherwise you have to play with
// Attachment functions...
(see SDK reference)

lole_send.Send(0) // Sednin' it ;-)

//
// Here is a place for your code, which is printing on the WinFax printer
driver

Sleep(200) // You MUST have this delay, othewise you'll get a Send
dialog box

lole_send.Done() // Do some clean-ups

Sleep(200) // You MUST have this delay, othewise you'll get a Send dialog
box

lole_send.DisconnectObject()
DESTROY lole_send

Sorry, some correction of the code (It's amazing, but WinFax doesn't work as
described in the SDK at all :-((( ).

First correction:
----------------

lole_send.SetTime(string(RelativeTime(now(),3600),"hh:mm:ss")) // You have
to add this line below:
lole_send.SetDate(string(Today(),"mm/dd/yy")) // Without this function
send() doesn't work at all :-(


Second correction:
-------------------

*Before* and *after* your code which prints the document on the Winfax
driver, add this code:

DO WHILE lole_send.IsReadyToPrint() <> 1
Yield()
LOOP

------------------------------
If you will not do this, you'll get a Send dialog box :-(



Check out FAXMan at http://www.data-tech.com/Products/FaxMan/faxman.htm  

It is a fully programmable FAX driver that gives you control over every aspect of 
the process.

 

 

Using the following syntax, I've created datawindow objects with specific format (esp. for objects with a datatype of datetime, date, decimals)in a datastore.

<DW Control Name>.Modify(&
"create column(name=xx id=xx band=xx format=xx ) ")

I then use dwcontrol.SaveAs ( { filename, saveastype, colheading } )to save it to a file for export purpose, but when the file is exported, the format of the column is not the one I set in the create statement, instead it is using the data source format. e.g I set the format for a datetime column as 'dd/mm/yyyy', but when exported out, the format becomes 'dd/mm/yyyy hh:mm:ss'.

I was told it might be because the SaveAs function ignore the datawindow display format and uses the source datatype format.

Can I change the source datatype format to the format I needed somewhere? Or Can anyone think of another way around this format problem.



It goes by your control panel settings and uses the raw buffer data. 

This is very dangerous for export/import by other users if you don't have specific checks for shortdate and longdate formats in the registry before you import the file.

(In other words enforce a specific date format in the registry on startup and make sure you're users have their systems set this way (by using RegistryGet()) before allowing them to import this text file.

 

 

Amyuni has developed a PDF driver = that is really attractive from a licensing standpoint. For roughly = $1,100US, you get a full site license of their PDF writer (which comes = as either an ActiveX control or a DLL), and can freely distribute it to = all the PCs in your organization. For us as an ISV, we get to embed it = in our application suite and distribute it royalty free. I think the = link there is www.amyuni.com 
For other PDF resources, the best site I've found is www.planetPDF.com
Another vendor is Zeon: http://www.zeon.com.tw 
Use PSR format (SaveAs) and make a PSR viewer for your clients :)


Copyright © 2002 Powerwhizz.com.
Last updated: February, 2003