sfergus1 Posted November 22, 2012 Share Posted November 22, 2012 I'm trying to figure out how to embed a control in my document that, when clicked, opens the print dialog to print the currently viewed page. I can do this in Acrobat by setting the Link Properties for an element, then "Run a JavaScript" and "Execute a Menu Item". The code is "this.print(null,this.pageNum,this.pageNum)".What I haven't figured out yet is a) how to include this in a PDF generated using Jasper reports and iReport (4.5.0), or b) how to tie my specific element to trigger such code.I've found the net.sf.jasperreports.export.pdf.javascript property, which seems like it's part of the solution. However, despite weeks of searching and experimenting, I haven't been able to make this work. Is it possible? If so, can it be set up through iReport?Thanks,Steve Link to comment Share on other sites More sharing options...
lucianc Posted November 23, 2012 Share Posted November 23, 2012 Not possible with the current code. Log a feature request in the trackers.You can still achieve that by implementing a generic element PDF handler. That would involve writing a class that implements GenericElementPdfHandler, registering the handler as an extension and including a generic element in the report. The handler would do something similar to what JRPdfExporter.setHyperlinkInfo() does.Regards,Lucian Link to comment Share on other sites More sharing options...
sfergus1 Posted November 25, 2012 Author Share Posted November 25, 2012 Thanks for the quick reply. I'll have to take a look into it and see what I can do. Link to comment Share on other sites More sharing options...
sfergus1 Posted November 25, 2012 Author Share Posted November 25, 2012 Do you happen to have any examples of such a generic element handler for PDFs? The demo library only shows HTML, and doesn't seem to be transferable. I've spent most of the day looking over the code and haven't figured out where to insert my logic. I see that JRPdfExporter.exportGenericElement() hands off control to my new handler. The other case in the code that implements GenericElementPdfHandler (MapElementPdfHandler) generates an image and then delegates back to JRPdfExporter.exportImage(). I don't think that approach is appropriate in my case. Yet to duplicate the path the logic goes through between JRPdfExporter.exportText() and JRPdfExporter.setHyperlinkInfo(), which goes from JRPdfExporter to AbstractTextRenderer to PdfTextRenderer back to JRPdfExporter, I need access to protected attributes of JRPdfExporter (tagHelper, for example). Making my class a subclass of JRPdfExporter seems like one possible way to overcome this, but I'm not sure that's the best (or even a correct) approach. Thanks, Steve. Link to comment Share on other sites More sharing options...
Solution lucianc Posted November 27, 2012 Solution Share Posted November 27, 2012 Having all the functionality available to standard report text elements would indeed be impossible to achieve given the current PDF exporter code.But you can write a PDF handler that outputs a simple text with the Javascript action. Attaching such a minimal implementation. /sites/default/files/files/SimplePdfHandler_java.txtTo see it in action, add the following line to jasperreports_extension.properties:net.sf.jasperreports.extension.registry.factory.me=SimplePdfHandlerand then out a generic element with genericElementType namespace="urn:me:me" name="print" in a report.The most important part that is missing is the text font. JRPdfExporter.getFont() is protected unfortunately, if required you might be able to duplicate some code from there.The text itself can be easily given as a generic element parameter.Regards,Lucian Link to comment Share on other sites More sharing options...
sfergus1 Posted December 3, 2012 Author Share Posted December 3, 2012 Thank you very much! This was exactly the push I needed. I've gotten this working and made the solution a bit more generic to allow for any kind of Javascript code attached to the generic element using parameters, just as with the text as you indicated. The modification was trivial. We'll see if it retains formatting here: String linkText = (String)element.getParameterValue("text"); String script = (String)element.getParameterValue("script"); Phrase phrase = new Phrase(); Chunk chunk = new Chunk(linkText); chunk.setAction(PdfAction.javaScript(script, exporterContext.getPdfWriter())); phrase.add(chunk); Link to comment Share on other sites More sharing options...
sfergus1 Posted December 3, 2012 Author Share Posted December 3, 2012 I was able to further enhance the solution as you noted, copying a slimmed down version of the JrPdfExporter.getFont() method to my own class. I made a call to element.getStyle() and copied the TextAttribute values that interested me to the attribute map getFont() expects. This way I'm able to use the iReport GUI to define different styles for my link elements and still have them apply to the resulting generic object that's included in the PDF. Thank you again for your help. Link to comment Share on other sites More sharing options...
abigailklinton Posted August 12, 2013 Share Posted August 12, 2013 you can have a PDF Generating & Reading Add-On,which provides standard options to process PDF document, including:Create and sort a new PDF documentAdd, delete and duplicate page of PDF fileMerge, split, and append PDF document fileAdd annotations on PDF documentRotate one or more pages of PDF fileExtract text from PDF documentPrint PDF document file Link to comment Share on other sites More sharing options...
tingjust Posted May 5, 2014 Share Posted May 5, 2014 editing PDFs you should download one PDF editor software from http://www.pdfconverterformac.net see the descriptions of it and try to use. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now