1.1.0

Constructor Options

Last updated


This page lists every new pdf2image(options) option with its default and normalization rule.

Signature


  1. new pdf2image(options?: {
  2. file?: ArrayBuffer;
  3. filename?: string;
  4. scale?: number;
  5. type?: "png" | "jpg" | "webp";
  6. })

The constructor only stores options; it reads no file and makes no network request.

Options


OptionTypeDefaultNormalizationDescription
fileArrayBufferundefinedNoneRaw PDF data; pdf.js transfers it during conversion, which invalidates it (see Conversion)
filenamestring""trim(), then the first .pdf is removedBase name for the ZIP and images; accepts yyyy / MM / DD / hh / mm (see ZIP Download)
scalenumber1.5Falsy values (including 0) fall back to 1.5pdf.js viewport scale; output pixels = page pt × scale
typestring"jpg"Anything other than png / jpg / webp falls back to "jpg"Output format; "jpg" actually produces PNG (see Conversion)

Normalization Examples


  1. <script>
  2. const size = src => new Promise(r => {
  3. const img = new Image();
  4. img.onload = () => r(img.width + "x" + img.height);
  5. img.src = src;
  6. });
  7. addEventListener("load", async () => {
  8. const options = [{}, { scale: 0 }, { type: "gif" }, { type: "PNG" }];
  9. for (const extra of options) {
  10. const buffer = await (await fetch("/assets/sample.pdf")).arrayBuffer();
  11. const [first] = await new pdf2image({ file: buffer, ...extra }).convert();
  12. console.log(JSON.stringify(extra), "->", first.slice(5, first.indexOf(";")), await size(first));
  13. }
  14. });
  15. </script>
Live preview · @pardnchiu/pdf2image@1.1.2

type matching is case-sensitive, so "PNG" also falls back to "jpg".
filename must be a string or omitted: the constructor calls .trim() on it directly, so a truthy non-string value (such as 123) throws a TypeError at new pdf2image().

中文