<html>
<title>Print.App Custom integration sample</title>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1, shrink-to-fit=no">
<style>
#launch-button {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
}
#previews-div {
margin-top: 20px;
}
#previews-div img {
width: 100%;
max-width: 400px;
margin-bottom: 20px;
}
</style>
<script src="https://editor.print.app/js/client.js"></script>
</head>
<body>
<button id="launch-button" class="launch-button">Launch Designer</button>
<div id="previews-div"></div>
</body>
<script>
(function() {
//Get handles to the UI elements we'll be using
const launchButton = document.getElementById('launch-button'),
previewDiv = document.getElementById('previews-div');
//Disable the Launch button until Print.App is ready for use
launchButton.setAttribute('disabled', 'disabled');
// Initialize Print.App
// Kindly read more here on the options.. https://docs.print.app
var printAppInstance = new PrintAppClient({
domainKey: '', //Kinldy provide your own APIKey
designId: '', //Change this to your designId
custom: true,
mode: 'new-project',
});
//Function to run once the app is validated (ready to be used)
var appReady = () => {
console.log('editor is ready');
// Enable the Launch button
launchButton.removeAttribute('disabled');
// Attach event listener to the button when clicked to show the app
launchButton.onclick = () => printAppInstance.showApp();
};
// Function to run once the user has saved their project
var projectSaved = (value) => {
// You can console.log the data varaible to see all that's passed down
let { data } = value;
if (data && data.previews && data.previews.length) {
// Show the preview images
let html = '';
for (let i = 0; i < data.previews.length; i++) {
html += `<img src="${data.previews[i]}">`;
}
previewDiv.innerHTML = html;
}
};
// Attach events to the app.
// You can see a list of all the events here: https://docs.print.app
printAppInstance.addEventListener('app:ready', appReady);
printAppInstance.addEventListener('app:saved', projectSaved);
})();
</script>
</html>