Skip to main content
Best answer

PDF Monkey integration problem with line breaks


I wanted to create a nicely formatted PDF document out of Typeform answers. For that PDFMonkey seemed pretty nice.

Unfortunately I hit a problem with multi line (long_text) answers in PDF. They get sent to PDFmonkey with a line break which causes PDFMonkey to complain that json in unprocessable.
This is strange, especially as when you ask typeform api directly it returns json with stripped new line characters.
I could of course reformat every longform answer using formatter, but as my forms are very long, it would be a very tiresome task.
Do I feel correctly that this is kind of a bug in zapier/pdfmonkey integration? Is there some other workaround I don’t see? 

Best answer by PDFMonkeyBest answer by PDFMonkey

Hi everyone,

 

After using this code in prod I noticed a small issue with the quotes escaping, here is the correct version of the code: (the diff is the triple backslash near the end of the replace line)

let data = Object.assign({}, inputData);

for (let key in data) {
  if (typeof(data[key]) === "string" && data[key].length > 0) {
    data[key] = data[key].replace(/\r?\n/g, "<br>").replace(/\t/g, " ").replace(/"/g, '\\\"');
  }
}

output = [data];

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

10 replies

steph.n
Forum|alt.badge.img+8
  • Builder
  • 899 replies
  • April 7, 2020

Hi there @natucate - Thanks for writing to us! I’m escalating your report to Support. We would like to investigate the matter a little more deeply.

Thanks and stay tuned!


steph.n
Forum|alt.badge.img+8
  • Builder
  • 899 replies
  • April 9, 2020

Hi there @natucate - We sent you a message about two days ago in hopes to obtain more information from you to help troubleshoot this. Could you reply to the message from Edcel if you’re still experiencing troubles with this? Thanks!


nicksimard
Forum|alt.badge.img+11
  • Zapier Staff
  • 2115 replies
  • June 9, 2020

Hi @natucate!

I wanted to check in with you on this one, since I don’t see a response to the message that our Support team had sent you. Did you still need help here or did their reply to you help you resolve things? Please let us know :)


PDFMonkey
Forum|alt.badge.img
  • New
  • 8 replies
  • June 10, 2020

Hi there!

The line-break issue is very frequent as JSON doesn’t support it. You can clean the data before building your payload using a Code by Zapier step and use the following JS script:

let data = Object.assign({}, inputData);

for (let key in data) {
  if (typeof(data[key]) === "string" && data[key].length > 0) {
    data[key] = data[key].replace(/\r?\n/g, "<br>").replace(/\t/g, " ").replace(/"/g, '\"');
  }
}

output = [data];

This will clean any input data you send to the script. It will replace line-breaks with HTML line breaks that PDFMonkey will understand and will also replace any tab or quote character to prevent breaking the JSON payload.

Cheers!


nicksimard
Forum|alt.badge.img+11
  • Zapier Staff
  • 2115 replies
  • June 11, 2020

@PDFMonkey Thanks so much for chiming in here — very much appreciated :)


PDFMonkey
Forum|alt.badge.img
  • New
  • 8 replies
  • Answer
  • August 17, 2020

Hi everyone,

 

After using this code in prod I noticed a small issue with the quotes escaping, here is the correct version of the code: (the diff is the triple backslash near the end of the replace line)

let data = Object.assign({}, inputData);

for (let key in data) {
  if (typeof(data[key]) === "string" && data[key].length > 0) {
    data[key] = data[key].replace(/\r?\n/g, "<br>").replace(/\t/g, " ").replace(/"/g, '\\\"');
  }
}

output = [data];

 


  • New
  • 2 replies
  • March 9, 2021

Hi @PDFMonkey

I’ve ran into the same issue while using Zapier and Ninja Forms. Whenever I use a textarea field and someone adds line breaks the responses don’t flow into PDFMonkey. I tried the Code you’ve given above but it doesn’t work in my case. Do you know how I could adjust it for Ninja Forms?


  • New
  • 2 replies
  • March 10, 2021

Actually, @PDFMonkey I’ve just figured out how to implement the code you’ve given correctly and it works great. Thanks!

 

Do you know how I would adjust so that the code can fix multiple textarea responses in one zapier task?


PDFMonkey
Forum|alt.badge.img
  • New
  • 8 replies
  • January 23, 2022

Hi @cfi_web, I’m sorry I didn’t see your message 10 months back. I hope since then you found out that the code can be set in a single task that can take multiple items as input.

A Code task takes an initial input mapping where you can set the name to use on the left side and the content to clean on the right. You can then pass the cleaned up content to PDFMonkey while only introducing a single extra task.

Also know that since then we have released a new version of the integration that simplifies things a lot by allowing to provide your data as a simple key/value mapping and not needing to write JSON. It eliminates this line-break issue completely when you use it 😊


christina.d
Forum|alt.badge.img+9
  • Zapier Staff
  • 2653 replies
  • January 25, 2022

Thanks for the follow-up and insight here, @PDFMonkey! 🎉