react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

Adding Form Annotation support

Open axel7083 opened this issue 2 years ago • 1 comments

Since pdfkit support Form Annotation I added the logic to support them in react-pdf. I've never contributed to this project, so I am not aware if I was suppose to add this feature in the way I did. I also added the types support for TS.

See issue https://github.com/diegomura/react-pdf/issues/42

Here is an example

<Document>
    <Page>
      <View style={{backgroundColor: 'rgba(182,28,28,0.62)', width: '30%', height: '100%'}}>
          <Form>
              <FormField name="user-info" style={{flexDirection: 'column'}}>
                  <Text>FormText</Text>
                  <FormText name={'name'} value={"hello"} align={'center'} style={{height: '50px'}} password />

                  <Text>FormCombo</Text>
                  <FormCombo
                      name={'combo'}
                      select={['', 'option 1', 'option 2']}
                      value={''}
                      defaultValue={''}
                      style={{height: '20px'}}
                  />

                  <Text>FormList</Text>
                  <FormList name={'list'} select={['', 'option 1', 'option 2']} value={''} defaultValue={''} style={{height: '50px'}}/>

                  <Text>FormPushButton</Text>
                  <FormPushButton name={'bouton'} label={'push button'} style={{height: '50px'}}/>
              </FormField>
          </Form>
      </View>
    </Page>
  </Document>

And the result example.pdf

axel7083 avatar Sep 08 '22 21:09 axel7083

I just started looking into React-PDF today and was hoping they would add form support. Your timing is impeccable.

jamesmfriedman avatar Sep 09 '22 20:09 jamesmfriedman

Hi, any chance of this being fixed up & merged in the near future? Been using react-pdf at work and we're looking to add some form stuff to our PDFs. I'm down to contribute and help get this out the door if necessary!

Ovyerus avatar May 16 '23 02:05 Ovyerus

Hello @Ovyerus sadly I do not have much time to spend on side project currently, but I would be accepting contributions!

axel7083 avatar May 16 '23 06:05 axel7083

Sounds good!

Ovyerus avatar May 16 '23 08:05 Ovyerus

Would love to have this feature as well !

mdefeche avatar Jun 05 '23 12:06 mdefeche

@diegomura Any ETA on this. Would love this feature!

majid701 avatar Jun 13 '23 07:06 majid701

@axel7083 @diegomura Hi, I'll try to do some work on this onwards. I have a WIP with the latest changes and @axel7083 's commits, and have started implementing some of your proposed changes @diegomura . Should I open a new PR here for this when I'm closer to done, or is it better that I make a PR against the fork?

runelk avatar Jun 13 '23 18:06 runelk

@axel7083 @diegomura Hi, I'll try to do some work on this onwards. I have a WIP with the latest changes and @axel7083 's commits, and have started implementing some of your proposed changes @diegomura . Should I open a new PR here for this when I'm closer to done, or is it better that I make a PR against the fork?

If you make a PR against the fork I can quickly review it to commit it here.

axel7083 avatar Jun 13 '23 19:06 axel7083

Its there documentation about form elements?

joneldiablo avatar Jan 07 '24 00:01 joneldiablo

Any update on this? Or maybe someone could publish a fork while this is waiting to be merged? I would but I'm not familiar with the packaging/publishing process on a library like this.

kjossendal avatar Mar 11 '24 00:03 kjossendal

Is it acceptable, when using <Form /> the way this pr does, to just ignore it's initialization if it has already been initialized? Otherwise I'm not sure where it would be done globally. For example, the below prevents broken rendering issues from misuse in pdfkit/src/mixins/acroform.js. The problem is that, with this pr implementation, <Form /> can only be used once but it cannot wrap several pages the way it is rendered. So this bypasses having to change the renderNode method.

 initForm() {
    if (this._root.data.AcroForm) {                     <------------ Add this block
      // Form is already initialized
      return this;
    }
    if (!this._font) {
      throw new Error('Must set a font before calling initForm method');
    }
    this._acroform = {
      fonts: {},
      defaultFont: this._font.name
    };
    this._acroform.fonts[this._font.id] = this._font.ref();
   ...rest of method

Edit: Sorry, not sure how to format json... Edit: Figured it out

kjossendal avatar Mar 15 '24 00:03 kjossendal

Hi 👋 any update on this? Unfortunately I can't work on this myself at the moment, but maybe one of the community has the time and skills to do this. Thank you all!

natterstefan avatar Jul 11 '24 13:07 natterstefan

Hi 👋 any update on this? Unfortunately I can't work on this myself at the moment, but maybe one of the community has the time and skills to do this. Thank you all!

Hey, sadly I do not have time to look at this PR, which is almost 2 years old. I will close it. Everyone is welcome to take the code I wrote.

axel7083 avatar Jul 11 '24 14:07 axel7083