Hot Topic (More than 10 Replies) Sbasic command to take a snapshot of form (Read 3034 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Sbasic command to take a snapshot of form
Mar 10th, 2012 at 3:39pm
Print Post Print Post  
Goal:  to have Sesame programmatically take a snapshot (image file format, pdf file format, ??) of a form on the screen, then save it to a filename (file name determined by a variable).

Payoff:  to print large batches of invoices, have the program differentiate paper printed invoices from those which should be emailed.  On the 'email' candidate invoices, Sbasic grabs the invoice # in the invoice# field, saves a FormView in an image file format (using that Invoice# variable to name the file; further programming will then automatically email the invoice file to the client).

PrintAFormToHTML  doesn't print correctly FormView Subforms that have been toggled to tableview, and as someone here pointed out, there are security issues with sending an html file as an invoice (file could be inadvertently(or not!) altered).   

If this supposed approach won't work, any other suggestions?  We have the potential to print/send 300 - 400 invoices via email each month .... too many to print each one manually to a pdf and then email manually.
  

Larry
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Sbasic command to take a snapshot of form
Reply #1 - Mar 10th, 2012 at 7:27pm
Print Post Print Post  
Are you able to printout the invoices on paper using Printstring ( ) commands? If you can or if you are already doing so, instead of printing them out, print them to pdf printer, that will make pdf file that you can attach to email. Printing out subform records through printString ( ) commands is do-able.
  
Back to top
 
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Sbasic command to take a snapshot of form
Reply #2 - Mar 11th, 2012 at 2:41pm
Print Post Print Post  
Bharat,

Here is an example of my current invoices - http://www.wordcom.com/28441.jpg .  My customers like the easily viewed/easily found, colorful format. 

We generate/print invoices in batches - key in a string of sales order numbers; then the programming finds those sales orders and loops through, converting the sales order into the invoice format that you see in the example, prints it (PrintAForm); then changes the form back to SalesOrderVisual format; then loops on and repeats for the remainder of the string of sales orders.

We generate about 600 invoices a month (invoicing everyday for quick cashflow turnaround - thanks Sesame!), and could perhaps convert half of those to emailed instead of printed.  But I don't want to manually have to assign a pdf name to each invoice, then manually attach it to an email.  I want the invoicing programming to 'know' which invoices to email, grab the sales order # and 'print the invoice to a file (using the grabbed sales order # as the filename, then have Sesame programmatically attach that just-saved-file and email it to the client; then move on to the next invoice in the string to process.

That would offer tremendous time/money savings, and is a 'scale-up-with-no-additional-effort solution.

The programming is done, but the PrintAFormToHTML doesn't print correctly my SOLines subform from a formview toggled to Tableview (only prints the first record in form view).  And there's the security issue of the client being able to edit the html file.

So, regardless of the print command used, there isn't currently a way I know of to programmatically "print"/convert" the WYSIWYG form into a saved file (using a Sesame variable as the filename). 

Modified:  Actually, the product at this link http://www.converthtmltoimage.com/Usage.html  might be a good answer for having Sesame convert an html file to an image file and then email.  But it still leaves me with PrintAFormToHTML not printing converted-formview-to-tableview subform correctly.  So I'm still stumped.
  

Larry
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Sbasic command to take a snapshot of form
Reply #3 - Mar 11th, 2012 at 3:38pm
Print Post Print Post  
You could set up a parallel form that is linked to the same database, that has the relevant sub-form started in table view.

PDFs and images files are also easily editable. There are things you can do with any kind of file to detect if the user has messed with it, but only if the user sends it back in the same format.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Sbasic command to take a snapshot of form
Reply #4 - Mar 11th, 2012 at 7:27pm
Print Post Print Post  
Mark,

But I had something else to do this afternoon (LOL)!

That's an interesting angle (mostly parallel form to the same underlying database?).
   
So the invoicing would actually take place then using the parallel form .... Hmmm, so I just design an Invoice Form that links to the same Sales Order database fields  ... I'll  let my subconscious start planning this, and let you know how it's going.

Or else maybe just a parallel tableview SOLines2 form, using the underlying SOLines database fields, and then for invoicing purposes just make the SOLines subform (formview) Invisible, and the SOLines2 subform (tableview  form) visible, print, then revert and loop.

Thinking outloud - then I'd use PrintAFormToHTML to print the 'to be emailed' invoices from the InvoiceForm to a Invoice#.html filename, then have Seseame shell  out 'convertHTMLtoImage' command line conversion of that filename to an image file, then have Sesame email pickup the file and email it to the client.

That might work out.  Guess I know what I'm doing the rest of March!
  

Larry
Back to top
IP Logged
 
Rick_R
Full Member
***
Offline



Posts: 243
Joined: Jan 29th, 2010
Re: Sbasic command to take a snapshot of form
Reply #5 - Mar 11th, 2012 at 9:47pm
Print Post Print Post  
There are a number of programs that will print to a PDF completely programmatically, although I don't know of a particular one offhand.

One key approach is to always print to the same filename, e.g., "Invoice.pdf".  Then have Sesame rename that file. That should simplify all coding outside Sesame to a single command line.

Then have Sesame choose whether to print or email that file.  So, for example, you could have Sesame print to Invoice.pdf, rename that file, e.g., Babylon-Services-Invoice-03-12.pdf, then add to a Sesame table the name of the invoice and the recipient's email.  Then later run a separate routine that reads through that table, emails the file to the address, and records the date and time of emailing (or hardcopy printing).

If you can't find a program that will print to PDF completely programmatically, look into AutoHotKey.com.  You can create complex Windows macro scripts with it than can run other programs.  Call that script from Sesame.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Sbasic command to take a snapshot of form
Reply #6 - Mar 12th, 2012 at 5:22pm
Print Post Print Post  
Rick_R wrote on Mar 11th, 2012 at 9:47pm:
There are a number of programs that will print to a PDF completely programmatically, although I don't know of a particular one offhand.


PDF995 has a PDF995.ini file that has an entry: "Output File=". This allows you to automate the filenaming. I believe PDFCreator has something similar.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Sbasic command to take a snapshot of form
Reply #7 - Mar 13th, 2012 at 12:27am
Print Post Print Post  
Mark,

I added a second subform (SOLTV) to my Orders form, set in table view.  The whole Order form now is just better - many benefits from your suggestion.  Many thanks.

I'll look into pdf995.     PrintAFormToHTML doesn't give me my same crisp printed output (example here ... http://www.wordcom.com/29087.html ).  I can tweak some stuff around - any suggestions on how to make it more readable/attractive - specifically how to get PrintAFormToHTML to print the field labels (columns)?

  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Sbasic command to take a snapshot of form
Reply #8 - Mar 13th, 2012 at 4:20pm
Print Post Print Post  
I had used PDF995 in the past, but started using free BullZip PDF printer a few years ago instead.  Link for info here: http://bullzip.com

From their features page:
============================
Features

    Print to PDF from almost any Windows program.
    Runs on Microsoft Windows 2000/XP/XP x64/2003/2003 x64/Vista/Vista x64/2008/Windows 7.
    Supports 64-bit operating systems.
    Direct output to the same file each time or prompt for destination.
    Control if the printer should ask if you want to see the resulting PDF document.
    Control output and prompts programmatically.
    Setup can run unattended.
    Graphical user interface.
    Password protect PDF documents.
    128/40 bit encryption.
    Quality settings (screen, printer, ebook, prepress).
    Set document properties.
    Watermark text, size, rotation, and transparency.
    Superimpose/background documents.
    Appending/prepending documents.
    User interface control.
    Command line interface to all settings.
    COM/ActiveX interface for programmatic control.
    Support for Citrix MetaFrame
    Support for Windows Terminal Server
    Multiple output types supported: BMP, JPEG, PCX, PDF, PNG, and TIFF.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Sbasic command to take a snapshot of form
Reply #9 - Mar 13th, 2012 at 5:36pm
Print Post Print Post  
Hi Bob,

That's ironic.  We have used Bullzip for years here.  But when I was looking for this 'command line' solution a year ago, I couldn't detect that they offered that capability.

I have downloaded pdf995, and their docs say that their little program omniformat.exe and its converter "html2pdf995.exe" will do exactly what I need it to do ("c:\omniformat\html2pdf995.exe" "www.software995.com" "c:\pdf995\output.pdf").  I should be able to have Sesame CreateAProcess and execute this command line command, then grab the result and email it to the client.  I'll implement/test it this week and report on the results.  Fingers crossed!
  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Sbasic command to take a snapshot of form
Reply #10 - Mar 14th, 2012 at 4:19am
Print Post Print Post  
The documentation was hard to find at first.  Here is an explanation: PDF Printer - User Guide

The Bullzip PDF Printer is a limited free edition of the PDF Writer from bioPDF. There are very little technical differences between the edition from bioPDF and the freeware version. This means that you can use the documentation for the PDF Writer at www.biopdf.com as long as you take into consideration that small differences may apply.
Here is a link to the documentation:  http://www.biopdf.com/guide/


This is the syntax for BullZip Print To File:
USAGE:
  printto "file name" ["printer name"]
------------------
Here's a link to the Command Line instructions with BullZip: http://www.biopdf.com/guide/examples/command_line/

==================
Edited:  Never mind.  I just checked my latest version and it no longer has the "printto.exe" file.  I had this in an older version of BullZip, and may be able to locate it for you, but no need because PDF995 will do it for you.  So, no optional program to offer you.  Good luck.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Sbasic command to take a snapshot of form
Reply #11 - Mar 15th, 2012 at 2:46am
Print Post Print Post  
pdf995 (omniformat) didn't get the job done - way too slow.

I found a program www.converthtmltoimage.com  that did the trick.  It converts the html file to a jpeg image file (or .bmp, gif, png, etc, as you wish) with command line switches for lots of options.  It's very fast.  Sesame creates a batch file to get to the convert directory and then calls the command line string that converts the html invoice to a jpeg invoice, then emails the image to the client. 

PrintAFormToHTML was obscuring the subform's tableview's last line item, and converting it to an image file meant the client wouldn't be able to see this last line item on the invoice.  So I included a snippet that, on the fly and for emailed invoices only, adds a Spacer line item to the that Sales Order SOLines subform.  Here's the piece of code in question (I just got it working tonight, so it's not waxed and buffed) ...

                   {
                                                         If (vMailDiff = "") or ((vMailDiff <> "") and (vInvoiceEmailAddress = ""))
                                                           {
                                                           vPrt = @PrintAForm(0, 1, 1, 0, 28, -1, -1, -1, -1, 1, 1)
                                                           vQtyPrinted = vQtyPrinted + 1
                                                           vSONumsPrinted = vSONumsPrinted + vSONum + ";"
                                                           }
                                                           else if (vMailDiff <> "") and (vInvoiceEmailAddress <> "")
                                                                 {

                                                                        vNSOR = @FormNewRecord("SOLTV")
                                                                       FormFieldValue("SOLTV", "ItemNum", vNSOR, "SPACER")
                                                                       FormFieldValue("SOLTV", "SONum", vNSOR, vSONum)
                                                                       FormCommit("SOLTV")
                                                                       ForceRedraw()                                                                   
                                                                  
                                                                   vPrt = @PrintAFormToHTML("w:\sesame2\Invoices\MycompanyInvoice" + vSONum + ".html")
                                                                  
                                                                   If vPrt = 1
                                                                     {
                                                                       FileOverWrite("w:\sesame2\convert.bat", "")
                                                                       vInvoiceHTML = "MycompanyInvoice" + vSONum + ".html"
                                                                       vInvoice = "w:\sesame2\Invoices\" + vInvoiceHTML
                                                                        
                                                                       vConvertHTMLtoImage = "converthtmltoimage.exe /file" + " " + @chr(34) + "w:\sesame2\invoices\" + vInvoiceHTML + @chr(34) + " /dir " + @chr(34) + "w:\sesame2\invoices" + @chr(34) + " /name " + @chr(34) + "MycompanyInvoice" + vSONum + @chr(34) + " /quality " + "80"
                                                                       FileOverWrite("w:\sesame2\convert.bat", "c:" + @NewLine() + "cd\" + @NewLine() + "cd" + " " + @chr(34) + "program files" + @chr(34) + @NewLine() + "cd" + " " + @chr(34) + "convert html to image" + @chr(34) + @NewLine() + vConvertHTMLtoImage)
                                                                       
                                                                       CV = @Shell("w:\sesame2\convert.bat")
                                                                       Loiter(2000)
                                                                       vInvoiceImage = "w:\sesame2\Invoices\MyCompanyInvoice" + vSONum + ".jpg"
                                                                 
                                                                       If FileExists(vInvoiceImage)
                                                                         {

                                                                             vEmail = @sendmail("smtp2go.com","MyCompany Invoice " + vSONum,"Myserver@gmail.com",vInvoiceEmailAddress,"","","","","",vInvoiceImage)
                                                                             vEmailInvoices = vEmailInvoices + vSONum + ";"
                                                                             vQtyEmailInvoices = vQtyEmailInvoices + 1
                                                                             
                                                                         }
                                                                           else
                                                                             {
                                                                                   vEmail = @Sendmail("smtp2go.com","MyCompany Invoice " + vSONum + " failed","Myserver@gmail.com","myemail@gmail.com","","","","","")
                                                                                   vFailedEmailInvoices = vFailedEmailInvoices + vSONum + ";"
                                                                                   vQtyFailedEmailInvoices = vQtyFailedEmailInvoices + 1
                                                                             }
                                                                     }
                                                                       else if (vPrt = 0)
                                                                            {
                                                                             vFailedEmailInvoices = vFailedEmailInvoices + vSONum + ";"
                                                                             vQtyFailedEmailInvoices = vQtyFailedEmailInvoices + 1
                                                                             Writeln("error: Failed to create " + vSONum + ".html")
                                                                             vEmail = @Sendmail("smtp2go.com","MyCompany Invoice " + vSONum + ".html failed to write to disk","Myserver@gmail.com","myemail@gmail.com","","","","","")
                                                                             
                                                                                }
                                                                  
                                                                              
                                                                  }
  

Larry
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Sbasic command to take a snapshot of form
Reply #12 - Mar 15th, 2012 at 4:33am
Print Post Print Post  
Thanks for the clue.  Will grab a copy for my toolbox.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged