|
|
@@ -2,6 +2,10 @@ |
|
|
|
import React, { useEffect, useRef, useState } from 'react'; |
|
|
|
// import './App.css'; // For basic styling |
|
|
|
import axios from 'axios'; |
|
|
|
import {apiPath} from "../../auth/utils"; |
|
|
|
import { |
|
|
|
GET_PDF_PATH |
|
|
|
} from "../../utils/ApiPathConst"; |
|
|
|
|
|
|
|
// Import your chosen commercial PDF SDK (e.g., PSPDFKit) |
|
|
|
import PSPDFKit from 'pspdfkit'; |
|
|
@@ -10,28 +14,48 @@ function PDF() { |
|
|
|
const viewerRef = useRef(null); // Ref for the DOM element where PDF will render |
|
|
|
const instanceRef = useRef(null); // Ref for the PSPDFKit instance |
|
|
|
const [pdfLoaded, setPdfLoaded] = useState(false); |
|
|
|
const [template,setTemplate] = useState(); |
|
|
|
const [viewInstance,setViewInstance] = useState(); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
const loadPdfViewer = async () => { |
|
|
|
if (viewerRef.current) { |
|
|
|
if (document.getElementById(viewerRef)) { |
|
|
|
// if (viewerRef.current) { |
|
|
|
try { |
|
|
|
// 1. Fetch the blank PDF template from your Spring Boot backend |
|
|
|
const response = await axios.get('http://localhost:8090/api/pdf/template', { |
|
|
|
responseType: 'arraybuffer' // Essential for binary data |
|
|
|
//New try |
|
|
|
axios.get(`${apiPath}${GET_PDF_PATH}`, { |
|
|
|
responseType: 'arraybuffer', // Essential for binary data |
|
|
|
}) |
|
|
|
.then((response) => { |
|
|
|
if (response.status === 200) { |
|
|
|
setTemplate(response); |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch(error => { |
|
|
|
console.log(error); |
|
|
|
return false; |
|
|
|
}); |
|
|
|
const pdfBlob = new Blob([response.data], { type: 'application/pdf' }); |
|
|
|
// 1. Fetch the blank PDF template from your Spring Boot backend |
|
|
|
// const response = await axios.get(`${apiPath}${GET_PDF_PATH}`, { |
|
|
|
// responseType: 'arraybuffer', // Essential for binary data |
|
|
|
// }); |
|
|
|
const pdfBlob = new Blob(template, { type: 'application/pdf' }); |
|
|
|
const pdfUrl = URL.createObjectURL(pdfBlob); |
|
|
|
|
|
|
|
// 2. Initialize the PDF SDK (e.g., PSPDFKit) |
|
|
|
console.log(template); |
|
|
|
|
|
|
|
const instance = await PSPDFKit.load({ |
|
|
|
container: viewerRef.current, |
|
|
|
// setViewInstance(await PSPDFKit.load({ |
|
|
|
container: document.getElementById(viewerRef),//viewerRef.current, |
|
|
|
document: pdfUrl, |
|
|
|
// Remember to add your SDK license key if applicable |
|
|
|
// licenseKey: "YOUR_PSPDFKIT_LICENSE_KEY", |
|
|
|
baseUrl: process.env.PUBLIC_URL + '/pspdfkit-lib/', // Path to SDK assets |
|
|
|
baseUrl: `${process.env.PUBLIC_URL}/pspdfkit-lib/`//, // Path to SDK assets |
|
|
|
// Enable form filling UI |
|
|
|
formDesignerViewMode: PSPDFKit.FormDesignerViewMode.Enabled |
|
|
|
// formDesignerViewMode: PSPDFKit.FormDesignerViewMode.Enabled |
|
|
|
}); |
|
|
|
// })); |
|
|
|
|
|
|
|
instanceRef.current = instance; |
|
|
|
setPdfLoaded(true); |
|
|
@@ -104,7 +128,7 @@ function PDF() { |
|
|
|
)} |
|
|
|
</header> |
|
|
|
<div |
|
|
|
ref={viewerRef} |
|
|
|
id={viewerRef} |
|
|
|
className="pdf-viewer-container" |
|
|
|
style={{ |
|
|
|
width: '100%', |
|
|
|