Welcome Guest Search | Active Topics | Sign In | Register

ASPXtoPdf How to show result message Options
KevinExpress
Posted: Monday, October 6, 2014 9:11:09 PM
Rank: Newbie
Groups: Member

Joined: 9/24/2014
Posts: 5
Hello, I'm rendering a PDF on an aspx page, and using the ASPXToPDF_AfterRender event to get the resulting Pdf, and send it to a third party web service. This function returns a success/error message to me and I need to be able to show my client the result of the Pdf transfer.

I understand that the ASPXToPDF_AfterRender event occurs after the page has been fully rendered so I don't have access to insert any javascript or modify any controls at that point, there must be some sort of workaround I can use?
eo_support
Posted: Tuesday, October 7, 2014 9:40:51 AM
Rank: Administration
Groups: Administration

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

You are correct that there is nothing you can do at that point because the page has already been rendered, so anything you want to do has to occur before that point. For example, you can add the following JavaScript code in your page:

Code: JavaScript
if (typeof(eopdf) == "undefined")
{
    var div = document.getElementById("msg_div");
    div.innerHTML = "conversion completed!";
}


The above code:

1. It will only run when the conversion has completed successfully because if the conversion fails, an exception will throw and you will be redirected to ASP.NET's default or your own custom error page;

2. It will only run when the page is viewed in a browser because it checks whether variable "eopdf" is defined. This variable is only defined when the page runs inside our converter. This means the "conversion completed" message will not appear in the PDF file.

Hope this helps. Please feel free to let us know if you still have any more questions.

Thanks!



KevinExpress
Posted: Tuesday, October 7, 2014 4:49:56 PM
Rank: Newbie
Groups: Member

Joined: 9/24/2014
Posts: 5
Ok I understand what you're describing, I don't think that will work for me though.

Maybe I can describe our use case and you can advise the best process to use with your component, here is what has to happen:
1) Show the user a 'preview' page of what the PDF will look like
2) The user clicks 'send' to initiate the PDF conversion
3) I need to get the PDF binary (byte array) in memory preferably
4) I send this binary to a third party web service, they give me a specific response code (not just success/fail)
5) I use this response code to generate a user-friendly message
6) I hide the 'preview' content and show the user response message
eo_support
Posted: Tuesday, October 7, 2014 5:10:59 PM
Rank: Administration
Groups: Administration

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

In this case your best approach would be using an iframe to load/convert the page to PDF, and then use a "hosting" page to poll the status with AJAX. The iframe does not have to be visible. The basic step will be like this:

1. You must have two different pages. For example, one is "SendReport.aspx" and one is "Report.aspx". You can, of course, merge them into a single aspx and use query string to distinguish the two. For example, you can have "Report.aspx" and "Report.aspx?pdf=1";
2. Generate a unique "task id" for each SendReport.aspx request. That page contains an iframe that can be used to pull "Report.aspx";
3. When user click "Send" button, the code loads a request in the iframe to trigger the conversion, and pass the unique task id in step 2 back to the server. This way your server side code will know which task is being converted;
4. At the same time, the code starts an AJAX timer to poll the server for conversion status. It will also pass the unique Id back to the server so that your server side code knows which task id's status it needs;

As you can see, the key is to separate them into two different documents and then coordinates between them.

Please let us know if you still have any questions.

Thanks!
KevinExpress
Posted: Tuesday, October 7, 2014 5:29:52 PM
Rank: Newbie
Groups: Member

Joined: 9/24/2014
Posts: 5
Ok I understand the basic concept with the iFrame, but I'm not sure how/where I do the binary conversion and return message

1. Which method/event do I generate the PDF binary contents
2. Which method/event would I grab the PDF binary and send to the web service?
3. Which method/event do I store the web service result?
4. How do I query that result message from the container page?
eo_support
Posted: Tuesday, October 7, 2014 5:45:33 PM
Rank: Administration
Groups: Administration

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

For #1 and #2 please see here for more information:

http://www.essentialobjects.com/doc/4/web/aspxtopdf.aspx#save

Look for "Save Conversion Result into a File", it contains sample code about how to save the result into a file name. You will need to change that part to the following:

//Grab the conversion result into a byte array
Code: C#
MemoryStream ms = new MemoryStream();
result.PdfDocument.Save(ms);
byte[] pdfFileData = ms.ToArray();


You will need to work out #3 and #4 yourself. We consider those general Web programming questions, so we do not provide any technical assistance on those. You can search online and you should be able to find plenty of information on those.

Thanks!
KevinExpress
Posted: Tuesday, October 7, 2014 7:15:43 PM
Rank: Newbie
Groups: Member

Joined: 9/24/2014
Posts: 5
I've already read that and am already doing that, that's why I'm posting the question here. The AfterRender event doesn't support anything I can use to actually do something with the PDF after generation. Saving it to a physical file is not best practice in a web app, then there's cleanup to deal with. Surely this is the most commonly requested problem is to take the resulting PDF and do something else with it. So my only option is:
1. Save the PDF to a file
2. Detect when the conversion is complete and trigger another postback
3. Read the file/binary and process through the service
4. Delete the file
5. Show user confirmation message

That's 3 postbacks to do something with the binary I already have in the render event, seems odd.
eo_support
Posted: Tuesday, October 7, 2014 7:45:41 PM
Rank: Administration
Groups: Administration

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

Why do you need to save it into a file in step #1 and then read it back in step #3? Why can't you process it through the service immediately after the conversion inside AfterRender? All you really need is a way to get a result code back to the client asynchronously. Your original questions (#3 and #4) seems to be more on the right direction. So we think that's what you should focus on. If you do not know how to do those, you may want to ask someone around you to see if they can explain it to you. We are happy to provide you basic pointers as we have done so in our previous replies, but we are not in a position to review or endorse your specific implementation schemes beyond our programming interface, which we have already clearly explained to you. So please consider this issue closed.

Thanks!
KevinExpress
Posted: Tuesday, October 7, 2014 8:02:25 PM
Rank: Newbie
Groups: Member

Joined: 9/24/2014
Posts: 5
I was coding 10 years before your company even existed lol I don't need anyone to explain an asynchronous call, you haven't addressed the basic question I asked in the first place, your words "anything you want to do has to occur before that point" explain to me how I return the web service code before the web service has been executed.

"Why can't you process it through the service immediately after the conversion inside AfterRender? All you really need is a way to get a result code back to the client asynchronously" - Thats EXACTLY what I was doing, if I have no access to session/request/response/cookies/controls how do I take that code from the AfterRender event and return it anywhere?

If the answer is it's impossible due to the way your components programming model functions then just state so.
eo_support
Posted: Tuesday, October 7, 2014 8:55:31 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
We have explicitly told you that it is possible and explained the process to you as clearly as possible --- you need to have two separate requests. The first request to do the work the the second request to fetch the status. In another word, the real question you have is having one request triggering some work and another request fetching result. This is a rather common and generic web programming scenario and it does not have to rely on session/request/response/cookies/control. We have even pointed out to you that you can consider using a unique task id to match up the requests pairs in our earlier reply. The reason that we won't go further on this is if we were to provide step by step programming assistance on such questions, it would only encourage our users to run such programming questions through us in the future and give our users false illusion that we will help them no matter where the problem is. The reality is not only those questions are beyond the scope of our responsibilities, but also it is impossible for us to fill such technical gaps for our users for free. As a result, we do not answer such questions.

We value all our customers but we believe a good customer relationship goes both ways and can only be achieved if we do our part and you do your part. In this case we believe we have explained everything about our product and pointed you to the right direction for the rest, so we believe we have already gone extra miles for you ---- if that is still not acceptable to you, then it might be better for you to try your luck with a different vendor as basically you are asking us to do things we do not do here. Of course, if you decide to take this as our product can not do what you wanted to do then it is completely your choice too. We will not comment further on this issue.


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.