Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using pdf.js implement pdf to image and support for non-latin characters
<canvas id="the-canvas" style="border:1px solid black"></canvas>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
var pdfurl = "~/Content/js/Attachments/File/d1553218164017cb9d87df-f88a-467a-8dcd-1c8d32a13975.pdf";//Replace it with your url of pdf resource
var pdfjsLib = window['pdfjs-dist/build/pdf'];
pdfjsLib.GlobalWorkerOptions.workerSrc = '';
var loadingTask = pdfjsLib.getDocument({url:pdfurl,
cMapUrl: '' , // use cdn load cmaps。
cMapPacked: true, // must set true
loadingTask.promise.then(function(pdf) {
console.log('PDF loaded');
pdf.getPage(1).then(function(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
// Prepare canvas using PDF page dimensions
var canvas = document.getElementById('the-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
// Render PDF page into canvas context
var task = page.render({canvasContext: context, viewport: viewport})
}, function(error){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.