Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF.js CSS/Stylesheets #127

Closed
jeff-griffin-hm opened this issue Mar 1, 2017 · 9 comments
Closed

PDF.js CSS/Stylesheets #127

jeff-griffin-hm opened this issue Mar 1, 2017 · 9 comments

Comments

@jeff-griffin-hm
Copy link

I used PDFObject to display an embedded PDF for our customers, utilizing the ability to fall back on PDF.js in case of no embedded PDF support (e.g., iOS).

This ended up working great, and thanks for the useful library.

However, I did notice a slight problem in my use case. Originally the PDF.js viewer.html file would not show up at all, whereas the raw embedded PDF would.

After downloading the source and investigating, I isolated the problem to the following:

var iframe = "<div style='" + scrollfix + "position: absolute; top: 0; right: 0; bottom: 0; left: 0;'><iframe  " + id + " src='" + fullURL + "' style='border: none; width: 100%; height: 100%;' `frameborder='0'></iframe></div>";

Removing the position: absolute from this <div> or switching it to position: relative caused the PDF.js viewer to appear. Removing position styles from the root container (.pdfobject-container) also fixes the issue.

This may have something to do with the context this is running in (I haven't had time to check), but in general, is it feasible to put the styling in a separate CSS file rather than inside the JS code?

@pipwerks
Copy link
Owner

pipwerks commented Mar 1, 2017

Interesting use case.

Currently there is only one file: pdfobject.js. Externalizing the CSS would require adding another file. No big deal to those who use NPM, but many PDFObject users do not use package managers, and adding the additional CSS would be a big deal.

Also, the code you're asking to remove was specifically added for PDF.js! https://github.com/pipwerks/PDFObject/blob/master/pdfobject.js#L153

So I'd need to better understand the issue before making any changes.

@jeff-griffin-hm
Copy link
Author

Yeah, I understand the code was added specifically for PDF.js. That's how I isolated the issue in the first place. The inline CSS worked fine for my application when it was doing the raw embed, but setting forcePDFJS: true or accessing the application in iOS caused a blank area where viewer.html should have been. I fixed it by removing the positioning styles from that function in my local copy of the file.

I can emulate the problem with the following HTML file:

<html>
	<head>
	</head>
	<body>
		<div id="pdf-container" style="position: relative">
			<div id="inner" style="position: absolute; top: 0; right: 0; bottom: 0; left: 0;">
			<iframe src='embed.html' style='border: none; width: 100%; height: 100%;'>
			</iframe>
			</div>
		</div>
	</body>
</html>

And say embed.html contains some filler like this:

<h1>Pretend I am a PDF.</h1>

This mimics PDFObject's generated structure (with the #pdf-container <div> element being the container passed to the embed() method).

The iframe source will not show for me in Google Chrome unless the CSS is modified in one of the ways suggested above.

@pipwerks
Copy link
Owner

pipwerks commented Mar 2, 2017

Thanks for the additional info, I will need some time to check it out.

@jeff-griffin-hm
Copy link
Author

Sure, and if there's anything else I can provide to assist you, let me know.

@jordi-pujol-cayon
Copy link

I want to add that Firefox 52.0 is the first without support for MIME application/pdf, and just was released on March 7 2017, as a current supported official release. So... the number of troubled pdfobject v1 users will increase since then.

@pipwerks
Copy link
Owner

Sorry for the radio silence on this @j30392 . Do you happen to have an example posted online that I can review?

@pipwerks
Copy link
Owner

@jeff-griffin-hm is this still an issue?

@pipwerks
Copy link
Owner

For the 2.2.0 update, there is now an option to remove all inline styles so you can manage CSS on your own. https://pdfobject.com/dev/tests/omit-inline-styles.html

2.2.0 is not released yet but will be released soon. Closing ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@pipwerks @jordi-pujol-cayon @jeff-griffin-hm and others