View PDF in browser

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

View PDF in browser

Bob Nemec
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 |
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. 

Thanks,
Bob Nemec




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Bob Nemec
Reply | Threaded
Open this post in threaded view
|

Re: View PDF in browser

Yanni Chiu
On 18/12/11 1:29 PM, [hidden email] wrote:
>
> Given that the href="/files... anchor works, it seems like this could work.
> I'd be gratefulfor any suggestions.

Have you tried setting the content-length http header, or turning off
streaming of the http response?

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: View PDF in browser

Bob Nemec
Yanni,

I already use...
headerAt: 'Content-length' put: aContents size printString;
...for all of may document downloads, and I did try to manually build a WABufferedResponse

Neither made a difference.

Is there something else you're suggesting?

Bob


From: Yanni Chiu <[hidden email]>
To: [hidden email]
Sent: Sunday, December 18, 2011 7:05:43 PM
Subject: [Seaside] Re: View PDF in browser

On 18/12/11 1:29 PM, [hidden email] wrote:
>
> Given that the href="/files... anchor works, it seems like this could work.
> I'd be gratefulfor any suggestions.

Have you tried setting the content-length http header, or turning off
streaming of the http response?

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Bob Nemec
Reply | Threaded
Open this post in threaded view
|

Re: View PDF in browser

Torsten Bergmann
In reply to this post by Bob Nemec
Bob Nemec wrote:
>but not the question of how get the browser to view the PDF without >launching a reader app for browsers

Hi Bob,

This is not a server issue. It's a client setting.

In Adobe there is a setting to 'Display PDF in browser', somewhere in the preferences. I think it is edit | preferences. Click on internet on the left then display pdf in browser on the right.

Bye
Torsten


--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: View PDF in browser

Bob Nemec
In reply to this post by Bob Nemec
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 |
response
cacheFor: self cacheDuration;
document: (self documentForFile: fileName)
mimeType: (self mimetypeForFile: fileName) ]

vs. 

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

Uploading a PDF file to the WAFileLibrary subclass and using...
http://localhost:48199/files/TSwaFileLibrary/TestSimpleReport.pdf
...opens the PDF document in the browser, but using my parameter suffixed version...
http://localhost:48199/files/TSwaFileLibrary/Report.pdf?options=assigned|id|system|title&filter=assigned:Bob_N.|status:open
...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?

Bob



From: "[hidden email]" <[hidden email]>
To: SeasideList <[hidden email]>
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 |
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. 

Thanks,
Bob Nemec




_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Bob Nemec
Reply | Threaded
Open this post in threaded view
|

Re: View PDF in browser

Yanni Chiu
In reply to this post by Bob Nemec
 <bobn <at> rogers.com> writes:
>
> Neither made a difference.
>
> Is there something else you're suggesting?

Nothing other than what you tried.

At this point, I'd look at the actual bytes being sent in the two cases.
I still think there's a difference in the http headers. I usually use "telnet"
to the http port, and respond with "GET <your-URL-here> HTTP/1.1".


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: View PDF in browser

Boris Popov, DeepCove Labs (SNN)
I just tested the below locally in Chrome and Firefox,

"Chrome downloads the file; Firefox prompts to download the file"
self requestContext respond:
                [:response |
                response document: ((WAMimeDocument on: bytes mimeType:
'application/pdf')
       
fileName: filename;
       
yourself)]

"Chrome opens the document in the browser; Firefox opens the document in
the browser"
self requestContext respond:
                [:response |
                response document: (WAMimeDocument on: bytes mimeType:
'application/pdf')]

-Boris

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Yanni
Chiu
Sent: Monday, December 19, 2011 2:36 PM
To: [hidden email]
Subject: [Seaside] Re: View PDF in browser

 <bobn <at> rogers.com> writes:
>
> Neither made a difference.
>
> Is there something else you're suggesting?

Nothing other than what you tried.

At this point, I'd look at the actual bytes being sent in the two cases.
I still think there's a difference in the http headers. I usually use
"telnet"
to the http port, and respond with "GET <your-URL-here> HTTP/1.1".


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: View PDF in browser

Torsten Bergmann
In reply to this post by Bob Nemec
Hi Bob,

attached is an example that works for me (Seaside 3.0.6 in Pharo 1.3).

Point your browser to

   http://localhost:8080/pdfexample

There are two examples:

If you want to host the PDF file within a custom file library
look at PDFExRootComponent>>respondWithPDF

For the second example (hosting the PDF on hard disk)
just put the attached helloworld.pdf into c:\temp\ or adopt the
files location in PDFExRootComponent>>respondWithPDFFromFile.

Both of them open directly within the browser (tried with
Chrome and IE) in conjunction with Adobe Reader.

Bye
T.



-------- Original-Nachricht --------
> Datum: Mon, 19 Dec 2011 04:29:41 -0800 (PST)
> Von: [hidden email]
> An: Torsten Bergmann <[hidden email]>
> Betreff: Re: View PDF in browser

> Torsten,
> > In Adobe there is a setting to 'Display PDF in browser'
> That is indeed how I have my browser configured. If the link is to a PDF
> file, it does get displayed in the browser. 
>
> So...
> html anchor url: TSwaFileLibrary / #TestReportPdf; with: 'PDF Report
> File'. 
>
> ...is displayed in the browser, but...
> html anchor callback: [self pdfReport]; with: 'PDF Report Build'. 
>
> ...triggers a PDF file download.
>
> I'm looking for a way to trigger the 'in browser' PDF display for
> generated PDF files served from Seaside, a way to have browser see the link as a
> PDF document.
>
> Bob
>
>
> ________________________________
>  From: Torsten Bergmann <[hidden email]>
> To: [hidden email]
> Cc: [hidden email]
> Sent: Monday, December 19, 2011 6:39:18 AM
> Subject: Re: View PDF in browser
>  
> Bob Nemec wrote:
> >but not the question of how get the browser to view the PDF without
> >launching a reader app for browsers
>
> Hi Bob,
>
> This is not a server issue. It's a client setting.
>
> In Adobe there is a setting to 'Display PDF in browser', somewhere in the
> preferences. I think it is edit | preferences. Click on internet on the
> left then display pdf in browser on the right.
>
> Bye
> Torsten
>
>
> --
> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

helloworld.pdf (11K) Download Attachment
PDF-Download-Example.st (40K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: View PDF in browser

Bob Nemec
In reply to this post by Boris Popov, DeepCove Labs (SNN)
Boris,
Thanks, nice catch.
No filename in the response was indeed the difference.

Bob


From: "Boris Popov, DeepCove Labs" <[hidden email]>
To: Seaside - general discussion <[hidden email]>
Sent: Monday, December 19, 2011 2:46:53 PM
Subject: RE: [Seaside] Re: View PDF in browser

I just tested the below locally in Chrome and Firefox,

"Chrome downloads the file; Firefox prompts to download the file"
self requestContext respond:
        [:response |
        response document: ((WAMimeDocument on: bytes mimeType:
'application/pdf')
   
fileName: filename;
   
yourself)]

"Chrome opens the document in the browser; Firefox opens the document in
the browser"
self requestContext respond:
        [:response |
        response document: (WAMimeDocument on: bytes mimeType:
'application/pdf')]

-Boris

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Yanni
Chiu
Sent: Monday, December 19, 2011 2:36 PM
To: [hidden email]
Subject: [Seaside] Re: View PDF in browser

<bobn <at> rogers.com> writes:
>
> Neither made a difference.
>
> Is there something else you're suggesting?

Nothing other than what you tried.

At this point, I'd look at the actual bytes being sent in the two cases.
I still think there's a difference in the http headers. I usually use
"telnet"
to the http port, and respond with "GET <your-URL-here> HTTP/1.1".


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Bob Nemec