Omnis Studio reports - Print to PDF in Windows (silent mode)

Rob Mostyn mostyn at platformis.net
Tue Sep 3 11:33:29 UTC 2024


Are you saying it works reliably provided this window is open?
If the window is disconcerting / you want to hide it, you could open the window 1 pixel by 1 pixel in size.
If something goes wrong with the print job the timer inside the window could enlarge and advise what needs to be done.

Or am I missing something here?

We use $pdfcomplete in remote forms and it works well for us.

Cheers,
Rob

> On 3 Sep 2024, at 11:12, Paul Mulroney <pmulroney at logicaldevelopments.com.au> wrote:
> 
> Hi Phil,
> 
> On the 28th I said that we're using the Omnis PDF device, and because it is asynchronous, it's a bit lumpy. I asked if there was a better way, and we had a conversation about how to make it better.  I thought I'd found a way to eliminate showing a window while it's printing, but it turns out that I was wrong.  I just wanted to let the people on the list know that rather than have them try to do what I had said, and have it fail for them and have them scratch their heads.
> 
> We're using Studio 10.2, but the same issues applies in Studio 11.1.
> 
> The Omnis PDF device is asynchronus, so if you print in the main thread you need to have either a callback or a way to pause execution of your code while you're waiting for the file to be generated.  
> 
> Omnis supplies a task method $pdfcomplete(), which tells us when the job is done, BUT you need to be able to process this method call by somehow interrupting the current method execution to allow it.  
> 
> Regards
> Paul.
> 
> 
>> On 3 Sep 2024, at 5:02 pm, Phil (OmnisList) <phil at pgpotter.co.uk> wrote:
>> 
>> Hi Paul,
>> 
>> Sounds like you have a solution that works, yet you say it does not work?
>> 
>> Is that correct?
>> 
>> How does it not work, assuming the process completes properly and
>> creates a PDF?
>> 
>> What version of Studio are you using for this?
>> Curious as the omnis solution is different for different versions:
>> 10: uses Python
>> 11: uses Node.js
>> 
>> regards
>> Phil Potter
>> Based in Chester in the UK.
>> 
>> On 03/09/2024 09:08, Paul Mulroney wrote:
>>> Hi $all
>>> 
>>> I've just finished trying this approach - it doesn't work. You need to have something like a window with an enter data command in it, in order for the method stack to be interrupted so it can jump to pdfcomplete.  In a nutshell you'll need these classes/methods:
>>> 
>>> Task method $pdfcomplete sets an instance var to say that it's done
>>> Task method $ispdfcomplete returns the instance var set by $pdfcomplete - this is basically a callback method
>>> 
>>> Create a  "wait for report" window
>>> - window has a timer object that sets instance var
>>> - start the timer when window is opened
>>> - enter data until complete
>>> - close window
>>> 
>>> Timer object
>>> - calls $ispdfcomplete and if that says we're done then set the instance var in the window to flag that we're complete
>>> 
>>> Put it all together:
>>> - set printer to Omnis PDF
>>> - print report
>>> - open our wait for report window.  Execution pauses here until the file is generated
>>> - Carry on processing - at this point we have a guaranteed PDF file.
>>> 
>>> You might want to put some timeouts and error checking eg if you're taking more than a few minutes then you've probably missed something or there was an error and it will never be generated.
>>> 
>>> Regards
>>> Paul.
>>> 
>>> 
>>> 
>>>> On 31 Aug 2024, at 4:37 pm, Paul Mulroney<pmulroney at logicaldevelopments.com.au>  wrote:
>>>> 
>>>> Hi Joe
>>>> 
>>>> We've tried this approach in the past, and have found that it isn't always successful.  If the report hasn't finished printing, but it's partly spooled the output, we can sometimes grab the PDF before it's complete.  We added tests to see the filesize and wait until the filesize finishes changing
>>>> 
>>>> I think that there's a way to fuse the sleep() function and the $pdfcomplete() method callback to achieve what we need.
>>>> 
>>>> So something like this:
>>>> 
>>>> Have the $pdfcomplete() method set a task var somewhere to say that it's done
>>>> 
>>>> Have a method waitForSleep() that has this: (more why in a minute)
>>>> 
>>>>> do sleep(250)
>>>> Then the main waitForPrintJob:
>>>> 
>>>> Repeat
>>>>  do method waitForSleep()
>>>> until my task var printingdone is set or we grow tired waiting ...
>>>> 
>>>> The reason you put sleep in another function is due to the way Omnis callbacks work - the callback is added to the top of the internal stack, but only gets executed after the current method returns, i.e. after the method doing sleep returns, at which point if $pdfcomplete has been pushed onto the stack, it will be executing and set done to kTrue, which then breaks out of the repeat loop.
>>>> 
>>>> Hope this is helpful.
>>>> 
>>>> Regards
>>>> Paul.
>>>> 
>>>> 
>>>> 
>>>>> On 30 Aug 2024, at 11:30 pm, Joe Maus<jmaus at theccgllc.com>  wrote:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> Don't know if this is any better, but it seems to have fewer moving parts and does not need Enter Data.  We've successfully used this short repeat loop to detect when the PDF file is ready for a number of years.  Perhaps it might help get you to a better solution.
>>>>> 
>>>>> Calculate fileExists as kFalse
>>>>> If isclear(pPathAndFileName)=kFalse
>>>>> Calculate counterTest as 0
>>>>> Repeat
>>>>> Do FileOps.$doesfileexist(pPathAndFileName) Returns fileExists
>>>>> Calculate sleepSuccess as sleep(250). ##milliseconds
>>>>> Calculate counterTest as counterTest+1
>>>>> Until (fileExists=kTrue)|(counterTest=20)
>>>>> # Handle when counterTest=20
>>>>> End If
>>>>> 
>>>>> Quit method fileExists
>>>>> 
>>>>> Kind regards,
>>>>> 
>>>>> Joe Maus
>>>>> The Convergent Consulting Group, LLC
>>>>> jmaus at theccgllc.com
>>>>> 303-349-6696
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>>> On Aug 28, 2024, at 3:39 AM, Paul Mulroney<pmulroney at logicaldevelopments.com.au>  wrote:
>>>>>> 
>>>>>> Hi $all
>>>>>> 
>>>>>> I know this is an old post, but it's just reared it's ugly head for us again.  Apart from using BrainyData's PDFdevice, is there a way to synchronously print PDFs on Windows?
>>>>>> 
>>>>>> We have something like this:
>>>>>> - There's a method in the Startup_Task called "$pdfcomplete".  This is called when the PDF has finished being generated.  It has two parameters: report file path and success flag.  We override this method and use this to store an instance var in the Startup_Task to indicate that we're done creating our PDF.
>>>>>> - We use the normal setup to send to PDF and print report eg set print device to be Omnis PDF, set the report path etc, set report name, print report.
>>>>>> - We then open a window that has a timer object in it.  We have an enter data until complete command, and the timer fires every second to test the instance var in the Startup_task to see if it's done.
>>>>>> - When it's completed, the enter data terminates, the window closes, and execution of the main stack resumes.
>>>>>> 
>>>>>> Obviously we have some checks eg if it takes too long to generate, or the PDF fails to generate etc, so we don't hang forever.  But it's still a bit lumpy.
>>>>>> 
>>>>>> Has anyone come up with a better method?
>>>>>> 
>>>>>> Regards
>>>>>> Paul.
>>>>>> 
>>>>>>> On 29 Apr 2020, at 1:19 am, Ben Weinberg<ben at pca.com>  wrote:
>>>>>>> 
>>>>>>> Phil:
>>>>>>> 
>>>>>>> I used the following code to check if the file is present after printing to pdf:
>>>>>>> 
>>>>>>> 
>>>>>>>   Repeat
>>>>>>>      Do FileOps.$doesfileexist(cFilePath) Returns iReturnFlag
>>>>>>>      Calculate %i as sleep(100)
>>>>>>>    Until iReturnFlag=kTrue
>>>>>>> 
>>>>>>> Ben Weinberg
>>>>>>> 
>>>>>>>> On Apr 28, 2020, at 2:23 AM, Phil (OmnisList) via omnisdev-en<omnisdev-en at lists.omnis-dev.com>  wrote:
>>>>>>>> 
>>>>>>>> Just to comment on this...
>>>>>>>> 
>>>>>>>> The main problem we had with the internal PDF print was that it was printed asynchronously.
>>>>>>>> 
>>>>>>>> As in, when Omnis methods started running again, the PDF is still getting produced in the background, and we had no idea when it was completed, we had to check the filesize was not increasing...
>>>>>>>> 
>>>>>>>> Brainy Datas PDFdevice is fully synchronous, so when control returns to the Omnis methods, the PDF is fully there.
>>>>>>>> 
>>>>>>>> This was an issue for us, as generally the reason we are creating a PDF, is because we are just about to email the report to someone, and we cannot attach the PDF to an email, until it has been completed.
>>>>>>>> 
>>>>>>>> regards
>>>>>>>> Phil Potter
>>>>>>>> Based in Chester in the UK.
>>>>>>>> 
>>>>>>>> On 28/04/2020 10:04, Rocco Ventura [Kunvi] wrote:
>>>>>>>>> Hi Mayada,
>>>>>>>>> 
>>>>>>>>> I use these commands to print on a PDF-file, using only... Omnis Studio 😉
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> ________________________________
>>>>>>>>> 
>>>>>>>>> If pForceToPDF
>>>>>>>>> 	# Before setting the report name...
>>>>>>>>> 	Calculate ReportDevicePREV as sys(24)		## I save the previous report-device name
>>>>>>>>> 	Do $cdevice.$assign($devices.PDF)
>>>>>>>>> End if
>>>>>>>>> 
>>>>>>>>> If sys(24)='PDF'
>>>>>>>>> 	Calculate DownDIR as "My local path on the Hard-disk"
>>>>>>>>> 	Calculate FilePDF_OUT as con(DownDIR,$clib().$name,"_", pReportName,'_',jst(#D,'D:y-M-D H-N-S'),'.pdf')
>>>>>>>>> 	Do FileOps.$doesfileexist(FilePDF_OUT) Returns Retc
>>>>>>>>> 	If Retc
>>>>>>>>> 		# DELETE the previous PDF-file
>>>>>>>>> 		Do FileOps.$deletefile(FilePDF_OUT)
>>>>>>>>> 		Do sleep(750)		## much better to wait, usually the CPU is faster than the Hard-disk
>>>>>>>>> 	End If
>>>>>>>>> 	Do $root.$prefs.$reportfile.$assign(FilePDF_OUT)
>>>>>>>>> End If
>>>>>>>>> 
>>>>>>>>> # prepare your printing report
>>>>>>>>> 
>>>>>>>>> Set report name [pReportName]
>>>>>>>>> # and use your commands to print the trigger the report...
>>>>>>>>> 
>>>>>>>>> # After the printing if over...
>>>>>>>>> If pForceToPDF
>>>>>>>>> 	# clean the previous PDF-file...
>>>>>>>>> 	Do $root.$prefs.$reportfile.$assign('')
>>>>>>>>> 
>>>>>>>>> 	# re-set the previous device-name
>>>>>>>>> 	Do $cdevice.$assign($devices.[ReportDevicePREV])
>>>>>>>>> 
>>>>>>>>> 	# on FilePDF_OUT local-var you have the complete path of the PDF
>>>>>>>>> End if
>>>>>>>>> 
>>>>>>>>> Quit method 1
>>>>>>>>> 
>>>>>>>>> Bye
>>>>>>>>> 
>>>>>>>>> Rocco
>>>>>>>>> 
>>>>>>>>> ______________________________________
>>>>>>>>> Distinti saluti. Best regards.
>>>>>>>>> 
>>>>>>>>> Rocco Dr. Ventura
>>>>>>>>> WMS Analist and Software Developer
>>>>>>>>> 
>>>>>>>>> KUNVI srl - Experiences Holding -www.kunvi.it
>>>>>>>>> Email:r.ventura at kunvi.it  - Mobile: +39 348 5186051
>>>>>>>>> 
>>>>>>>>> -----Messaggio originale-----
>>>>>>>>> Da: omnisdev-en<omnisdev-en-bounces at lists.omnis-dev.com>  Per conto di malkishtini
>>>>>>>>> Inviato: martedì 28 aprile 2020 01:37
>>>>>>>>> A: 'Doug Easterbrook'<doug at artsman.com>
>>>>>>>>> Cc: 'OmnisDev List - English'<omnisdev-en at lists.omnis-dev.com>
>>>>>>>>> Oggetto: RE: Omnis Studio reports - Print to PDF in Windows (silent mode)
>>>>>>>>> 
>>>>>>>>> Hi Doug,
>>>>>>>>> I thought that will be the answer, but just wanted someone to confirm that it is the right path to go.
>>>>>>>>> 
>>>>>>>>> Thank you so much,
>>>>>>>>> Mayada
>>>>>>>>> 
>>>>>>>>> -----Original Message-----
>>>>>>>>> From: omnisdev-en [mailto:omnisdev-en-bounces at lists.omnis-dev.com] On Behalf Of Doug Easterbrook
>>>>>>>>> Sent: Monday, April 27, 2020 7:15 PM
>>>>>>>>> To: OmnisDev List - English
>>>>>>>>> Subject: Re: Omnis Studio reports - Print to PDF in Windows (silent mode)
>>>>>>>>> 
>>>>>>>>> hi mayada.
>>>>>>>>> 
>>>>>>>>> I just did that this weekend …   using Brainy data’s  print to PDF.
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> Doug Easterbrook
>>>>>>>>> Arts Management Systems Ltd.
>>>>>>>>> mailto:doug at artsman.com
>>>>>>>>> http://www.artsman.com
>>>>>>>>> Phone (403) 650-1978
>>>>>>>>> 
>>>>>>>>>> On April 27, 2020, at 3:56 PM, malkishtini<malkishtini at gmail.com>  wrote:
>>>>>>>>>> 
>>>>>>>>>> Hi $all,
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> Any advice about the best way to print Omnis studio reports as PDF files saved directly on disk (without prompting the user to make any selection or to enter the file name)? I.e. automate the printing process.
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> 
>>>>>>>>>> Thank you,
>>>>>>>>>> 
>>>>>>>>>> Mayada
>>> 
>>> An invisible man married an invisible woman.  The kids were nothing to look at either.
>> _____________________________________________________________
>> Manage your list subscriptions at https://lists.omnis-dev.com
>> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
> 
> 
> 
> 
>  <https://www.logicaldevelopments.com.au/> 	Paul W Mulroney
> Logical Developments
> Customised Software Solutions
> Ph: 08 9458 3889
> 	We Don't Do Simple Pty Ltd
> trading as
> Logical Developments
> ACN 161 009 374
> 	  <https://www.facebook.com/logicaldevelopmentswa/>   <https://twitter.com/WeDontDoSimple>   <https://www.linkedin.com/company/logicaldevelopments/>   <https://www.youtube.com/channel/UCPldVVgWR05WX3cVrR5WUQw>
> _____________________________________________________________
> Manage your list subscriptions at https://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com



More information about the omnisdev-en mailing list