Hi Daniel, Yes, you need an iframe. It isn't possible to directly embed a PDF file into an HTML page (independent of Tapestry). As suggested, use the ComponentResource to get the link for the iframe.
Best, Thilo ________________________________________ From: Poggenpohl, Daniel <daniel.poggenp...@isst.fraunhofer.de> Sent: Thursday, February 19, 2015 16:50 To: Tapestry users Subject: AW: PDF Viewer component Hi, I think I've reduced the problem... Can I have a page containing a zone that displays the contents of a pdf file? tml: <body> <t:Zone t:id="inline" id="inline"> </t:Zone> <t:EventLink t:event="showDoc" t:zone="inline"> Show Doc </t:EventLink> </body> Java: Object onShowDoc() { // Some Object containing a member describing a path to a PDF document SomeObject someObject = someDAO.find(1L); String documentPath = someObject.getDocumentUrl(); Path somePath = Paths.get(documentPath); // the PDF document File someFile = somePath.toFile(); return new InlineViewingStreamResponse(someFile); } Do I have to use an iframe for displaying a pdf? Does this work with zones? Does the zone need some other return value? Once this is clear to me, the rest will fall into place, it seems. Regards, Daniel P. -----Ursprüngliche Nachricht----- Von: Poggenpohl, Daniel [mailto:daniel.poggenp...@isst.fraunhofer.de] Gesendet: Donnerstag, 19. Februar 2015 16:11 An: Tapestry users Betreff: AW: PDF Viewer component Hi, I've found out that the "src" value is a web app context relative path (could have thought of that myself...). So the embedding of another page shouldn't be a problem. Also thanks to Lance Java for helping with that, so there are at least two ways to generate page links to a separate viewer page. However, I would still like to know what I am doing wrong using a component for doing the job. Must be something super obvious, I think. @Thilo Tanner: I'm a bit confused by your eventlink suggestion. I have probably omitted too much information, it seems. My setup is basically this: A page containing two components - a box containing information and a few buttons, one of which fires the event which does some maintenance work and then bubbles up the event to the main page. The main page changes the current document url page property and updates the zone containing the document viewer (zone="someZone" and return someZone.getBody() ). - the document viewer component: it receives the document url property of the main page as a parameter and returns the StreamResponse according to the content of the property. Is this what you mean by using event links? Or do you mean that I should update the zone with the StreamResponse directly? Regards, Daniel P. -----Ursprüngliche Nachricht----- Von: Poggenpohl, Daniel [mailto:daniel.poggenp...@isst.fraunhofer.de] Gesendet: Donnerstag, 19. Februar 2015 15:28 An: Tapestry users Betreff: AW: PDF Viewer component Hello, well, embedding the component in a page shows not the PDF but the Java object identity, e.g. InlineViewingStreamResponse@8173c6 Maybe the error is somewhere else? My component template is basically only ${showDocument()}. Re: iframe - If I use an iframe for embedding a document viewer page, how do I set the "src" parameter? I haven't found a more elegant way than src="go\back\to\the\folder\containing\the\viewer". Regards, Daniel P. -----Ursprüngliche Nachricht----- Von: Thilo Tanner [mailto:thilo.tan...@reprisk.com] Gesendet: Donnerstag, 19. Februar 2015 15:19 An: Tapestry users Betreff: Re: PDF Viewer component Hi Daniel, What exactly is the issue with your code? We use something similar (and content type "application/pdf"); see below. I'm sure you will take care of it when the code works, but your implementation is extremely dangerous :-) Best, Thilo public abstract class AbstractStreamResponse implements StreamResponse { private String contentType; private String filename; public AbstractStreamResponse(String contentType) { this.contentType = contentType; } public void setFilename(String filename) { this.filename = filename; } @Override public String getContentType() { return contentType; } @Override public void prepareResponse(Response response) { if(!Strings.isNullOrEmpty(filename)) { try { String encodedFilename = URLEncoder.encode(filename, "UTF-8"); response.setHeader("Content-Disposition", String.format("attachment; filename=%s", encodedFilename)); } catch (UnsupportedEncodingException e) { // skip } } } } ________________________________________ From: Poggenpohl, Daniel <daniel.poggenp...@isst.fraunhofer.de> Sent: Thursday, February 19, 2015 15:06 To: Tapestry users Subject: AW: PDF Viewer component Hi, a little bit more information (read: code)... I know the code is imperfect but this was just a quick and dirty setup to try inline document viewing. My Viewer component: public class Viewer { @Parameter(required=true) @Property String documentUrl; @Inject Logger logger; public StreamResponse showDocument() { if ("".equals(documentUrl)) { return null; } File pdf = new File(documentUrl); return new InlineViewingStreamResponse (pdf); } My StreamResponse implementation: public class InlineViewingStreamResponse implements StreamResponse { File file; public FileAttachment(File file) throws FileNotFoundException { if (file != null && file.exists() && file.isFile()) { this.file = file; } else { throw new FileNotFoundException(); } } @Override public String getContentType() { try { return Files.probeContentType(file.toPath()); } catch (IOException e) { e.printStackTrace(); return null; } } @Override public InputStream getStream() throws IOException { return new BufferedInputStream(new FileInputStream(file)); } @Override public void prepareResponse(Response response) { response.setHeader("Content-Disposition", "inline; filename=" + file.getName()); } Regards, Daniel P. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org