Skip to content

Instantly share code, notes, and snippets.

@earlgreyxxx
Created December 20, 2022 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earlgreyxxx/a62e8b5aabb09268c8a11a794e2c1729 to your computer and use it in GitHub Desktop.
Save earlgreyxxx/a62e8b5aabb09268c8a11a794e2c1729 to your computer and use it in GitHub Desktop.
// ロード
import pdf2img from './pdf2img.js';
(($) => {
// PDFファイル選択
// --------------------------------------------------------------------------
async function onChangeFile(ev)
{
if(this.files.length <= 0)
return;
$('#image').empty();
const pdfFile = this.files[0];
// Fileオブジェクトと適当な解像度を引数として渡すと
// 画像ファイル(Fileオブジェクト)として返る。
const image = await pdf2img(pdfFile,144);
// img要素を生成してDOMツリーに追加
const $img = $('<img>').appendTo('#image');
//PDFファイルから変換した画像ファイルオブジェクトを設定して表示
$img.attr('src',URL.createObjectURL(image));
// クリア
this.value = '';
}
//初期化
$('#pdf-file').change(onChangeFile);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment