Skip to content

Conversation

@alonelion1987
Copy link
Contributor

@alonelion1987 alonelion1987 commented Jan 16, 2019

Hello!

closes #13162

For more convenient viewing of pdf files in a frame in the browser and for viewing in a new window in a desktop application (Electron) using a special library (related RocketChat/Rocket.Chat.Electron#1062 => as it should work along with it) with the ability to view all pages pdf, print, zoom and more

const dataUrl = URL.createObjectURL(filePdfBlob);
modal.open({
showConfirmButton: false,
text: Blaze.toHTMLWithData(Template.pdfViewer, { dataUrl }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you pass the PDF url instead of loading the file in memory to pass a object url?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as soon as I pass the direct absolute link in the web browser, the file is downloaded and the document is not displayed in the modal window

_14

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may change here to accept parameters when requesting the file, that way you could pass like ?disposition=inline and replace the attachment by inline

Copy link
Contributor Author

@alonelion1987 alonelion1987 Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodrigok tell me pls, how exactly, i can get into this place from 'click .pdf-open-in-modal'(event) function to overwrite Content-Disposition header? i find some places where in my code have simple access this and this, perhaps maybe there are more places that need processing. I understand what it is not very beautiful, because should be manage headers from one place, but now i can't access to here.

Moreover, using this workaround, I achieved that I was loading into a modal window in the browser, but not until the end. There are problems with CSP:
_20

Edit: Solved CSP problem in current processing res.removeHeader('Content-Security-Policy');

updated pr - commit

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place you need to change is this I guess, this is the final part where the file pass before end up at client side, there the content-disposition is defined for every file.

Copy link
Contributor Author

@alonelion1987 alonelion1987 Jan 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! well, I will continue to look at how to improve this situation in order to remove the server method that is not needed at all (I have already deleted it)

One more question. Is this a solution that will allow working with pdf from a web browser and an electron application to be on a par with rendering pdf, which is now or instead of it?

@alonelion1987 alonelion1987 changed the title [NEW] PDF preview server side rendering [NEW] PDF preview full rendering in modal (browser), in window (app) Jan 24, 2019
@alonelion1987 alonelion1987 changed the title [NEW] PDF preview full rendering in modal (browser), in window (app) [NEW] full PDF preview rendering in modal (browser), in window (app) Jan 24, 2019
ggazzo
ggazzo previously approved these changes Mar 1, 2019
if (stat && stat.isFile()) {
file = FileUpload.addExtensionTo(file);
res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${ encodeURIComponent(file.name) }`);
if (req.query && req.query.hasOwnProperty('disposition')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not?

const disposition = req.query && req.query.hasOwnProperty('disposition') ? req.query.disposition : 'attachment';
if (disposition) {
	res.removeHeader('Content-Security-Policy');
}
res.setHeader('Content-Disposition', `${ req.query.disposition }; filename*=UTF-8''${ encodeURIComponent(file.name) }`);

And why need to remove the Content-Security-Policy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why need to remove the Content-Security-Policy?

because i get error:

_59

and probably rude fix:

if (disposition === 'inline') {
	res.removeHeader('Content-Security-Policy');
}

<span class="collapse-switch icon-down-dir" data-index="{{index}}" data-collapsed="{{collapsed}}"></span>
{{/if}}
</div>
<div class="attachment-title">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation is wrong here

@rodrigok
Copy link
Member

rodrigok commented Mar 1, 2019

What happens for files stored at S3 or GS?

@alonelion1987
Copy link
Contributor Author

What happens for files stored at S3 or GS?

I need help verifying these services. But in the code of these components, I did not find the set of the Content-Disposition header, but I can’t test it experimentally.

@ggazzo ggazzo added this to the 2.3.0 milestone Oct 28, 2019
@engelgabriel engelgabriel modified the milestones: 2.3.0, 3.1.0 Mar 17, 2020
@engelgabriel engelgabriel modified the milestones: 3.1.0, 3.2.0 Apr 20, 2020
@engelgabriel engelgabriel modified the milestones: 3.2.0, 3.3.0 May 7, 2020
@rodrigok rodrigok modified the milestones: 3.3.0, 3.4.0 May 20, 2020
@rodrigok rodrigok modified the milestones: 3.4.0, 3.5.0 Jun 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make previews for PDF files (server side rendering)

6 participants