Dowemo
0 0 0 0


Question:

my wicket apliaction created some pdf file. now I want to add button to print it somethink like this: http://javascript.about.com/library/blprint.htm how I can do it ?


Best Answer:


it looks you mix two things together. Your example is a javascript. It is not a PDF, it is just printing your document. It is equal as browser menu File -> Print, but the event is invoked from a javascript that handles button action. You can use the same button as in that example and add @print CSS to your web page to make your document nicely printable.

Also there is another way. If you want to print a PDF document from your application and you generate the PDF from Java code, look the following example for Wicket 1.6:

add(new Link<Void>("myPdfLink") {
    private static final long serialVersionUID = 1L;
    @Override
    public void onClick() {
        byte[] data = ... // TODO your data
        final ByteArrayInputStream stream = new ByteArrayInputStream(data);
        IResourceStream resourceStream = new AbstractResourceStream() {                    
            private static final long serialVersionUID = 1L;
            @Override
            public InputStream getInputStream() throws ResourceStreamNotFoundException {
                return stream;
            }
            @Override
            public void close() throws IOException {
                stream.close();
            }
            @Override
            public String getContentType() {
                return "application/pdf";
            }
        };   
        getRequestCycle().scheduleRequestHandlerAfterCurrent(
            new ResourceStreamRequestHandler(resourceStream)
                .setFileName("my-pdf-to-download.pdf")
                .setContentDisposition(ContentDisposition.ATTACHMENT)
                .setCacheDuration(Duration.ONE_SECOND)
        );  
    }
}); 



Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs