Mansour Hussen نشر 20 أبريل أرسل تقرير نشر 20 أبريل سلام عليكم عندما استخدم مكتبة تحويل من HTML الى PDF بلغة بايثون وضمن الخط العربي يظهر الخط العربي: <!DOCTYPE html> <html lang="ar"> <head> <meta charset="utf-8"> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@100..900&display=swap" rel="stylesheet"> <style> .font { font-family: "Noto Sans Arabic", sans-serif; direction: rtl; text-align: right; font-size: 18px; } </style> </head> <body> <h1 class="font">عربي </h1> <h1>english</h1> </body> </html> @app.route("/pdf") def pdf(): html = render_template("template.html") result = io.BytesIO() pisa_status = pisa.CreatePDF( html, dest=result, encoding='utf-8', link_callback=link_callback ) if pisa_status.err: return "PDF generation failed", 500 result.seek(0) response = make_response(result.getvalue()) response.headers["Content-Type"] = "application/pdf" response.headers["Content-Disposition"] = "attachment; filename=arabic.pdf" return response 3 اقتباس
0 بلال زيادة نشر 20 أبريل أرسل تقرير نشر 20 أبريل المشكلة أن مكتبة pisa لا تدعم الخطوط العربية بشكل جيد افتراضيًا، خاصة عند استخدام خطوط Google Fonts مباشرة. بالإضافة إلى ذلك، قد تكون هناك مشكلة في طريقة معالجة اتجاه النص (RTL) أو الترميز و ايضا حاول تنزيل ملفات الخط محليا على جهازك ووضعها في المشروع و استدعائها بهذا الشكل @font-face { font-family: 'Noto Sans Arabic'; src: url('static/fonts/NotoSansArabic-Regular.ttf') format('truetype'); font-weight: normal; font-style: normal; } .font { font-family: 'Noto Sans Arabic', sans-serif; direction: rtl; text-align: right; font-size: 18px; } و اخباري بالنتيجة لو سمحت هل تم اصلاح مشكلة اللغة العربية أو لا. اقتباس
0 محمد عاطف16 نشر 20 أبريل أرسل تقرير نشر 20 أبريل وعليكم السلام ورحمة الله وبركاته. يرجى تجربة تحميل الملفات على جهازك محليا حيث يبدوا أن المكتبة xhtml2pdf أو بايثون لا يقومان بإرسال الطلب الخاص بالخط في ملف html. لذلك يرجى تحميل ملف الخط محليا ووضعه في مشروعك وفي ملف html يرجى إستخدام التالي: <style> @font-face { font-family: "Noto Sans Arabic"; src: url("/static/fonts/NotoSansArabic-Regular.ttf"); } .font { font-family: "Noto Sans Arabic", sans-serif; direction: rtl; text-align: right; font-size: 18px; } </style> بعد تحميل الخط وتنفيذ التعديل السابق يرجى إعادة تشغيل المشروع والمحاولة مرة أخرى. اقتباس
0 Mansour Hussen نشر 8 مايو الكاتب أرسل تقرير نشر 8 مايو عملت جميع مقرحات لكن بدون فائدة html = render_template_string(""" <html> <head> <style> @font-face { font-family: 'Noto Sans Arabic'; src: url('static/fonts/NotoSansArabic-Regular.ttf') format('truetype'); font-weight: normal; font-style: normal; } .font { font-family: 'Noto Sans Arabic', sans-serif; direction: rtl; text-align: right; font-size: 18px; } </style> </head> <body> <h1 class="amiri">عربي</h1> <h1 class="font">PDF</h1> </body> </html> """) result = io.BytesIO() pisa_status = pisa.CreatePDF(html, dest=result) if pisa_status.err: return "خطأ في توليد PDF", 500 result.seek(0) response = make_response(result.read()) response.headers['Content-Type'] = 'application/pdf' response.headers['Content-Disposition'] = 'inline; filename=document.pdf' return response 1 اقتباس
0 Mustafa Suleiman نشر 8 مايو أرسل تقرير نشر 8 مايو بتاريخ منذ ساعة مضت قال Mansour Hussen: عملت جميع مقرحات لكن بدون فائدة html = render_template_string(""" <html> <head> <style> @font-face { font-family: 'Noto Sans Arabic'; src: url('static/fonts/NotoSansArabic-Regular.ttf') format('truetype'); font-weight: normal; font-style: normal; } .font { font-family: 'Noto Sans Arabic', sans-serif; direction: rtl; text-align: right; font-size: 18px; } </style> </head> <body> <h1 class="amiri">عربي</h1> <h1 class="font">PDF</h1> </body> </html> """) result = io.BytesIO() pisa_status = pisa.CreatePDF(html, dest=result) if pisa_status.err: return "خطأ في توليد PDF", 500 result.seek(0) response = make_response(result.read()) response.headers['Content-Type'] = 'application/pdf' response.headers['Content-Disposition'] = 'inline; filename=document.pdf' return response سحتاج إلى مكتبة WeasyPrint لأنها تدعم العربية بشكل ممتاز وتتعامل مع CSS و@font-face بشكل أفضل بكثير من xhtml2pdf. أولاً عليك تثبيت gtk3-runtime-3.24.31-2022-01-04-ts-win64.exe حيث تعتمد عليه المكتبة، فقط اضغط next next: https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer/releases ثم قم بغلق محرر الأكواد ومنفذ الأوامر، ثم إعادة تشغيلهم. ثم استخدم المشروع التالي أرفقته لك، كل ما تحتاجه تثبيت الحزم من خلال: pip install -r requirements.txt html_2_pdf.rar 1 اقتباس
السؤال
Mansour Hussen
سلام عليكم
عندما استخدم مكتبة تحويل من HTML الى PDF بلغة بايثون وضمن الخط العربي يظهر الخط العربي:
4 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.