<!DOCTYPE HTML>
<html lang="de" style="padding:0; margin:0;">
<head>
    <meta charset="utf-8" />
    
    <meta name="application-name" content="untermStrich" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <title>PDF - {$i.basic_title}</title>

    <link rel="shortcut icon" href="{site_url url="favicon.ico"}" type="image/x-icon" id="shortcut_ico" />
    
    <script type="text/javascript" src="{site_url url="$js_path/page_centric/pdf__{$us_version_ue}.js"}"></script>
</head>
<body style="padding:0; margin:0;">
    <canvas id="the-canvas" style="padding:0; margin:0; background:transparent;"></canvas>
    <script type="text/javascript">
    /* <![CDATA[ */
        (function () {
            let canvas = document.getElementById('the-canvas');
            let context = canvas.getContext('2d');
            canvas.height = 70;
            canvas.width = 350;
            context.font = '20px "Open Sans",Arial,Helvetica,sans-serif';
            context.fillText("{$i.basic_loading}", 30, 50);
    
            pdfjsLib.GlobalWorkerOptions.workerSrc = '{site_url url="$js_path/page_centric/pdf.worker__{$us_version_ue}.js"}';

            var loadingTask = pdfjsLib.getDocument('{$pdf_url}');
            loadingTask.promise.then(pdf => {
                pdf.getPage(1).then(page => {
                    let scale = {$pdf_size};
                    let viewport = page.getViewport({ scale: scale, });

                    canvas.height = viewport.height;
                    canvas.width = viewport.width;

                    let renderContext = {
                        canvasContext: context,
                        viewport: viewport,
                    };
                    page.render(renderContext);
                }).catch(e => {
                    context.clearRect(0, 0, canvas.width, canvas.height);
                    context.fillText('Error loading page', 30, 40);
                    context.font = '16px "Open Sans",Arial,Helvetica,sans-serif';
                    context.fillText('Cannot open page 1', 30, 65);
                    write_error(e);
                });
            }).catch(e => {
                context.clearRect(0, 0, canvas.width, canvas.height);
                context.fillText('Error loading pdf', 30, 40);
                context.font = '16px "Open Sans",Arial,Helvetica,sans-serif';
                context.fillText('Cannot load file via the server', 30, 65);
                write_error(e);
            });
            
            function write_error(e) {
                let newText = document.createElement('div');
                newText.style.padding = '30px';
                newText.style.fontSize = '10px';
                newText.style.wordWrap = 'break-word';
                var newTextNode = document.createTextNode(e);
                newText.appendChild(newTextNode);
                canvas.parentNode.insertBefore(newText, canvas.nextSibling );
            }
        })();
    /* ]]> */
    </script>
</body>
</html>
