تحويل ملف XLSX إلى صيغة PDF باستخدام JavaScript عبر C++

تحويل Excel إلى PDF

يستخدم هذا المثال ملف Excel (SampleInput.xlsx) كنموذج. يحتوي دفتر العمل على أوراق عمل مع مخططات وصور. كل ورقة تحتوي على أنواع مختلفة من التنسيقات باستخدام الخطوط والصفات والألوان وتأثيرات التظليل والحدود. توجد مخطط عمود على الورقة الأولى وصورة في الأخيرة.

ملف Excel القالب

ملف النموذج يحتوي على ثلاث أوراق عمل، بما في ذلك الرسوم البيانية والصور كوسائط. تحتوي الورقة الأولى على رسوم بيانية، والورقة الأخيرة تحتوي على صورة كما هو موضح في لقطات الشاشة أدناه.

todo:image_alt_text todo:image_alt_text
الورقة العمل الأولى (توقعات المبيعات) الورقة العمل الثانية (تقرير المبيعات)
todo:image_alt_text todo:image_alt_text
الصفحة العملية الثالثة (ادخال البيانات) الصفحة العملية الأخيرة (الصورة)

عملية التحويل

<!DOCTYPE html>
<html>
    <head>
        <title>Aspose.Cells Example - Excel to PDF</title>
    </head>
    <body>
        <h1>Excel to PDF Example</h1>
        <input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
        <button id="runExample">Convert to PDF</button>
        <a id="downloadLink" style="display: none;"></a>
        <div id="result"></div>
    </body>

    <script src="aspose.cells.js.min.js"></script>
    <script type="text/javascript">
        const { Workbook, SaveFormat, Utils } = AsposeCells;

        AsposeCells.onReady({
            license: "/lic/aspose.cells.enc",
            fontPath: "/fonts/",
            fontList: [
                "arial.ttf",
                "NotoSansSC-Regular.ttf"
            ]
        }).then(() => {
            console.log("Aspose.Cells initialized");
        });

        document.getElementById('runExample').addEventListener('click', async () => {
            const fileInput = document.getElementById('fileInput');
            if (!fileInput.files.length) {
                document.getElementById('result').innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
                return;
            }

            const file = fileInput.files[0];
            const arrayBuffer = await file.arrayBuffer();

            // Instantiating a Workbook object with the uploaded file
            const workbook = new Workbook(new Uint8Array(arrayBuffer));

            // Saving the PDF file
            const outputData = workbook.save(SaveFormat.Pdf);
            const blob = new Blob([outputData], { type: 'application/pdf' });
            const downloadLink = document.getElementById('downloadLink');
            downloadLink.href = URL.createObjectURL(blob);
            downloadLink.download = 'Output.out.pdf';
            downloadLink.style.display = 'block';
            downloadLink.textContent = 'Download PDF File';

            document.getElementById('result').innerHTML = '<p style="color: green;">PDF generated successfully! Click the download link to get the PDF file.</p>';
        });
    </script>
</html>

النتيجة

عند تشغيل الرمز أعلاه، يتم إنشاء ملف PDF في مجلد Files في دليل التطبيق الخاص بك. توضح اللقطات الشاشة التالية صفحات ملف PDF. يرجى ملاحظة أن الهوامش العلوية والسفلية محتفظ بها أيضًا في ملف PDF الناتج.

todo:image_alt_text todo:image_alt_text
الورقة العمل الأولى (توقعات المبيعات) الورقة العمل الثانية (تقرير المبيعات)
todo:image_alt_text todo:image_alt_text
الصفحة العملية الثالثة (ادخال البيانات) الصفحة العملية الأخيرة (الصورة)