HD

PDF Object 본문

javascript/PDF.JS

PDF Object

hunecenter 2019. 11. 18. 11:16
반응형

이전 mozilla PDF.js를 사용한 PDF VIEWER를 포스팅 해봤었다.

 

그런데 mozilla PDF외에 PDF Object를 발견해 한번 적용연습을 해봤다.

 

 

※예제 참고

https://pdfobject.com/#api

 

PDFObject: A JavaScript utility for embedding PDFs

width [string]. Default: "100%" Will insert the width as an inline style via the style attribute on the element. If left unspecified, PDFObject will default to 100%. Is standard CSS, supports all units, including px, %, em, and rem. Tip: It's safer to spec

pdfobject.com

 


script

pdfobject.min.js 필수

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<style>
	/*
	PDFObject appends the classname "pdfobject-container" to the target element.
	This enables you to style the element differently depending on whether the embed was successful.
	In this example, a successful embed will result in a large box.
	A failed embed will not have dimensions specified, so you don't see an oddly large empty box.
	*/
	
	.pdfobject-container {
		width: 100%;
		max-width: 100%;
		height: 100%;
	}
</style>

<script src="/Web-home/pdfobject.min.js"></script>


<script>
	$(document).ready(function () {
		 var options = {
			pdfOpenParams: {
				navpanes: 0,
				toolbar: 0,
				statusbar: 0,
				view: "FitV",
				pagemode: "",
				page: 1
			}
			,forcePDFJS: true
            //[PDFJS_URL]mozila PDF viewer.html 
            //https://mozilla.github.io/pdf.js/getting_started/#download 참고
			,PDFJS_URL:"/Web-home/pdfjs/web/viewer.html"
		};
		var myPDF = PDFObject.embed("해당 pdf 경로", "#pdfContent", options);
		console.log("myPDF : "+myPDF);
		var el = document.querySelector("#results");
		el.setAttribute("class", (myPDF) ? "success" : "fail");
		el.innerHTML = (myPDF) ? "PDFObject was successful!" : "Uh-oh, the embed didn't work.";
	});
</script>

pdfobject.min.js
0.00MB
pdfjs-2.2.228-dist.zip
4.01MB

※참고

 

Getting Started

Getting Started An introduction to PDF.js with examples. Introduction Before downloading PDF.js please take a moment to understand the different layers of the PDF.js project. Layer About Core The core layer is where a binary PDF is parsed and interpreted.

mozilla.github.io


HTML

 

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>

<div class="application" style="height:80%"> 
  	<div id="results" class="hidden"></div>
	<div id="pdfContent" style="height:100%"></div>
</div>

 

 

※코드 생성기도 제공하니 참고

Code Generator

 

PDFObject: Code Generator

Optional PDF Open Parameters PDF Open parameters allow you to customize the way a PDF file opens in Adobe Reader. You can show/hide toolbars, specify a page number, change the display size, and more. Read Adobe's specifications to learn more. These paramet

pdfobject.com

 


UI

 

반응형

'javascript > PDF.JS' 카테고리의 다른 글

mozilla PDF.js  (1) 2019.08.08
Comments