Describe the issue/error/question
I am trying to save to PDF the body of an email. I have thought to use the field HTML from IMAP node to convert to PDF but I haven’t found the way to do it.
Do someone some idea about how can I do it?
Any help will be welcome.
Thank you very much for your time and patient!
BR!
Please share the workflow
Information on your n8n setup
- **n8n version:**0.182.0
- Database you’re using (default: SQLite): N/A
- **Running n8n with the execution process [own(default), main]:**own
- **Running n8n via [Docker, npm, n8n.cloud, desktop app]:**desktop app
Hi @franchogarcia, this isn’t an operation built into n8n I am afraid. You could use an API for the job, for example OneSimpleAPI. n8n has a node for it, but it only supports converting HTML coming from a URL into a PDF.
If you want to use your email HTML you’d need to use the HTTP Request node. Like so:
Your credentials would need to be set up like so (Name = token, Value would be your actual token):
The above workflow would transform this:
Into a PDF like this:
Thank you very much @MutedJam!! You are the best! 
Do you think that your solution will support embebed pictures into the html code? IMAP returns the embebed pictures into the body as base64.
I doubt it tbh, but it’s worth simply trying it out. If not, it could be worth checking directly with the folks offering this API. I believe @Jon mentioned they’re pretty active when it comes to the development of their tool.
There might be other APIs out there as well, though I am not super familiar with this space.
Okey, thank you very much again @MutedJam!!
Yes, there are tons of alternatives - if what you have works, that’s great. Generally HTML→PDF conversion isn’t great, but if you can be sure the content won’t be very complex or dynamic you’ll be ok (or if you don’t care about the output).
If you’re finding this isn’t performing well enough, you could consider converting the HTML to markdown then using a simple library like pdfmake to produce a PDF.
إضافة شيء واحد لأي شخص يصل هنا من البحث، لأن الصور المضمنة هي الجزء الذي عادة ما يسبب مشاكل.
- يشير HTML البريد الإلكتروني إلى الصور المضمنة بروابط
cid: (على سبيل المثال <img src="cid:image001.png@...">). لا يمكن لمحرر PDF حل هذه الروابط، لذلك تظهر الصور فارغة.
- إذا كنت تستخدم عقدة Email Trigger (IMAP)، تحقق من Resolved format أولاً. قد يكون إخراج HTML الخاص به قد حول الصور المضمنة بالفعل إلى data URIs.
- إذا كان لا يزال لديك روابط
cid:، استخدم عقدة Code لاستبدال كل واحدة برابط data URI (data:image/png;base64,...) مبني من المرفق المطابق. بعد ذلك يكون HTML محتوياً على نفسه.
- أضف
<meta charset="utf-8"> و@page { size: A4; margin: 12mm; } بسيط قبل التحويل، وإلا قد تبدو الرموز والهوامش غريبة.
- ثم أرسل HTML إلى محرر الخاص بك. Gotenberg الذي يستضيفه بنفسك يعمل بشكل جيد: عقدة HTTP Request، بيانات نموذج متعددة الأجزاء، HTML كحقل ملف باسم
index.html، POST إلى /forms/chromium/convert/html. الاستجابة هي ملف PDF الثنائي، جاهز للـ Drive أو المرفق.
رسائل البريد الإلكتروني على نمط النشرة الإخبارية الواسعة (جداول بحجم 600 إلى 700 بكسل) تطبع أيضاً بشكل أفضل مع صفحة في اتجاه أفقي أو zoom طفيف على الجسم.
إذا كنت تفضل عدم تشغيل Gotenberg بنفسك، فإن thirds.ai يأخذ نفس HTML في استدعاء API واحد ويعيد PDF: HTML to PDF API: convert HTML to PDF from your code | thirds.ai
(إفصاح: أنا متصل بـ thirds.ai.)