You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by hongdida <ho...@gmail.com> on 2014/07/29 05:03:32 UTC
Re: NonCachingImage and xhtmlRenderer
Xavi López wrote
> Sorry for double-posting, I'm attaching some of the code I'm using:
>
> I havent't mentioned other static styling images are rendering correctly.
>
>
> byte[] imageByteArray =
> generateBarCodeImage <http://www.barcodelib.com/net_barcode/main.html>
> (...)
>> ByteArrayResource resource = new ByteArrayResource("image/jpeg",
>> imageByteArray);
>> Image barcodeImage= new Image("barcode", resource){
>> protected void onComponentTag(ComponentTag tag)
>> {
>> super.onComponentTag(tag);
>> String url = tag.getAttributes().getString("src");
>> url = url + ((url.indexOf("?") >= 0) ? "&" : "?");
>> url = url + "wicket:antiCache=" +
>> System.currentTimeMillis();
>> tag.put("src", url);
>> }
>> };
>> barcodeImage.setMarkupId("barcodeImageId");
>> barcodeImage.setOutputMarkupId(true);
>> add(imatgeCodiBarres);
>> .....
>> link = new Link("printPDF"){
>> private static final long serialVersionUID = 1L;
>> @Override
>> public void onClick() {
>> try{
>> String baseUrl = "http://myapp/";
>> // Get the html to render into pdf
>> String html = RenderHTMLUtils.renderPage(new
>> PrintPage(...));
>> DocumentBuilder builder =
>> DocumentBuilderFactory.newInstance().newDocumentBuilder();
>> Document doc = builder.parse(new
>> ByteArrayInputStream(html.getBytes("UTF-8")));
>>
>>
>> String src =
>> doc.getElementById("barcodeImageId").getAttribute("src");
>> src = baseUrl + src;
>>
>> doc.getElementById("barcodeImageId").setAttribute("src", src);
>>
>> ITextRenderer renderer = new ITextRenderer();
>> renderer.setDocument(doc, baseUrl);
>>
>>
>> RequestCycle.get().setRequestTarget(EmptyRequestTarget.getInstance());
>> WebResponse response = (WebResponse)
>> getResponse();
>> response.setContentType("application/pdf");
>> response.setAttachmentHeader("printout.pdf");
>> response.setHeader("Cache-Control",
>> "max-age=0");
>> OutputStream out =
>> response.getOutputStream();
>> renderer.layout();
>> renderer.createPDF(out);
>> }
>> catch (Exception e){ }
>> }
>> };
>>
>
> 2010/5/27 Xavier López <
> xavilope@
> >
>
> --
> "Klein bottle for rent--inquire within."
Never successful with the dynamic image styling?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/NonCachingImage-and-xhtmlRenderer-tp2232935p4666779.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org