I'm trying to load a pdf from external server and now I'm getting this error in console.
XMLHttpRequest cannot load https://mobile.switchitapp.com/uploads/pdf/userGuide.pdf. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://appsdata2.cloudapp.net' is therefore not allowed access.
How to get rid of this error? I have tried a lot but nothing has worked for me till now please help me out
thanks :)
here is my code
<!DOCTYPE html>
<html>
<head>
<title>PDF.js Learning</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/1.8.472/pdf.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdf.js/1.8.472/pdf.worker.js"></script>
<script>
// URL of PDF document
var url = "https://mobile.switchitapp.com/uploads/pdf/userGuide.pdf";
// Asynchronous download PDF
PDFJS.getDocument(url)
.then(function(pdf) {
return pdf.getPage(1);
})
.then(function(page) {
// Set scale (zoom) level
var scale = 1.5;
// Get viewport (dimensions)
var viewport = page.getViewport(scale);
// Get canvas#the-canvas
var canvas = document.getElementById('the-canvas');
// Fetch canvas' 2d context
var context = canvas.getContext('2d');
// Set dimensions to Canvas
canvas.height = viewport.height;
canvas.width = viewport.width;
// Prepare object needed by render method
var renderContext = {
canvasContext: context,
viewport: viewport
};
// Render PDF page
page.render(renderContext);
});
</script>
</head>
<body>
<canvas id="the-canvas"></canvas>
</body>
</html>