Welcome Guest Search | Active Topics | Sign In | Register

Execute pieces of code only when converting to PDF Options
Greg
Posted: Friday, August 15, 2014 10:11:24 AM
Rank: Member
Groups: Member

Joined: 11/13/2013
Posts: 11
Hello,

Here is the context: I have a parent page containing some UserControl in which there is Telerik grids. These grids contain text box when the user is on the web page. When they click the PDF button, I would like all these text boxes to be simple label text.

My thought would be to have the Telerik grid in edit mode when the users are going through the web page and in simple rendering mode when they click the PDF button. In this scenario, I would turn on and off the edit mode of the grid according to the page being converted as PDF or not.
So the question is:
is there any way to have a flag in the code like
if(converting to PDF)
Telerik grid in regular rending mode
else Telerik grid in edit mode

A work around would be to create labels for every text box and play with HtmlToPdf.Options.InvisibleElementIds. Just the first option seems more comfortable and direct.

Thank you
Grégory
eo_support
Posted: Friday, August 15, 2014 10:51:42 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

Yes. See here for more details:

http://www.essentialobjects.com/doc/4/htmltopdf/eo_js.aspx

The first section "Checking Whether Inside HTML to PDF Converter" describes how to do this.

Thanks!
Greg
Posted: Friday, August 15, 2014 11:24:47 AM
Rank: Member
Groups: Member

Joined: 11/13/2013
Posts: 11
thank you for your answer.

I would like to have the same option but for the code behind in C#. All I saw was only in Javascript.

Gregory
eo_support
Posted: Saturday, August 16, 2014 9:46:43 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

No. There is no such options on the server side. What you can do is to put such code in your "triggering action". For example, if you use ASPXToPDF and has an "Export To PDF" button, then you would just set your Grid to regular rendering mode inside that button's click handler. If you use ConvertUrl, you can add a query string argument and then check that argument in your Page_Load to check the argument and perform similar logic.

Thanks
Greg
Posted: Monday, August 18, 2014 10:51:50 AM
Rank: Member
Groups: Member

Joined: 11/13/2013
Posts: 11
Thank you for the idea. It is probably the good way to go. Nevertheless I am having difficulties to realize it.

My page is structured with a masterpage and a user control which includes the telerik grid and a user control with the button to click to start ASPXToPDF.
In the masterPage, I have a public property bool OnExportingPDF
In the UserControl with button for PDF, I have in the method onButtonClick ( ... master.OnExportingPDF = true; ... )
In the ASPX page I have a
BaseMaster master = this.Master as BaseMaster;
if(master.OnExportingPDF ) label.text = "true";
else label.text = "false"

When loading the page, the value is false which is normal.
When clicking on the pdf button, the Pdf export has false instead of true.

I am probably missing a step or having the code in a wrong execution order. Would you have an explanation for this one?

Thank you very much

eo_support
Posted: Monday, August 18, 2014 11:05:15 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Hi,

Try to get everything working property on the screen first. For example, if in your "Export PDF" button you call RenderAsPDF, then comment that line out (leaving other code intact). If the result is correct on the screen when you do so, then you can uncomment RenderAsPDF and the result PDF file should be correct. If the result is not correct on the screen, then you need to fix that first. You can try to think ASPXToPDF as an "output redirector". So first you would always try to get the correct result on screen. Afterwards you simply put RenderAsPDF in and the exact same HTML output that was sent to your browser will now be sent to the HTML to PDF converter. As such as long as the HTML output is correct, the PDF result should be correct, and if the HTML output is incorrect, you will be able to see it on screen if you comment RenderAsPDF out.

Thanks!
Greg
Posted: Monday, August 18, 2014 2:25:21 PM
Rank: Member
Groups: Member

Joined: 11/13/2013
Posts: 11
Hi,

Thank you for the last answer. Commenting RenderAsPDF has been a nice trick to debug my issue.

Thanks!
eo_support
Posted: Monday, August 18, 2014 10:29:37 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Glad to hear that you got it working! Please feel free to let us know if there is anything else.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.