<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PDF Viewer</title>
	<script src="../js/util.js"></script>
</head>
<body>
    <iframe id="pdfViewer" width="100%" height="100%">
        Your browser does not support iframes.
    </iframe>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.min.js"></script>
    <script>
		loadPdf()
		
		async function loadPdf(){
			const pdfUrl =  'http://192.168.3.37:8036'+'/' + gemhoUtil.getParameter('pdfSrc'); // Replace with your PDF URL
			
			const iframe = document.getElementById('pdfViewer');
			const iframeDoc = iframe.contentDocument;
			
			iframeDoc.open();
			iframeDoc.write('<style>body, html { margin: 0; padding: 0; }</style>');
			iframeDoc.write('<style>.pdfViewer { width: 100%; height: 100vh; }</style>');
			iframeDoc.write('<div class="pdfViewer"></div>');
			iframeDoc.close();
			
			const pdfContainer = iframeDoc.querySelector('.pdfViewer');
			
			// 线上文件获取流
			  const response = await fetch(pdfUrl, { method: 'GET' });
			const pdfBlob = await response.blob();
			      // 加载 PDF 文件
			      const pdfData = new Uint8Array(await pdfBlob.arrayBuffer());
			
			
			pdfjsLib.getDocument(pdfData).promise.then((pdf) => {
			// pdfjsLib.getDocument(pdfUrl).promise.then((pdf) => {
			    pdf.getPage(1).then((page) => {
			        const scale = 1.5;
			        const viewport = page.getViewport({ scale: scale });
			
			        const canvas = document.createElement('canvas');
			        const context = canvas.getContext('2d');
			
			        canvas.height = viewport.height;
			        canvas.width = viewport.width;
			
			        page.render({ canvasContext: context, viewport: viewport });
			        pdfContainer.appendChild(canvas);
			    });
			});
		}
       
    </script>
</body>
</html>
