質問

For an intranet application, in which very confidential documents are transferred AES256-encrypted, pdf data sources are available as base64-strings (given the fact they are decrypted first). For testing purposes I read a pdf from server http://ddlab.de/stackoverflow/pdf.js/1/test.pdf

Here´s index.html: http://ddlab.de/stackoverflow/pdf.js/1/index.html

In viewer.js I can set

var DEFAULT_URL = 'test.pdf'; // giving a local or crossdomain path to pdf

My idea is, to set a base64 string as default source like

var DEFAULT_URL = 'data:application/pdf;base64,JVBERi0...GCg=='; // shortened

(which also works in FF)

For this I wrote a small php script, that delivers the base64 encoded string. http://ddlab.de/stackoverflow/pdf.js/1/readfile.php

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
ob_start('ob_gzhandler');
header('Content-Type: text/javascript; charset=utf-8');
$file = 'test.pdf';
$mime = mime_content_type ($file);
$data = base64_encode(file_get_contents($file));
$url = 'data:' . $mime . ';base64,' . $data;
echo '/*read pdf and output the base64 code*/' . "\n\n";
echo 'var pdf_src = "' . $url . '";';
ob_end_flush();
?>

This is added to HEAD as

<script type="text/javascript" src="readfile.php"></script>

So, finally I can use

var DEFAULT_URL = pdf_src; // retrieving the base64-string as URL

in viewer.js

This works totally great in FF, but in Safari and Chrome ? Nope.

Can somebody help me with this issue ?

役に立ちましたか?

解決

PDFView.open call accepts typed array. Copy "Base64 / binary data / UTF-8 strings utilities" from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding and decode base64 content using base64DecToArr function. You are already modifying the viewer, so adding couple of functions shall not be a problem.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top