Created
December 20, 2022 12:04
-
-
Save earlgreyxxx/a62e8b5aabb09268c8a11a794e2c1729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ロード | |
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