0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PDF.jsでPDF->画像変換した時にPDF内のテキストが欠損してしまう時の対処法

Posted at

こちらの症状は cMap という 「フォントが持つそれぞれの文字と、文字コードを結びつけるための対応表」 の情報をオプションに追加することで表示できるようになりました。

解決方法

pdfjs の getDocument() メソッドの引数オプションにcMapUrlを追記することで解決します。

import * as pdfjs from 'pdfjs-dist';

const pdfData = await file.arrayBuffer();
const pdf = await pdfjs.getDocument({
	data: pdfData,
    // 👇 今回追加した部分
+	cMapUrl: `https://unpkg.com/pdfjs-dist@${pdfjs.version}/cmaps/`,
+	cMapPacked: true,
}).promise;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?