question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fill PDF with dynamic data from a form

See original GitHub issue

I have a form and I wish to have a print button that renders the data that is on the form into a PDF. If I make a change to a field, and click the print button again, I want that new data to be on the PDF.

So far, I have been able to use a BlobProvider component to create the PDF but getting dynamic data from the form to the PDF is proving to be quite difficult and unusual.

After many different approaches, this is the closest I have come…

<BlobProvider document={this.OrderPDF()}>
     {({ url }) => (
          <a href={url} target="_blank">Print</a>
     )}
</BlobProvider>
OrderPDF = () => {

      var { form } = this.props;
      var note = form.getFieldValue('note');

      return (

          <Document title="Order">

            <Page size="A4" style={styles.page}>

              <View style={styles.section}>
                {Header}
              </View>

              <View style={styles.section}>
                <Text>{note}</Text>

              </View>

              <View style={styles.section}>
                <Text style={styles.body}>Section #2</Text>
              </View>

              <View style={[styles.section, { bottom: 1 }]}>
                {Footer}
              </View>

            </Page>

          </Document>

      )

  }

Here’s the unusual part…

When I first load the page, whether there is data in the note field or not, the first time I click on the Print button, the PDF shows nothing for the note. Then if I make any change to the note field (ie. clear some characters), then print the PDF again, it shows the correct data, but only for the first change I made.

So for example…

  1. Load page with note field as: Hello
  2. Click print: Nothing rendered for {note} on the PDF
  3. Change note field to Hell
  4. Click print: Hell is displayed on PDF
  5. Change note field back to Hello
  6. Click print: Hell is displayed on PDF

At first I was thinking that the reason is because the PDF is only being rendered once upon load, so that’s why I moved it into a function to try to get it to render new values each time I click Print, but it seems to be rendering only twice…once upon load, then a second time when I click the print button, and then every time after that it always just shows the PDF from the second time it rendered.

Why is this happening and is there anyway I can retrieve the new values each time I click Print?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
bkoltaicommented, Oct 2, 2018

I recently had that error and there is a fix pending release for it. You may be getting it when testing is an empty string. Try handling the empty string case explicitly in your Text component and render null instead when empty

<Text>{texting === “” ? null : testing}</Text>
1reaction
diegomuracommented, Oct 2, 2018

Fix is going to be published soon 😊

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically fill out PDF from database | Adobe Acrobat
What I would like to do is pre-populate all of these fields in the PDFs with values from a database and have the...
Read more >
Pre-filling and merging PDF forms with dynamic survey data
Method 1: Pre-fill Forms​​ If you would like to customize and dynamically generate each form to pre-fill certain fields in your survey, you...
Read more >
Form Filling - DynamicPDF
As PDF documents are created, DynamicPDF supports merging form field values using acro form field values, reorganized acro form fields, and FDF files....
Read more >
How to fill in PDF forms in Adobe Acrobat or Reader
To allow Reader users to save the data they typed, choose File > Save As Other > Reader Extended PDF > Enable More...
Read more >
Create Dynamic PDF Forms with Simple Drag-and-Drop - frevvo
Using our wizards, connectors, and API, you can map the dynamic form controls to fields in your PDF and frevvo will automatically map...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found