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

Phil (OmnisList) phil at pgpotter.co.uk
Sat Aug 31 15:53:27 UTC 2024


Hi Paul,

Particular reason to avoid BrainyData solution?

Which works very well...

and does not have this issue, which we gave up trying to resolve also.

regards
Phil Potter
Based in Chester in the UK.

On 31/08/2024 09:37, Paul Mulroney 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
>
> I told my wife she was drawing her eyebrows too high. She looked surprised.


More information about the omnisdev-en mailing list