How to Print a form using K2 Control Button?


Userlevel 3
Badge +16

Hi,

 

I'm super new to K2 and Smartforms, i've been following the examples.pdf to get an idea of how Smartforms work etc.

 

My first task with K2 Designer is to create an online form which students will fill in when handing in assignments. It should have a print button which should print two copies, one white copy to hand-in with an assignment and a second copy (yellow) which the students keeps as a receipt.

 

I've done my first Smartform via K2 Designer, setup the views and added them to the form. I've added the necessary wording and logos, but I haven't got a clue how to add a Print option to the form.

 

The closest I can think off, is using a Button Control, but i'm lost after that. Do i need to do something with Workflows to do an action to print when a student pressing the button upon completion?

 

Any ideas how to print two copies? Or is it possible to have two views, when the student clicks Print after completing the form, it somehow prints their sheet, followed by a copy in yellow? Is any of this possible?

 

Thanks in advance for any pointers.,

Sharpy


18 replies

Badge +6

Hi,


 


As far as I am aware there is no direct printing functionality for printing a form directly from a button or rule. I do know that you could achieve this from either printing from the web browser, or you could use the Save to PDF control, which will render an entire form and all of its content to a PDF document, you could then print from the PDF file - which I personally think will have a better finish than printing from the browser. 


 


Here is some more information on the Save to PDF control:


help.k2.com/files/6410


 


Regards,


 

Userlevel 3
Badge +16

Hi,

 

I had a look at the PDF method, but i guess this generates lots of space on the server? If its used by students, this will fill up quickly.

 

So there is no way of having a Button link to a Print event to print the form, even it it just brings up the microsoft windows Print box?

 

 

Badge +6

Hi,


 


Unfortunately not with using standard out of the box K2 components. It should be possible implementing such functionality using custom code. Alternatively, you could log an official K2 Feature Request - which may be implemented in a future release.


 


Regards

Userlevel 3
Badge +16

Do you have any links to this custom code you speak off? Also, how do you integrate custom code into smartforms?

Badge +5

Hi, Sharpharp1


 


Can you please look at the following links below.


 



  1. Help file content: Save as PDF Control
  2. Video demo: http://help.k2.com/videos/6502
  3. Creating a Custom Control

 


Regards


 


Julia

Userlevel 3
Badge +16

Hi,

 

Thanks for the links, but i've already looked at the save to pdf control info, which isn't what i'm after.

The video link also just shows how to use pdfs for offline use.

 

All i want is a print button of the form on the screen, does anyone know of a custom control already written to do this?

 

Why is is so hard to get an answer on this subject? Is it not possible to print without any PDF involvement whatsoever.

Honestly, I wouldn't have a clue on writing a custom control, I was kinda hoping printing controls would be part of the system to start with.

Badge +5

Hi, Sharpharp1


 


The only way i know that you can achieve this is through a PDF control, I'm not sure if you can create a button to print copies, i also checked under rules, and didn't find any rule action to print a page.


 


 


Regards


 


Julia

Userlevel 3
Badge +16

Hi Julia,

 

Appreciate your quick replies.

 

Say i go the create PDF road, can I do this?

 

I have added a button to the Form and called it SAVE WORK and put the Save PDF Control on as well.

When the User fills in the details and clicked on the SAVE WORK button, the PDF is created, but can i set a rule to immediately open that PDF full screen as soon as it is created?

 

Is there also a way of deleting the PDF from the LIST and K2 Server so that storage space is not used up by these PDFs. As far as i'm concerned, once the user has opened and printed the PDF, it should not use up any more space on the K2 server.

Badge +5

Hi, Sharpharp1


 



  •  Below from the link i sent you Save as PDF Control under Considerations they explain more about the page size.

 



  • Save as PDF : This control allows a Form to be converted into a PDF document. Once the PDF is generated it is saved as a SmartObject that can be reused either in another Form or in a workflow.
     So i'm not sure about deleting the pdf after printing the document.

Regards


 


Julia

Userlevel 4
Badge +13

Hi Sharpharp1


 


If you use the save to pdf control I am sure that it would achieve what you would like the outcome to be.


What the Pdf control does is, it takes a snapshot of the current view or form - So if you have lets say a view that the student has to fill in his name and surname and click save when he/she is done filling in the view, once the save button is clicked the save to pdf control will then execute with the default save to smartobject rule. The save to smartobject rule saves the record to SQL into a smartobject and the save to pdf takes a snapshot of the view with all the filled in content. you can then open the pdf and print it if you want as you will still have the pdf on record and the input of the user in a smartobject as input, so basically the view and its content will then be saved twice - first in a smartobject that only saves it as a record with all the filled in content and secondly as a pdf wich would look exactly like the view look when the student clicked the save button.


 


I made a quick test project, These were my steps:


1.open K2 designer


2.create a smartobject and add the field the student has to fill in


3.generate a item view from the smartobject


4.in your breadcrumb bar on the left hand side navigate to system>controls>save as pdf>generate a list view from the PDF File


5.now go open the item view in edit mode and drag a Save to PDF control into the view


6. edit the save buttons rule to look like this


 


    When Save Button is clicked


    then complete the following one after another


    then execute the Save method (Configure)


    then execute Save As PDF control's Save PDF method (Configure)


    then open PDF File List View - (When Save Button Is Clicked) as a subview (Configure)


 


Configure the above ( then execute the Save method (Configure)) rule as follows and leave the other two configure options to default:


16214iCA25F98189A11ECF.png


7.Now save the view and run it


The view will popup, after the view is filled in and the save button is clicked the subview will popup with the pdf contaned in it, click on the pdf to open it and to be able to print it


 

Userlevel 3
Badge +16

Thanks Raymond for taking the time to explain it in laymans terms, I have had a quick go.

 

Just wanted to ask how you only display one PDF in the List View. In my List view there are several PDFs in there from previous attempts where i clicked Save. How can i ensure that only the current PDF I just generated by filling the form in is displayed in the list view?

 

Also, is there any settings on the server to clear out the PDFs as soon after it's been printed or displayed? Otherwise our server will become full rather quickly.

 

It mentions this in the PDF Control documentation:

12. When using the default Out of the Box PDFFile SmartObject to store the PDF file, it is important to clean up unused PDF

files on a regular basis to ensure that performance issues are not encountered when having to load PDF files. PDF files that

are only required for the duration of the process can be subsequently removed for example

 

How do I go about doing this? It says that you should do this, but not how.

 

 

Userlevel 4
Badge +13

Hi


 


When all the items are deleted this time and everytime when the save button is clicked, only one pdf item would be present thereafter you can then ensure that you delete the pdf before colsing the subview.


 


There are multiple ways of deleting the records manually one by one but i am unaware of any way to delete all or even multiple records from a list view - this is not possible as far as i know.


 


I would suggest that you use the delete button supplied in the list view to delete the records when finished with them, you can use a smartobject method to do the same thing or even a advanced condition

Userlevel 3
Badge +16

Hi Raymond,

 

I have deleted the records using the Delete Button, and entered a new record (record 1). It displays in the List View. I then entered another record (record 2), but it also displays in the List view. So now I have 2 records, I only want to display the current one...

 

In terms of deleting records, is the manual way the only way to do this?

I will be having potentially 1000+ users using this daily, I can't realistically delete the records manually each day.

 

Any ideas if its possible to get a workflow to run a delete method on the List each every hour, pull out the IDs and delete all and reset ID back to Zero?

Userlevel 4
Badge +13

Hi Sharpharp1


 


I have created something that would definitly be of use to you in regards to always having only the one pdf record in the list view that was created.


 


After you have filled in the form and clicked submit/save then the pdf will be created to the list view which pop's up as a subview.


 


You can set the pdf to be deleted once the user clicks on the link to open it, so it would open the pdf and remove it from the list and the smartobject at the same time. I have attached my kspx project for you to have a look at, please have a look at it and revert back to me.


 


In the package note that when the form is filled in and submitted a subview popup is displayed containing the pdf's. when you click on the pdf to view it the pdf is deleted from the pdf smartobject and the list view while the pdf is opened from where you can then save the pdf.


 


Kind Regards


Raymond

Badge +7

Hey all,

 

Thought I'd add this to the thread.  I was able to send a call to the print function via an Expression.  I threw down a hyperlink control and added an expression to it to call javascript for printing.  If you wanted a link for users to click on, they can use this...I haven't been able to add it to a button or image click.

 

16063iF2BB1A43211F71CF.png

Badge +7

Do we have any feature or rule to download automatically withought calling subview list ? I need to generate pdf and download automatic .

Badge +4

Hi,

 

Option 1) As one of the member mentioned that you can do JavaScript to populate Windows Standard Print option. I have implementated this in oun eof our solution.

 

Option 2) You can use SAVE As PDF option. I have also implementated this in our one of the form, but here is the trick.. I was also worried about to fill the space on the server, so I tried to retive file and then delete it from the SmartObject as you already have file in your file attachment. By doing this you will not be worried about running out of memory issue.

 

 

 

Badge +7
Hi Vishesh,

You r right I had implemented by that way only . you also can do that.

Regards,

Arvind kumar

Reply