[Seaside] View PDF in browser

bobn at rogers.com bobn at rogers.com
Mon Dec 19 19:10:18 UTC 2011

In trying to answer my own question, I followed the path used to answer content from WAFileLibary.
I added an override for #handle: and checked for an 'options' key. If found, a new PDF document is created and answered.

The document is created correctly, but still is not rendered in the browser. I thought I had paralleled the answer sequence correctly. 

WAFileLibrary >> handle: 
aRequestContext respond: [ :response |
cacheFor: self cacheDuration;
document: (self documentForFile: fileName)
mimeType: (self mimetypeForFile: fileName) ]


TSwaFileLibrary >> handleReport: aRequestContext
aRequestContext respond: [ :response |
document: byteArray
mimeType: (self class mimetypeFor: 'PDF') ]

Uploading a PDF file to the WAFileLibrary subclass and using...

...opens the PDF document in the browser, but using my parameter suffixed version...

...triggers a file download on the generated PDF file.

What is different? Both versions write a PDF content byte array to a response with the same mime type. 
Is there something else in the response sequence that I need to deal with?


 From: "bobn at rogers.com" <bobn at rogers.com>
To: SeasideList <seaside at lists.squeakfoundation.org> 
Sent: Sunday, December 18, 2011 1:29:54 PM
Subject: [Seaside] View PDF in browser

The question of how to serve a PDF document has been asked and answered a few times, but not the question of how get the browser to view the PDF without launching a reader app for browsers configured to do that for PDF links. 

For example, if I create a PDF document and load it into my WAFileLibrary subclass, I can reference it with a simple anchor url: ... 
html anchor url: TSwaFileLibrary / #TestReportPdf; with: 'PDF Report File'.

<a href="/files/TSwaFileLibrary/TestReport.pdf">PDF Report File</a>

...which, when selected, displays it in the browser. 

If I generate the file response...
self requestContext respond: [:response |
document: byteArray 
mimeType: (Seaside.WAFileLibrary mimetypeFor: 'PDF')
fileName: 'IssueReport.PDF']
...and use a callback...

html anchor callback: [self pdfReport]; with: 'PDF Report Build'.
<a href="/Issues?_s=tkTzO72EQJbWMxF_&_k=SZ5ABAiSyHAfmzFW&79">PDF Report Build</a>

...I get a PDF reader opening on a file download.

So, I though be cleaver and build a RESTful url for the report (handy for sending links instead of content) which looked like '/blah blah blah.PDF'...
html anchor url: '/Issues?Report=TEST&filter=assigned:Bob_N.|status:open&filename=IssueReport.PDF'; with: 'PDF Report Anchor'

<a href="/Issues?Report=TEST&filter=assigned:Bob_N.|status:open&filename=IssueReport.PDF">PDF Report Anchor</a>

...which also opens a PDF reader on a file download.

Using #target: or WAPopupAnchorTag to open a new browser tab also did not work. 

Given that the href="/files... anchor works, it seems like this could work. 
I'd be grateful for any suggestions.

BTW: I'm using Christian Haider's pdf4smalltalk to build the PDF document. It rocks. 

Bob Nemec

seaside mailing list
seaside at lists.squeakfoundation.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20111219/9c5f8e38/attachment.htm

More information about the seaside mailing list