making PDFs open in browser

27 views
Skip to first unread message

fooba...@gmail.com

unread,
Oct 6, 2021, 12:30:43 PM10/6/21
to Dataverse Users Community
When users open PDFs from my dataverse installation, I'd like the response to encourage the browser to open the PDF inline rather than downloading it. As it stands, the only way to request the file is the "download" button which creates a response with content-disposition: attachment. I think if I could get it to do content-disposition:inline then we'd be good. Is there a way to do that with Dataverse?

James Myers

unread,
Oct 6, 2021, 1:15:56 PM10/6/21
to dataverse...@googlegroups.com

There isn’t a way to change the content-disposition, but there are previewers for pdf and other file types. You can follow the instructions at https://github.com/GlobalDataverseCommunityConsortium/dataverse-previewers to set up the pdf previewer (and others that you might want.) These were implemented as of Dataverse v4.11, but there have been updates to display previews in the page (v4.18) and to separate how previewers and other explore tools are displayed (v5.2+). Note that there is a develop branch in that repository (https://github.com/GlobalDataverseCommunityConsortium/dataverse-previewers/tree/develop) that has updated instructions for Dataverse v5.2+.

 

-- Jim

--
You received this message because you are subscribed to the Google Groups "Dataverse Users Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dataverse-commu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dataverse-community/7ac1755d-ad2a-4496-a3dd-5d23fae763ccn%40googlegroups.com.

Sherry Lake

unread,
Oct 6, 2021, 1:21:30 PM10/6/21
to dataverse...@googlegroups.com
Hello,

Yes there is a way to preview PDFs (and other common file types) in Dataverse with Previewers set up. Here's the guide info:

Check out the github readme to see how to configure the options.


--
Sherry Lake
University of Virginia 

On Wed, Oct 6, 2021 at 12:30 PM fooba...@gmail.com <fooba...@gmail.com> wrote:
When users open PDFs from my dataverse installation, I'd like the response to encourage the browser to open the PDF inline rather than downloading it. As it stands, the only way to request the file is the "download" button which creates a response with content-disposition: attachment. I think if I could get it to do content-disposition:inline then we'd be good. Is there a way to do that with Dataverse?

--

fooba...@gmail.com

unread,
Oct 6, 2021, 3:48:14 PM10/6/21
to Dataverse Users Community
Thanks all! I didn't know about the previewer.

Philip Durbin

unread,
Oct 6, 2021, 3:59:20 PM10/6/21
to dataverse...@googlegroups.com
If you haven't played with the previewers and just want to see how PDFs look in them, they're enabled on both https://demo.dataverse.org and Harvard Dataverse (and no doubt other installations).

Here's an random example of how a PDF looks: https://dataverse.harvard.edu/file.xhtml?fileId=4467934

Thanks,

Phil




--

fooba...@gmail.com

unread,
Oct 6, 2021, 4:09:43 PM10/6/21
to Dataverse Users Community
Hm. I've enabled the PDF previewer on my installation and it's not really what I was looking for. I wonder if I could make a simple previewer that causes the browser's PDF reader to open the file inline?

James Myers

unread,
Oct 6, 2021, 5:25:55 PM10/6/21
to dataverse...@googlegroups.com

FWIW: Later versions of Dataverse (>4.18) do open the PDF in the DataFile page rather than as a new window (you can still pop-out). That said, previewers are just tools using the Dataverse API so you can make any you want. The intent with the existing ones was to cover ‘most’ browsers, so relying on specific plugins wasn’t something we wanted to do, but if the browser’s pdf viewing is better, it could be that the existing previewer could be updated to do that if possible and, if not, default back to what happens now.

 

Feel free to discuss at the dataverse-previewers repo and/or to create a PR there if you think what you’re doing is of general interest.

 

-- Jim

 

From: dataverse...@googlegroups.com [mailto:dataverse...@googlegroups.com] On Behalf Of fooba...@gmail.com


Sent: Wednesday, October 6, 2021 4:10 PM
To: Dataverse Users Community

fooba...@gmail.com

unread,
Oct 6, 2021, 6:23:30 PM10/6/21
to Dataverse Users Community
Thanks, Jim. I'm going to experiment with a previewer of my own and will create a PR if it works out.

fooba...@gmail.com

unread,
Oct 7, 2021, 12:31:37 AM10/7/21
to Dataverse Users Community
I ended up writing this simple middleware: https://github.com/foobarbecue/dataverse-previewers/blob/develop/previewers/PDFEmbed.html , but I also had to hack the response headers to make it work. I used a traefik middlware in kubernetes to change content-disposition to inline and x-frame-options to allow.

I also played around with improving the pdf.js display in the existing previewer and I might submit a PR for that at some point in the future.

fooba...@gmail.com

unread,
Oct 7, 2021, 12:34:01 AM10/7/21
to Dataverse Users Community
I meant, "this simple externalTool"
Reply all
Reply to author
Forward
0 new messages