You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris <ch...@gmx.at> on 2015/04/07 01:10:26 UTC
create link to pdf created on the fly
Hi all,
I would like to create a download link to a PDF which is generated on the fly.
How can I transform the ByteArrayResource into an IResource Stream?
Thanks, Chris
Link pdfLink = new Link("linkPdf") {
@Override
public void onClick() {
final OutputStream pdfOutputStream = generatePdf();
final ByteArrayResource byteArrayResource = new ByteArrayResource("application/pdf", ((ByteArrayOutputStream) pdfOutputStream).toByteArray());
IResourceStream resourceStream = byteArrayResource...;
getRequestCycle().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream, "PDF_Download"));
}
};
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: create link to pdf created on the fly
Posted by Chris <ch...@gmx.at>.
Hi Martin,
thanks a lot, that worked!
Chris
> Am 07.04.2015 um 08:52 schrieb Martin Grigorov <mg...@apache.org>:
>
> Hi,
>
> Check ResourceLink component.
>
> Martin Grigorov
> Freelancer, available for hire!
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Tue, Apr 7, 2015 at 2:10 AM, Chris <ch...@gmx.at> wrote:
>
>> Hi all,
>>
>> I would like to create a download link to a PDF which is generated on the
>> fly.
>>
>> How can I transform the ByteArrayResource into an IResource Stream?
>>
>> Thanks, Chris
>>
>> Link pdfLink = new Link("linkPdf") {
>> @Override
>> public void onClick() {
>> final OutputStream pdfOutputStream = generatePdf();
>>
>> final ByteArrayResource byteArrayResource = new
>> ByteArrayResource("application/pdf", ((ByteArrayOutputStream)
>> pdfOutputStream).toByteArray());
>> IResourceStream resourceStream = byteArrayResource...;
>> getRequestCycle().scheduleRequestHandlerAfterCurrent(new
>> ResourceStreamRequestHandler(resourceStream, "PDF_Download"));
>> }
>> };
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: create link to pdf created on the fly
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
Check ResourceLink component.
Martin Grigorov
Freelancer, available for hire!
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Tue, Apr 7, 2015 at 2:10 AM, Chris <ch...@gmx.at> wrote:
> Hi all,
>
> I would like to create a download link to a PDF which is generated on the
> fly.
>
> How can I transform the ByteArrayResource into an IResource Stream?
>
> Thanks, Chris
>
> Link pdfLink = new Link("linkPdf") {
> @Override
> public void onClick() {
> final OutputStream pdfOutputStream = generatePdf();
>
> final ByteArrayResource byteArrayResource = new
> ByteArrayResource("application/pdf", ((ByteArrayOutputStream)
> pdfOutputStream).toByteArray());
> IResourceStream resourceStream = byteArrayResource...;
> getRequestCycle().scheduleRequestHandlerAfterCurrent(new
> ResourceStreamRequestHandler(resourceStream, "PDF_Download"));
> }
> };
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: create link to pdf created on the fly
Posted by Christoph Läubrich <la...@googlemail.com>.
Is there any reason why you can't use a static mounted resource (with
some page parameter if neccessary)?
This has several advantages e.g. leveraging browser caching, no need for
statefull link etc...
Am 07.04.2015 01:10, schrieb Chris:
> Hi all,
>
> I would like to create a download link to a PDF which is generated on the fly.
>
> How can I transform the ByteArrayResource into an IResource Stream?
>
> Thanks, Chris
>
> Link pdfLink = new Link("linkPdf") {
> @Override
> public void onClick() {
> final OutputStream pdfOutputStream = generatePdf();
>
> final ByteArrayResource byteArrayResource = new ByteArrayResource("application/pdf", ((ByteArrayOutputStream) pdfOutputStream).toByteArray());
> IResourceStream resourceStream = byteArrayResource...;
> getRequestCycle().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream, "PDF_Download"));
> }
> };
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org