# print preview code execution

**URL:** <https://forum.servoy.com/t/print-preview-code-execution/3891>\
**Category:** Classic Servoy\
**Created:** [March 17, 2005, 4:59pm UTC](https://forum.servoy.com/t/print-preview-code-execution/3891 "2005-03-17T16:59:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [March 17, 2005, 4:59pm UTC](https://forum.servoy.com/t/print-preview-code-execution/3891/1 "2005-03-17T16:59:55Z")

</div>

Hello,

I had a method that did this:

```auto
someCode
someform.controller.showPrintPreview();
somMoreCode

```

in RC2 the method seemed to “wait”, until the form showing the preview was closed on way or another. Now in RC3 the code runs directly to the end.

What is expected behaviour in this situation?

Thanks  
Patrick

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [August 16, 2005, 12:00pm UTC](https://forum.servoy.com/t/print-preview-code-execution/3891/2 "2005-08-16T12:00:24Z")

</div>

Can any of the servoyans respond to this?

Why the change?  
This new behavior is for me a royal pain in the butt. ![:?]( "Confused")

Servoy Developer  
Version R2 2.2.1rc-build 330

---

<div class="post-metadata">

**Author:** ![Jan\_Blok](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Jan\_Blok](https://forum.servoy.com/u/Jan_Blok)\
**Post date:** [August 16, 2005, 2:10pm UTC](https://forum.servoy.com/t/print-preview-code-execution/3891/3 "2005-08-16T14:10:09Z")

</div>

showPrintPreview has never waited… nothing is changed there

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [August 16, 2005, 2:38pm UTC](https://forum.servoy.com/t/print-preview-code-execution/3891/4 "2005-08-16T14:38:41Z")

</div>

> Jan Blok:  
> showPrintPreview has never waited… nothing is changed there

Indeed, it has always been this way, but I would like to see it changed! ![:)]( "Smile")

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [August 16, 2005, 6:52pm UTC](https://forum.servoy.com/t/print-preview-code-execution/3891/5 "2005-08-16T18:52:14Z")

</div>

I guess I never noticed it because I used it as last function.  
But now I need to execute code AFTER the print preview is closed and is conditional if it was printed or not.  
So I am having a hard time with this.

Any chance to make it optional to let it wait until the close button is pressed in Print Preview?

---

<div class="post-metadata">

**Author:** ![seanthomasdevlin](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/seanthomasdevlin/32/5_2.png) [@seanthomasdevlin](https://forum.servoy.com/u/seanthomasdevlin)\
**Post date:** [February 9, 2007, 5:35pm UTC](https://forum.servoy.com/t/print-preview-code-execution/3891/6 "2007-02-09T17:35:10Z")

</div>

Yeah this is troublesome.

how can one print to PDF from preview using the PDFOutput plugin?

How can we know if the user clicked on ‘print’ or ‘close’ from the preview?  
This code won’t work because end print job will return byte length 0 before the user even clicks print.

```auto
//	start the print job
plugins.pdf_output.startMetaPrintJob();

//	show the preview
controller.showPrintPreview(false, plugins.pdf_output.getPDFPrinter());

//	get the print job
var bytes = plugins.pdf_output.endMetaPrintJob();

```

---

<div class="post-metadata">

**Author:** ![fsciweb](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@fsciweb](https://forum.servoy.com/u/fsciweb)\
**Post date:** [November 20, 2007, 5:09pm UTC](https://forum.servoy.com/t/print-preview-code-execution/3891/7 "2007-11-20T17:09:18Z")

</div>

Any further word on this?

What trigger can be used to run a method after a print preview is done, ie closed.

We have a form that uses a getImage from a custom bean. We have to show this form for the bean to update.

It is a special form just for printing. We have to show the form, rather than just loadRecords, as the getImage function returns just a black graphic if the bean doesn’t show in servoy when the getImage method is triggered.

Then, a print preview close returns to the badly formatted (print sliding use extensively) print form.

So, is there any trigger for when a print preview is closed? or method to capture / wait real-time within a method?

NCM  
FSCI

---

<div class="post-metadata">

**Author:** ![Harry\_Catharell](https://avatars.discourse-cdn.com/v4/letter/h/e19adc/32.png) [@Harry\_Catharell](https://forum.servoy.com/u/Harry_Catharell)\
**Post date:** [November 26, 2007, 5:43pm UTC](https://forum.servoy.com/t/print-preview-code-execution/3891/8 "2007-11-26T17:43:45Z")

</div>

Hi,

There is an: ```  
application.isLastPrintPreviewPrinted()

```function

Have you considered just setting a global variable when you initiate the print preview and then have a condition in the onShow of the form that you end up at that then checks for the global variable and does something based on that - sort of as follows:

'print_preview' method

```

globals.preview\_flag = 1;  
forms.print\_form.controller.showPrintPreview();

```auto

'on_show' method [on badly formatted form]

```

// other on\_show processes followed by  
if (globals.preview\_flag == 1)  
{  
// reset the flag  
globals.preview\_flag = 0  
//do something after the print preview !!!  
}

```auto

Hope this helps

Cheers
Harry
```
