Hi!
Ok.
Here is some bits and parts, hopefully useful:
/**
* Convert HTML to PDF
* @param in HTML
* @param out PDF
*/
public static void html2pdf(InputStream in, OutputStream out) {
try {
StringWriter sw = new StringWriter();
Tidy tidier = new Tidy();
{
tidier.setInputEncoding(ENCODING);
tidier.setQuiet(true);
tidier.setXHTML(true);
tidier.setTidyMark(false);
tidier.parse(in, sw);
}
{
ITextRenderer renderer = new ITextRenderer();
// String s = sw.getBuffer().toString();
// System.out.println(s);
renderer.setDocumentFromString(sw.getBuffer().toString());
renderer.layout();
renderer.createPDF(out);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Renders given page
* @param pageClass to render
* @param pageParameters to render with
* @param clean
* @return String of HTML produced
*/
public static String renderPageToString(
final Class<? extends Page> pageClass,
final PageParameters pageParameters, boolean clean) {
String webPageAsString;
{
WebApplication webApplication = WebApplication.get();
ServletContext servletContext = webApplication.getServletContext();
MockHttpSession servletSession = new MockHttpSession(servletContext);
servletSession.setTemporary(true);
MockHttpServletRequest servletRequest = new MockHttpServletRequest(
webApplication, servletSession, servletContext);
MockHttpServletResponse servletResponse = new MockHttpServletResponse(
servletRequest);
servletRequest.initialize();
servletResponse.initialize();
WebRequest webRequest = new ServletWebRequest(servletRequest);
BufferedWebResponse webResponse = new
BufferedWebResponse(servletResponse);
webResponse.setAjax(true);
WebRequestCycle htmlRequestCycle =
new WebRequestCycle(webApplication, webRequest, webResponse);
BookmarkablePageRequestTarget htmlTarget =
new BookmarkablePageRequestTarget(pageClass, pageParameters);
htmlRequestCycle.setRequestTarget(htmlTarget);
try {
htmlRequestCycle.getProcessor().respond(htmlRequestCycle);
if (htmlRequestCycle.wasHandled() == false) {
htmlRequestCycle.setRequestTarget(new WebErrorCodeResponseTarget(
HttpServletResponse.SC_NOT_FOUND));
}
htmlRequestCycle.detach();
} finally {
htmlRequestCycle.getResponse().close();
}
webPageAsString = webResponse.toString();
}
webPageAsString = Utils.replaceAll(webPageAsString,
WebPageConstants.SRC_URL_PATTERN, "file:///" +
WebApplication.get().getServletContext().getRealPath("/") + "/");
if (clean) {
return escapeHighEnd(webPageAsString.replaceAll("<wicket.*?>", "")
.replaceAll("</wicket.*?>", "").replaceAll("\\swicketpath=\".*?\"",
""));
}
return escapeHighEnd(webPageAsString);
}
**
Martin
2010/2/28 Alex Rass <[email protected]>:
> That's what google is doing to print (through a conversion on the back end).
> So if you contribute it, I am sure SOMEONE would want it :)
>
> - Alex
>
>
> -----Original Message-----
> From: Martin Makundi [mailto:[email protected]]
> Sent: Sunday, February 28, 2010 12:22 PM
> To: [email protected]
> Subject: Re: Print friendly panel
>
> Hi!
>
> Anybody interested in pdf print script via wicket?
>
> **
> Martin
>
> 2010/2/28 nino martinez wael <[email protected]>:
>> Yeah I agree this is the way it should be done. Works like a charm! And
> then
>> just have a simple js like this:
>>
>> <script language="Javascript1.2">
>> <!--
>> function printpage() {
>> window.print();
>> }
>> //-->
>> </script>
>>
>> on or link button or whatever..
>>
>>
>>
>> 2010/2/28 Riyad Kalla <[email protected]>
>>
>>> This is what I've done in the past as well, allows your user to just
>>> "print"
>>> the page they are staring at and have the browser do the right thing in
>>> using an alternative style sheet for rendering the page -- this includes
>>> using a lot of display:none to trim down the parts of the page that you
>>> don't want printing. This way all you need on your page is a "Print" link
>>> that invokes the Print dialog, no other popups ontop of popups.
>>>
>>> Some info:
>>>
> http://www.scottklarr.com/topic/15/css-create-a-style-sheet-for-print-only/
>>>
>>> <
>>>
> http://www.scottklarr.com/topic/15/css-create-a-style-sheet-for-print-only/
>>> >
>>> http://webdesign.about.com/cs/css/a/aa042103a.htm
>>>
>>> On Sat, Feb 27, 2010 at 4:54 PM, Alex Rass <[email protected]> wrote:
>>>
>>> > Josh,
>>> >
>>> > This doesn't answer your question directly (about a popup).
>>> > But a MUCH simpler way is to make your page printer friendly by
> supplying
>>> > an
>>> > alternative CSS for printing format (google on that). Makes life much
>>> > easier.
>>> >
>>> > When you tell your page which css to use, you can say "use this CSS for
>>> > printing only". All transparent to the user.
>>> >
>>> > - Alex
>>> >
>>> >
>>> > -----Original Message-----
>>> > From: Josh Chappelle [mailto:[email protected]]
>>> > Sent: Friday, February 26, 2010 4:09 PM
>>> > To: [email protected]
>>> > Subject: Print friendly panel
>>> >
>>> > Hi,
>>> >
>>> >
>>> >
>>> > Does anyone know of a suggested method to render a printer friendly
> panel
>>> > to
>>> > a separate browser window so that user's can print? The only thing I
> have
>>> > found is the following article and it looks a little clunky.
>>> >
>>> >
>>> >
>>> > http://cwiki.apache.org/WICKET/rendering-panel-to-a-string.html
>>> >
>>> >
>>> >
>>> > Basically I just need to be able to place a link that when clicked will
>>> pop
>>> > up a new browser window with only the contents to the target panel.
> That
>>> > way
>>> > users can print that panel from there.
>>> >
>>> >
>>> >
>>> > Thanks,
>>> >
>>> >
>>> >
>>> > Josh
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: [email protected]
>>> > For additional commands, e-mail: [email protected]
>>> >
>>> >
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]