How to pdf input field act as an input field using pdf js

Viewed 1665

From a pdf file if there are input fields to act as an input field I try to use pdf js. But I am not able to do that.

So here's an example of what I'm trying to get at:

const canvas = document.getElementById(`canvas-${this.pageNumber}`);

      const context = canvas.getContext("2d");
      const dis = this;
      this.fabricObj = fabric;

      const scale = this.scale;
      const viewport = page.getViewport(scale);
      canvas.height = viewport.height;
      canvas.width = viewport.width;

      var formFields = {};

      page.render({
          canvasContext: context,
          viewport
        })
        .promise.then(() => {})

Is it possible to act as a pdf input field as an input field?

1 Answers

You cannot render pdf from canvas and have editable inputs in the pdf you generated. What you want is partially covered in relation to rendering interactive forms and AcroForms. Check the AcroForms example and renderInteractiveForms flag in the pdf.js API docs.

AcroForms example: https://github.com/mozilla/pdf.js/tree/master/examples/acroforms

Related