diff --git a/html/arabic/python/general/convert-docx-to-markdown-with-selective-features-using-pytho/_index.md b/html/arabic/python/general/convert-docx-to-markdown-with-selective-features-using-pytho/_index.md new file mode 100644 index 000000000..87f94e4f4 --- /dev/null +++ b/html/arabic/python/general/convert-docx-to-markdown-with-selective-features-using-pytho/_index.md @@ -0,0 +1,226 @@ +--- +category: general +date: 2026-09-10 +description: حوّل ملفات docx إلى markdown بسرعة – تعلّم كيفية تصدير Word كـ markdown + مع التحكم في الروابط والفقرات في سكريبت واحد. +draft: false +images: +- PLACEHOLDER_URL/og-image.png +keywords: +- convert docx to markdown +- export word as markdown +- convert html to markdown +- save document as markdown +- convert word with links +language: ar +lastmod: 2026-09-10 +og_description: تحويل ملف docx إلى markdown باستخدام Python، وتصدير مستند Word كـ markdown، + والتحكم في العناصر التي يتم حفظها (الروابط، الفقرات). +og_image_alt: Screenshot of a Python script converting a Word file to a Markdown file +og_title: تحويل docx إلى markdown مع ميزات مختارة – دليل بايثون +schemas: +- author: Aspose + dateModified: '2026-09-10' + description: Convert docx to markdown quickly – learn how to export word as markdown + while controlling links and paragraphs in a single script. + headline: Convert docx to markdown with selective features using Python + type: TechArticle +- description: Convert docx to markdown quickly – learn how to export word as markdown + while controlling links and paragraphs in a single script. + name: Convert docx to markdown with selective features using Python + steps: + - name: Can I **save document as markdown** without using Aspose? + text: Yes, you could use `python-docx` to read the DOCX and a Markdown library + like `markdownify`. However, Aspose.Words offers a single‑call, high‑fidelity + conversion that respects complex Word features (e.g., nested lists, footnotes) + out of the box. + - name: What if my source is HTML instead of DOCX? + text: Replace the `load_document` call with an `HtmlLoadOptions`‑based load, or + pass an `HtmlDocument` directly to `Converter.convert_html`. The rest of the + pipeline (options configuration and saving) remains identical. + - name: Does the converter preserve Unicode characters? + text: Absolutely. Aspose.Words handles UTF‑8 throughout the conversion, so characters + such as emojis, accented letters, or non‑Latin scripts appear correctly in the + Markdown output. + type: HowTo +tags: +- Aspose.Words +- Python +- Document conversion +title: تحويل ملف docx إلى markdown مع ميزات انتقائية باستخدام بايثون +url: /ar/python/general/convert-docx-to-markdown-with-selective-features-using-pytho/ +--- + +{{< blocks/products/pf/main-wrap-class >}} +{{< blocks/products/pf/main-container >}} +{{< blocks/products/pf/tutorial-page-section >}} + +# تحويل docx إلى markdown مع ميزات انتقائية باستخدام Python + +إذا كنت بحاجة إلى **convert docx to markdown** مع الحفاظ فقط على عناصر محددة مثل الروابط والفقرات، فإن هذا الدليل يوضح لك بالضبط كيفية القيام بذلك. سترى سكريبت كامل قابل للتنفيذ يقوم **exports word as markdown** باستخدام Aspose.Words for Python ويشرح لماذا كل إعداد مهم. + +بحلول نهاية الدليل ستتمكن من: + +* تحميل ملف `.docx` باستخدام Aspose.Words. +* تكوين `MarkdownSaveOptions` لتضمين فقط الميزات التي تحتاجها. +* حفظ ملف Markdown الناتج إلى القرص. +* فهم كيفية تعديل النهج نفسه لتطبيق **convert html to markdown** أو **save document as markdown** مع مجموعات ميزات مختلفة. + +لا توجد أدوات خارجية مطلوبة—فقط مكتبة Aspose.Words وعدة أسطر من Python. + +## المتطلبات المسبقة + +* Python 3.8 أو أحدث. +* Aspose.Words for Python عبر .NET (`pip install aspose-words-cloud` أو الحزمة المناسبة لمنصتك). +* مستند Word (`.docx`) ترغب في تحويله. + +> **نصيحة احترافية:** إذا كنت تخطط لمعالجة العديد من الملفات، أنشئ بيئة افتراضية للحفاظ على عزل الاعتمادات. + +## الخطوة 1: تثبيت حزمة Aspose.Words + +```bash +pip install aspose-words +``` + +توفر الحزمة الفئات `Document` و `MarkdownSaveOptions` و `Converter` المستخدمة طوال هذا الدليل. + +## الخطوة 2: استيراد الفئات المطلوبة + +```python +import os +from aspose.words import Document, MarkdownSaveOptions, Converter +``` + +تمنحك هذه الاستيرادات الوصول إلى محرك التحويل الأساسي (`Converter`) وكائن الخيارات الذي يتحكم فيما يتم كتابته إلى ملف Markdown. + +## الخطوة 3: تحميل مستند DOCX + +```python +def load_document(path: str) -> Document: + """ + Opens the Word file located at `path` and returns an Aspose.Words Document object. + """ + if not os.path.isfile(path): + raise FileNotFoundError(f"Input file not found: {path}") + return Document(path) +``` + +تحميل المستند هو الخطوة الإلزامية الأولى؛ بدون كائن `Document` لا يمتلك المحول ما يعالجه. + +## الخطوة 4: تكوين خيارات حفظ Markdown + +```python +def configure_options() -> MarkdownSaveOptions: + """ + Creates a MarkdownSaveOptions object that enables only the desired features: + - LINK: preserve hyperlinks. + - PARAGRAPH: keep paragraph breaks. + """ + options = MarkdownSaveOptions() + # The Feature enum controls which Markdown constructs are emitted. + options.features = [ + MarkdownSaveOptions.Feature.LINK, + MarkdownSaveOptions.Feature.PARAGRAPH + ] + return options +``` + +**لماذا تقييد الميزات؟** +عندما تحتاج فقط إلى الروابط وبنية الفقرات، فإن تعطيل الميزات الأخرى (مثل الجداول أو الصور) ينتج Markdown أنظف ويقلل حجم الملف. هذا مفيد بشكل خاص عندما لا يستطيع المستهلك اللاحق (مثل مولد المواقع الثابتة) معالجة تلك العناصر. + +## الخطوة 5: تنفيذ التحويل + +```python +def convert_docx_to_markdown(input_path: str, output_path: str) -> None: + """ + Converts a DOCX file to Markdown using the configured options. + The `Converter.convert_html` method works for both DOCX and HTML sources, + so you can also **convert html to markdown** by passing an HTML Document. + """ + doc = load_document(input_path) + opts = configure_options() + # The third argument is the target file path. + Converter.convert_html(doc, opts, output_path) +``` + +> **ملاحظة:** `Converter.convert_html` هي طريقة متعددة الاستخدامات يمكنها أيضًا قبول `HtmlDocument`. لهذا السبب يمكن إعادة استخدام نفس الشيفرة لسيناريوهات **convert html to markdown**. + +## الخطوة 6: تشغيل السكريبت والتحقق من المخرجات + +```python +if __name__ == "__main__": + # Adjust these paths to match your environment. + INPUT_DOCX = "YOUR_DIRECTORY/input.docx" + OUTPUT_MD = "YOUR_DIRECTORY/links_paragraphs.md" + + try: + convert_docx_to_markdown(INPUT_DOCX, OUTPUT_MD) + print(f"✅ Markdown saved to: {OUTPUT_MD}") + except Exception as e: + print(f"❌ Conversion failed: {e}") +``` + +عند انتهاء السكريبت، ستجد ملفًا مشابهًا للمقتطف أدناه: + +```markdown +[OpenAI](https://openai.com) + +This is a paragraph that was present in the original Word document. + +Another paragraph with a [different link](https://example.com). +``` + +فقط الروابط وفواصل الفقرات موجودة لأننا أمرنا المحول بـ **convert word with links** وتجاهل العناصر الأخرى. + +## كيفية **export word as markdown** مع ميزات إضافية + +إذا قررت لاحقًا أنك بحاجة إلى جداول أو صور، ما عليك سوى توسيع قائمة `features`: + +```python +options.features = [ + MarkdownSaveOptions.Feature.LINK, + MarkdownSaveOptions.Feature.PARAGRAPH, + MarkdownSaveOptions.Feature.TABLE, + MarkdownSaveOptions.Feature.IMAGE +] +``` + +تشغيل نفس التحويل الآن سيشمل جداول Markdown وإشارات الصور. + +## الأسئلة المتكررة + +### هل يمكنني **save document as markdown** دون استخدام Aspose؟ + +نعم، يمكنك استخدام `python-docx` لقراءة DOCX ومكتبة Markdown مثل `markdownify`. ومع ذلك، توفر Aspose.Words تحويلًا عالي الدقة بنقرة واحدة يحافظ على ميزات Word المعقدة (مثل القوائم المتداخلة، الحواشي) مباشرةً. + +### ماذا لو كان المصدر الخاص بي HTML بدلاً من DOCX؟ + +استبدل استدعاء `load_document` بتحميل يعتمد على `HtmlLoadOptions`، أو مرّر `HtmlDocument` مباشرة إلى `Converter.convert_html`. يبقى باقي خط الأنابيب (تكوين الخيارات والحفظ) كما هو. + +### هل يحافظ المحول على أحرف Unicode؟ + +بالطبع. تتعامل Aspose.Words مع UTF‑8 طوال عملية التحويل، لذا تظهر الأحرف مثل الإيموجي، الحروف المشكّلة، أو النصوص غير اللاتينية بشكل صحيح في مخرجات Markdown. + +## الخلاصة + +أصبح لديك الآن **حل كامل من البداية إلى النهاية** لتحويل docx إلى markdown مع التحكم الدقيق في العناصر التي يتم إصدارها. يوضح السكريبت النهج الموصى به لـ **export word as markdown**، ويظهر كيف يمكن لنفس الـ API أن **convert html to markdown**، ويشرح كيفية **save document as markdown** مع علامات ميزات مخصصة. + +لا تتردد في التجربة: + +* إضافة أو إزالة ميزات من `options.features`. +* استبدال مصدر الإدخال بـ HTML لاختبار مسار تحويل HTML. +* دمج الدالة في خط أنابيب معالجة دفعات أكبر. + +برمجة سعيدة، واستمتع بملفات Markdown النظيفة والغنية بالروابط التي تم إنشاؤها من مستندات Word الخاصة بك! + +## ما الذي يجب أن تتعلمه بعد ذلك؟ + +الدروس التالية تغطي مواضيع ذات صلة وثيقة تبني على التقنيات الموضحة في هذا الدليل. كل مورد يتضمن أمثلة شيفرة كاملة مع شروحات خطوة بخطوة لمساعدتك على إتقان ميزات API إضافية واستكشاف أساليب تنفيذ بديلة في مشاريعك. + +- [Markdown to HTML Java - Convert with Aspose.HTML](/html/english/java/conversion-html-to-other-formats/convert-markdown-to-html/) +- [Convert Markdown to PDF in Java – Complete Guide](/html/english/java/conversion-html-to-other-formats/convert-markdown-to-pdf-in-java-complete-guide/) + +{{< /blocks/products/pf/tutorial-page-section >}} +{{< /blocks/products/pf/main-container >}} +{{< /blocks/products/pf/main-wrap-class >}} +{{< blocks/products/products-backtop-button >}} \ No newline at end of file diff --git a/html/arabic/python/general/create-pdf-from-html-with-aspose-html-in-python-step-by-step/_index.md b/html/arabic/python/general/create-pdf-from-html-with-aspose-html-in-python-step-by-step/_index.md new file mode 100644 index 000000000..80437f99e --- /dev/null +++ b/html/arabic/python/general/create-pdf-from-html-with-aspose-html-in-python-step-by-step/_index.md @@ -0,0 +1,267 @@ +--- +category: general +date: 2026-09-10 +description: إنشاء PDF من HTML باستخدام Aspose.HTML في بايثون. اتبع هذا المثال الكامل + لتحويل HTML إلى PDF لحفظ HTML كملف PDF بسرعة وموثوقية. +draft: false +images: +- PLACEHOLDER_URL/og-image.png +keywords: +- create pdf from html +- aspose html to pdf +- html to pdf example +- save html as pdf +- python html to pdf +language: ar +lastmod: 2026-09-10 +og_description: إنشاء ملف PDF من HTML باستخدام Aspose.HTML في بايثون. يشرح هذا الدليل + خطوة بخطوة مثالًا كاملاً لتحويل HTML إلى PDF، موضحًا كيفية حفظ HTML كملف PDF بكفاءة. +og_image_alt: Screenshot of Python code that creates a PDF from an HTML file using + Aspose.HTML +og_title: إنشاء PDF من HTML باستخدام Aspose.HTML في بايثون – دليل كامل +schemas: +- author: Aspose + dateModified: '2026-09-10' + description: Create PDF from HTML with Aspose.HTML in Python. Follow this complete + html to pdf example to save HTML as PDF quickly and reliably. + headline: Create PDF from HTML with Aspose.HTML in Python – step‑by‑step guide + type: TechArticle +- description: Create PDF from HTML with Aspose.HTML in Python. Follow this complete + html to pdf example to save HTML as PDF quickly and reliably. + name: Create PDF from HTML with Aspose.HTML in Python – step‑by‑step guide + steps: + - name: Why this step matters + text: The `aspose-html` package contains the `Converter` class that performs the + heavy lifting of rendering HTML and generating a PDF. Without it the rest of + the tutorial cannot run. + - name: Why this step matters + text: A well‑formed HTML source ensures the **aspose html to pdf** conversion + renders correctly. External resources such as images or CSS files should be + reachable via absolute or relative paths; otherwise the converter will embed + placeholders. + - name: Why this step matters + text: The `Converter.convert` method is the single call that **save html as pdf**. + Wrapping it in a function adds validation and makes the code reusable across + larger projects. + - name: Why this step matters + text: This demonstrates a more advanced **python html to pdf** scenario where + you don’t need an intermediate file, which is useful for web services or serverless + functions. + type: HowTo +tags: +- Aspose.HTML +- Python +- PDF conversion +title: إنشاء ملف PDF من HTML باستخدام Aspose.HTML في بايثون – دليل خطوة بخطوة +url: /ar/python/general/create-pdf-from-html-with-aspose-html-in-python-step-by-step/ +--- + +{{< blocks/products/pf/main-wrap-class >}} +{{< blocks/products/pf/main-container >}} +{{< blocks/products/pf/tutorial-page-section >}} + +# إنشاء PDF من HTML باستخدام Aspose.HTML في بايثون – دليل خطوة بخطوة + +إذا كنت بحاجة إلى **إنشاء PDF من HTML** في مشروع بايثون، يوضح لك هذا الدليل بالضبط كيفية القيام بذلك باستخدام مكتبة Aspose.HTML. ستحصل على **مثال html to pdf** جاهز للتنفيذ يحفظ صفحة HTML كملف PDF في ثلاث أسطر من الشيفرة فقط. + +سنغطي كل ما تحتاج إلى معرفته: تثبيت SDK، كتابة سكريبت التحويل، التعامل مع المشكلات الشائعة، وتوسيع الحل للمحتوى الديناميكي. في النهاية ستكون قادرًا على **حفظ HTML كـ PDF** بشكل موثوق في أي بيئة بايثون. + +## ما ستحتاجه + +* تثبيت Python 3.8 أو أحدث +* الوصول إلى الطرفية أو موجه الأوامر +* رخصة Aspose.HTML للبايثون (الإصدار التجريبي المجاني يعمل للتقييم) + +لا توجد أدوات طرف ثالث إضافية مطلوبة — SDK يتعامل مع CSS، الصور، والخطوط مباشرةً. + +## الخطوة 1: تثبيت Aspose.HTML للبايثون + +يتم توزيع Aspose.HTML عبر PyPI، لذا فإن التثبيت يتم بأمر `pip` واحد. + +```bash +pip install aspose-html +``` + +> **نصيحة احترافية:** شغّل الأمر داخل بيئة افتراضية للحفاظ على عزل الاعتمادات عن المشاريع الأخرى. + +### لماذا هذه الخطوة مهمة +حزمة `aspose-html` تحتوي على الفئة `Converter` التي تقوم بالمعالجة الثقيلة لتصيير HTML وإنشاء PDF. بدونها لا يمكن تشغيل باقي الدليل. + +## الخطوة 2: إعداد ملف HTML المصدر + +أنشئ ملف HTML بسيط باسم `sample.html` في مجلد تملكه (استبدل `YOUR_DIRECTORY` بالمسار الفعلي). يمكن للملف أن يحتوي على أي HTML صالح؛ للعرض سنستخدم صفحة بسيطة تحتوي على عنوان وفقرة. + +```html + + +
+ +This PDF was generated from an HTML file using Python.
+ + +``` + +### لماذا هذه الخطوة مهمة +مصدر HTML مُشكل جيدًا يضمن أن تحويل **aspose html to pdf** يتم بشكل صحيح. يجب أن تكون الموارد الخارجية مثل الصور أو ملفات CSS قابلة للوصول عبر مسارات مطلقة أو نسبية؛ وإلا سيُدرج المحول عناصر نائبة. + +## الخطوة 3: كتابة سكريبت التحويل بايثون + +أنشئ ملفًا جديدًا باسم `convert_to_pdf.py` في نفس الدليل والصق الشيفرة التالية. هذا هو **مثال html to pdf** الأساسي. + +```python +# convert_to_pdf.py +from aspose.html import Converter +import os + +def convert_html_to_pdf(input_html_path: str, output_pdf_path: str) -> None: + """ + Converts an HTML file to PDF using Aspose.HTML. + + Args: + input_html_path: Path to the source .html file. + output_pdf_path: Desired path for the generated .pdf file. + """ + # Verify that the input file exists + if not os.path.isfile(input_html_path): + raise FileNotFoundError(f"Input HTML file not found: {input_html_path}") + + # Perform the conversion + Converter.convert(input_html_path, output_pdf_path) + + print(f"✅ PDF created successfully: {output_pdf_path}") + +if __name__ == "__main__": + # Define the input and output locations (replace YOUR_DIRECTORY as needed) + input_html = os.path.join("YOUR_DIRECTORY", "sample.html") + output_pdf = os.path.join("YOUR_DIRECTORY", "sample.pdf") + + # Run the conversion + convert_html_to_pdf(input_html, output_pdf) +``` + +#### النتيجة المتوقعة + +Running the script: + +```bash +python convert_to_pdf.py +``` + +should print: + +``` +✅ PDF created successfully: YOUR_DIRECTORY/sample.pdf +``` + +وستجد `sample.pdf` بجوار `sample.html`. عند فتح الـ PDF سيظهر العنوان والفقرة مصوّرين بنفس التنسيق المحدد في كتلة ` + + +This PDF was generated from an HTML file using Python.
+ +