'Display a pdf in a viewer on a browser after clicking on a link (html)
Clicking on an html link such as <a href="Example.pdf">Example</a> downloads the Example.pdf. Alternatively, the pdf can be permanently embedded into a viewer with a code such as <object data="Example.pdf" type="application/pdf" title="Example" width="500" height="720"> <a href="Example.pdf">Example</a>. However, I would rather prefer that the pdf is neither downloaded from the link, nor permanently embedded and always viewable but that one must click on a link (coded in html) to view it. Is there a way to do that?
Solution 1:[1]
With this code, you can show a PDF:
<embed src="Example.pdf" width="500" height="720" type="application/pdf">
Then with JS you can show or hide this tag.
With Google Chrome or Android use this code:
<embed src="https://drive.google.com/viewerng/
viewer?embedded=true&url=http://example.pdf" width="500" height="720">
UPDATE: First introduce an ID in your tag:
<embed id="pdf_view" src="https://drive.google.com/viewerng/
viewer?embedded=true&url=http://example.pdf" width="500" height="720">
Then, in your HTML create a button or in your href put an onClick.
<a href="Example.pdf" onClick="showPdf()">Example</a>
Later create a function in JS
<script>
function showPdf() {
$("#pdf_view").show();
}
</script>
If you want to hide use:
$("#pdf_view").hide();
FOR DOWNLOAD PDF
<a href="AgustínTamayo_CV.pdf" class="btn btn-primary py-3 px-3" download="AgustínTamayo_CV.pdf">Download my CV</a>
FOR SEE IN THE SAME PAGE
<a href="AgustínTamayo_CV.pdf" class="btn btn-primary py-3 px-3">See my CV</a>
FOR SEE IN OTHER PAGE
<a href="AgustínTamayo_CV.pdf" class="btn btn-primary py-3 px-3" target="_blank">See my CV in other page</a>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
