Comments (5)
Very interesting! It does seem to work. Here's a minimal example:
https://gdocs-pdf-embed.pages.dev/
I used the following HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>PDF embed via Google Docs</title>
</head>
<body style="max-width: 72rem; margin: 0 auto; padding: 1rem">
<iframe
width="100%"
height="500px"
src="https://docs.google.com/viewer?embedded=true&url=https://pdfobject.com/pdf/sample-3pp.pdf"
></iframe>
</body>
</html>
from pdfobject.
It's an interesting idea, but using this technique will cause Google to scan and cache your file. Many companies who use PDFObject use it for proprietary documents (financial, legal documents, technical), which they'd prefer not to give to Google.
Also FWIW there are other providers who provide a similar PDF preview service, like Microsoft. https://gist.github.com/tzmartin/1cf85dc3d975f94cfddc04bc0dd399be
from pdfobject.
Yeah, I can't imagine having such a thing enabled by default in a FOSS PDF embedding library. Even having it on an opt-in basis would probably raise some eyebrows.
edit: I guess the API could be set up to allow people to supply a "fallback iframe source prefix," or something.
from pdfobject.
from pdfobject.
I added a rough implementation of this to my fork. You can see it in action here. A few notes, in case they might be useful to someone down the line:
Basically, I added a new member, fallbackPrefix
, to the options that can be passed to the embed
function. The prefix could be e.g. https://docs.google.com/viewer?embedded=true&url=
.
If fallbackPrefix
is set, it supersedes fallbackLink
:
const fallbackPrefix = opt.fallbackPrefix || ''
const fallbackLink = fallbackPrefix
? false
: typeof opt.fallbackLink === 'string' ||
typeof opt.fallbackLink === 'boolean'
? opt.fallbackLink
: true
Then embed
can call the markup generation function, with fallbackPrefix
prepended to the url
:
if (fallbackPrefix) {
const embedType = 'fallback'
return generatePDFoMarkup(
embedType,
targetNode,
targetSelector,
fallbackPrefix + url,
pdfOpenFragment,
width,
height,
id,
title,
omitInlineStyles
)
}
Finally, when generating markup, we just have to make sure to create an iframe with the correct src
attribute:
if (embedType === 'iframe' || embedType === 'fallback') {
embed = document.createElement('iframe')
embed.allow = 'fullscreen'
} else {
embed = document.createElement('embed')
embed.type = 'application/pdf'
}
embed.src = embedType === 'fallback' ? url : url + pdfOpenFragment
from pdfobject.
Related Issues (20)
- PDFObject Not Show and Only show Root File HOT 2
- Eraser HOT 1
- PDFObject save button option HOT 1
- Disabled download and print button HOT 1
- [Documentation] Standalone examples of .html files + PDFObject? HOT 3
- Remove some buttons and only show one page at a time HOT 1
- Render html elements within "the full-browser embed" HOT 1
- Fails to load in IE11 HOT 8
- Is there a way to track button clicks? HOT 2
- Navigator.pdfViewerEnabled support? HOT 8
- PDFObject: Page option not working in Microsoft Edge HOT 2
- The problem occurred when using PDFObject in React: Page A embedded with duplicate Page A. HOT 3
- Cannot set properties of undefined HOT 1
- Prevent download pdf automatically HOT 1
- PDFObject is vulnerable to PDFInjection HOT 4
- XSS in fallback link if url is controllable by attacker HOT 5
- base64 PDF how to set title? HOT 1
- Sign PDF with digital certificate HOT 1
- change default download file name HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdfobject.