Report filtering email as pdf

ok I’m looking at adding a delay before sending email action in rule. I know to create an execute automation command that has delay . but do I have to create a auto command and set it to send email action ? or is there another way to delay sending?

I’m thinking of when work period ends, then it will come up with save report area, with cutepdf installed it auto puts a sample name. then I put that sample name in send email action, and just before it fires that send email action, it waits about 1 minute before sending.

I’ve been using pdfcreator for years (before they started the commercialisation). However I can say the free version does included all those features on that page and there isn’t anything disabled. Just the free installer has ads in it which of course you just decline, and they claim the free version isn’t meant to be used for business purposes - however that’s against the free open source license and even their license page doesn’t say that so can just be ignored. Also make sure you don’t install PDF architect as well (I believe default it will install) as that is a trial version which you don’t need.

The free version has a few options you can use - you can set it to auto save using specific rules for saving files. You can also even get the pdfcreator to email the file (always an alternative route to check).

There is also a COM interface so it should be able to be integrated with .net applications if that were a future option to link with SambaPOS.

2 Likes

3 Likes

Yes! That solved 1 thing. Now for emailing that particular file. Since it auto generates filename, what value would I need to set in send email action?

Speaking of email, I will actually try to send email via pdfcreator and see how well that works :smile: thanks for all the input guys

2 Likes

I just gave an example how you could set the filename to use the date, but this might not work very well for you in this case, since you won’t know what the actual date/time filename is going to be.

I think it might be better to use the Save Report Action to save the Report to XPS then convert it to PDF, because when we Save the Report, we can choose the filename.

Here is a COM method using JScript …

I have yet to test the COM method. I’m just testing out the pdfcreator method which sends an email as soon as it creates the PDF.

If this works, then even though it’s relying on a third party application, will still be better to use as it’s really quite simple to set up.

But I’ll definitely check that COM method out for a more integrated solution :smiley:

UPDATE: Ok so using PDF creator, i was able to create the PDF report.

And I also received an email with the report successfully.
However there is only one issue I found with this method.

In Reports


When click Print… Since the terminal was set to PDF printer, it Prints and sends that report also…

Now ideally it would be nice to have both options. The rule I created for before end work period work perfectly fine in printing out work period report and pdf creator converting it and sending it. But I may have to set it back to ticket printer, in order for client to print it, but then using the save report rule I made earlier, I may have to get the application to monitor the folder I set for the reports to be saved, then change .xps to pdf. Then get Samba to send the email instead of pdf creator… unless there is another way to do this…

I may take a look at the COM script and fiddle around a bit. I wonder if pdfcreator can monitor and convert?

I am having some issues with the COM method. It works just fine with certain file types like TXT, but with XPS it does not work properly.

It has to do with the way the COM method actually works.

  • opens the file using the associated application in a hidden window
  • prints the file to the PDF Creator printer, using one of the profiles

With TXT it actually opens the file in Notepad in a hidden window, then prints.

With XPS it opens the file in XPS Viewer then attempts to print, but instead of doing so automatically, it brings up the Choose Printer dialog, which is frozen. Then XPS Viewer crashes, and no print/conversion is made.

EDIT: today it is working (sort of) … the Choose Printer dialog comes up, with PDF Creator already selected, so I just click the Print button and it makes the PDF, then PDF Viewer closes. Unfortunately, that is not automatic in that I must click a Print button grrrr.

Anyone know a way using PDFCreator or any other tool to simply perform a conversion without opening the source file?


The COM method would definitely be the way to go with this if it worked properly, because it gives you ultimate control over the filename and path…

Hey @QMcKay
None of this helps does it?

/PrintFile="Path\Filename.extension"
 Print a file with the standard program linked to the extension of the file. In general, this option is useful in connection with Auto-Save mode.

Example: pdfcreator.exe /PrintFile="C:\help.doc"

URL:
http://www.pdfforge.org/pdfcreator/manual/command-line-parameters

ce there is an API link there as well. Not Avaialble!
My original thoughts were to use command line parameters to convert fom XPS -> PDF via some sort of script (old school).

That command-line parameter does the same thing as the COM method. It opens the source file in its associated application, prints the file, then closes the application.

So in the case of XPS files, XPS Viewer is launched with the source file, then the Print command is invoked. Same case holds true though - the Choose Printer dialog appears and waits for you to click Print.

I think the solution to this might be to get a different XPS viewer application.

I can open the files in IE or in the “Reader” app in Win 10, but when I try to execute my COM script, it gives me the following error, even though I have correctly associated the XPS extension with IE/Reader …

That error ^ is caused by the ShellExecute() function in the script, which attempts to open a file using the associated application…

objShell.ShellExecute(filename,"", "", "print", 2);

Using the command line parameter after associating .xps to IE gives this error …

Did you tried setting your printer type as Windows Printer? Leave Printer name as . (dot) and it should display printer selection dialog.

Currently got the pdf printer set to raw, as it produces the Page u saw above during conversion. And even when u do a test print with pdfcreator the data type is raw. Having a dialogue is fine, but I think I may need to make a email delay action to put into send email rule… To give it time to save and convert to pdf then for samba to send email. Upon saying this the name of the file has to be uniquely set to work…
Whereas currently with pdfcreator, it generates date and time as file name then sends it via email through the pdfcreator app not samba.

The issue I have here is that I want to be able to keep the report to still be printed physically through ticket printer, but when work period ends, the work period report saves a pdf file and then sends it. In this case it would convert the saved xps file then send it. Having both on email and print on report screen can be reallllllllly useful. There is the save button on report, which then can be used in a rule to send after saving file. But it still requires a pdf conversion before sending automatically… or at least in reports when you do click save, having an ask question to say whether you want to email report or not would be awesome too. But anyway in meantime I’m gonna work on trying get both physical print and file conversion happening with email solution.

PDFCreator will allow you to create multiple Windows Printers that use different profiles. So you can have one that prints to file only, and another that prints to file then emails.

If you take Emre’s suggestion you set the report printer up like that then you get the dialog when you initiate printing report. But when you use an Action to print report, you can specify the printer and for that you would have another printer in SambaPOS set to go to your “Print then Email” printer.

1 Like

@markjw I knew I could create a new profile but something completely threw me off. thanks :smiley: .

also emre I saw why you said to change data type, the document looks much better.

ok so I managed to get it working 100% :smiley:.

it all had to do with PDFcreator profiling.

  1. I created 2 profiles. save only with print document action


    and ‘save and email’

  2. then under application settings I went to ‘printers’ and created 2 printers. then for each printer appointed a profile

  3. in samba I made 2 printers.
    'PDF Print Save


    PDF Save-Email

  4. I set terminal report printer

  5. created an action

  6. created a rule

now when I click ‘print in report’


it saves and does a physical print(as requested)

and ending work period now saves a PDF an send email automatically

:smiley:

I wonder if I should make this into a tutorial . maybe be helpful to others.

thank you everyone for all your help. I’m sorry if I annoyed anyone.

6 Likes

Mind you this method almost fully relies on third party software. Eventually I wannabe try making it fully samba

1 Like

Apologies guys, but I’ve come across a printing issue with the ‘Save Only’ profile.

When setting a Terminal with Print Save Printer(PDFCREATOR printer (Save only profile) is assigned) when going to print a report on report page, it saves the pdf as what it’s supposed to do, but it doesn’t print anything.

The profile does forward the document to be printed to ReceiptPOS1(ticket printer) but nothing actually gets printed. I tried changing Printer Type to RAW printing, It prints a report that has like very little information. such as the one below

but anything that has more information then that, it just prints a blank page.

I tried different printer types, even the default ESC/POS type, but ESC/POS type wouldn’t print, and RAW printed blank, Windows print, didn’t print at all, document print brought an error.

I was therefore had to put terminal 1 report printing back to ticket printer one(receiptPOS1).

It prints and sends work period report fine when you end work period(because of the rule we created). But if I set terminal to PDF creator printer, it would create but not print(maybe not supported, or I may be missing something)

Is there any rule that I can make that would slightly make a change to when “Print” is clicked in reports?

I’d probably make a rule so that when print is clicked, it would make a print to both printers, one for ticket printer and the other for PDFcreator printer(the save only profile)

SendKeys and a Sleep function to the rescue…

function sleep(milliseconds)
{
   var currentTime = new Date().getTime();
   while (currentTime + milliseconds >= new Date().getTime()) {
     // do nothing
   }
   return milliseconds;
}

function printPDF(f)
{
	var tmout = 5;
	
	var objFSO = new ActiveXObject("Scripting.FileSystemObject");
	var objShell = new ActiveXObject("Shell.Application");
	var WshShell = new ActiveXObject("WScript.Shell");

	var filename = f;

	if(!objFSO.FileExists(filename))
	{
	 return "File does not exist: " + filename;
	}

	
	try
	{
	var PDFCreatorQueue = new ActiveXObject("PDFCreator.JobQueue");

	PDFCreatorQueue.Initialize();

	//Since we are using the "DefaultGuid" pdf is our output format
	var fullname = objFSO.GetFileName(filename);
	var name =  fullname.replace(objFSO.GetExtensionName(fullname),"pdf");
	var fullPath = objFSO.GetParentFolderName(filename) + "/" + name;

        // invoke associated program and call it's "print" verb
	objShell.ShellExecute(filename,"", "", "print", 2);

        // call our sleep function
        var sleeping = sleep(500);
	// send ENTER key
	WshShell.SendKeys('{ENTER}');

	if(!PDFCreatorQueue.WaitForJob(tmout))
	{   
		PDFCreatorQueue.ReleaseCom();
		return "The print job did not reach the queue within " + tmout + " seconds";
	}
	else
	{
		var job = PDFCreatorQueue.NextJob;
		job.SetProfileByGuid("DefaultGuid");						
		
		//Assuming you want to convert to a .tif-file you can do this by
		//simply changing the output format setting of your current profile
		//job.SetProfileSetting("OutputFormat", "Tif");
		job.SetProfileSetting("OutputFormat", "Pdf");
		
		//Get the guid of the used profile
		var guid = job.GetProfileSetting("Guid");
		
		job.ConvertTo(fullPath);
		
		if(!job.IsFinished || !job.IsSuccessful)
		{
			PDFCreatorQueue.ReleaseCom();
			//WScript.Echo("Could not convert the file: " + fullPath);
			return "Could not convert the file: " + fullPath;
		}
		else
		{
			PDFCreatorQueue.ReleaseCom();
			//WScript.Echo("Job finished successfully");
			return "Success";
		}
	}
	PDFCreatorQueue.ReleaseCom();
	}
	catch(e)
	{
		PDFCreatorQueue.ReleaseCom();   
		return "ERROR: " + e.message;
	}
}

Here is the Rule I use which is fired when I click a button…

This actually uses the Save Report Action, then uses JScript to convert. The reason I like the Save Report Action is that it allows us to specify the FileName, so we have full control over it. You could add one more Action to Send Email with attachment at the end of it all.

1 Like

Super thanks Dude will surely implement this Cheers had an issue with XPS on Iphones

1 Like

would you kindly demonstrate how you have achieved this

To be honest, this was a while a go, so I don’t really remember how to do it.

I haven’t implemented this in other set-ups I did, as this was a customer specific request…

I’ll have another go at filter report prints and let you know.

1 Like