Project

General

Profile

Download of PDF resource of button click

Added by Markus Raabe almost 14 years ago

Hi,

I want to call a slot on clicking a button. A PDF is then generated. Now I would like the to get a Download/Open Dialog for the PDF on the client side, without redirecting to the PDF resource, because I don't want to lose the current view.

I could show an anchor to this PDF resource to open in a new window, but then the user have to click twice. First for generating the PDF, second for opening.

Is this somehow possible?

Thanks for suggestions

Markus


Replies (5)

RE: Download of PDF resource of button click - Added by Koen Deforche almost 14 years ago

Dear Markus,

The second option (redirecting an anchor to a PDF resource) is really the recommended solution, and the user only needs to click once. For this to work you can create the PDF on the fly when serving it, within a MyPdfResource::handleRequest() method.

Thus:

  • specialize WResource -> MyPdfResource
  • instantiate the resource and create a link to it from a WAnchor (which you can style to resemble a button, or you can instantiate a button inside the anchor).
  • when the user clicks the anchor/button, the resource receives a handleRequest() which should generate the PDF and serve it.

Regards,

koen

RE: Download of PDF resource of button click - Added by Markus Raabe almost 14 years ago

Thanks Koen,

adding a button into the WAnchor works fine. Didn't have a clue this could be possible.

I will also try to specialize the resource. Then it will work as I wanted.

Best regards

Markus

RE: Download of PDF resource of button click - Added by Markus Raabe almost 14 years ago

Unfortunately I did not check correctly.

I add a WPushbutton into the anchor:

m_reportAnchor = new Wt::WAnchor(root());

WPushButton *b2 = new WPushButton("Report");

b2->setMinimumSize(WLength::Auto, WLength(24));

m_reportAnchor->addWidget(b2);

m_input~~elementAt(row, 0)>addWidget(new Wt::WText(""));

m_input
elementAt(row, 1)>addWidget(new Wt::WText(""));

m_input
elementAt(row, 2)>addWidget(m_reportAnchor);

m_input
elementAt(row, 3)~~>addWidget(new Wt::WText(""));

Somewhere else the resource is added:

m_reportAnchor->setResource(m_report);

m_reportAnchor->setTarget(Wt::TargetNewWindow);

m_reportAnchor->show();

When I press the button, I get two windows with the pdf in each. Where does this double event come from?

Best regards

Markus

RE: Download of PDF resource of button click - Added by Markus Raabe almost 14 years ago

The event is only sent twice in firebox. In IE 8 no event is sent at all.

RE: Download of PDF resource of button click - Added by Koen Deforche almost 14 years ago

Hey,

You are right: the W3C spec dictates that you cannot put a button in an anchor and thus browsers will try their best to be as inconsistent as possible in their behavior when you do.

With that it seems that the only way to achieve what you want (to some extent) is to style an anchor that it looks like a button, e.g. using a PDF icon (which most users will recognize!).

Sorry for the wrong advice !

Regards,

koen

    (1-5/5)