Best answer

PDF Monkey integration problem with line breaks


Userlevel 1

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? 

icon

Best answer by PDFMonkey 17 August 2020, 12:19

View original

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

Userlevel 7
Badge +9

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

Userlevel 2
Badge

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 😊

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?

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?

Userlevel 2
Badge

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];

 

Userlevel 7
Badge +11

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

Userlevel 2
Badge

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!

Userlevel 7
Badge +11

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 :)

Userlevel 7
Badge +8

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!

Userlevel 7
Badge +8

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!