HTML JPG PDF XML DOCX
  Product Family
PDF

تغيير حجم PDF في .NET SDK

API للعمل مع تغيير حجم مستندات PDF باستخدام .NET.

Get Started

كيفية تغيير حجم PDF عبر Cloud .NET SDK

لتغيير حجم مستندات PDF، سنستخدم Aspose.PDF Cloud .NET SDK يتيح لك هذا SDK السحابي بناء تطبيقات لإنشاء وتحرير وتحويل PDF بسهولة في C#, ASP.NET أو لغات .NET أخرى لمنصات سحابية مختلفة. افتح NuGet مدير الحزم، وابحث عن Aspose.PDF Cloud وقم بالتثبيت. يمكنك أيضًا استخدام الأمر التالي من وحدة التحكم في مدير الحزم.

أمر وحدة تحكم مدير الحزم


    PM> Install-Package Aspose.Pdf-Cloud
     

خطوات لتغيير حجم PDF باستخدام .NET SDK

يمكن لمطوري Aspose.PDF Cloud تحميل وتغيير حجم PDF بسهولة في بضع سطور من الكود.

  1. قم برفع ملف PDF.
  2. تحويله إلى HTML (مع الحفاظ على الهيكل/المحتوى).
  3. تحويل HTML مرة أخرى إلى PDF جديد بالأبعاد المحددة.
  4. تحميل المستند الذي تم تغيير حجمه.
 

تغيير حجم PDF باستخدام .NET Cloud SDK


    using Aspose.Pdf.Cloud.Sdk.Model;


    namespace ChangeLayout
    {
        public class ResizeDocumentAllPages
        {
            private ChangeLayoutHelper _helper;

            public ResizeDocumentAllPages(ChangeLayoutHelper helper)
            {
                _helper = helper;
            }

            public async Task MakeResizeDocumentAllPages(string document, string htmlTempDoc, int pageWidth, int pageHeight)
            {
                await _helper.UploadFile(document);
                string htmlTempPath = Path.Combine(_helper.config.REMOTE_TEMP_FOLDER, htmlTempDoc);
                AsposeResponse response = await _helper.pdfApi.PutPdfInStorageToHtmlAsync(
                    document, htmlTempPath,
                    documentType: HtmlDocumentType.Xhtml.ToString(),
                    outputFormat: OutputFormat.Folder.ToString(),
                    folder: _helper.config.REMOTE_TEMP_FOLDER
                );
                if (response == null)
                    Console.WriteLine("MakeResizeDocumentAllPages(): Unexpected error - no response in Pdf to Html convert!");
                else if (response.Code != 200)
                    Console.WriteLine("MakeResizeDocumentAllPages(): Error -> Code {0} -> Status '{1}'", [response.Code, response.Status]);
                else
                {
                    Console.WriteLine("MakeResizeDocumentAllPages(): temporary file '{0}' successfully created.", htmlTempDoc);
                    string outputDocument = "resized_" + document;
                    await _helper.pdfApi.PutHtmlInStorageToPdfAsync(
                        outputDocument, htmlTempPath,
                        dstFolder: _helper.config.REMOTE_TEMP_FOLDER,
                        htmlFileName: htmlTempDoc,
                        height: pageHeight,
                        width: pageWidth
                    );

                    if (response == null)
                        Console.WriteLine("MakeResizeDocumentAllPages(): Unexpected error - no response in html to Pdf convert!");
                    else if (response.Code != 200)
                        Console.WriteLine("MakeResizeDocumentAllPages(): Error -> Code {0} -> Status '{1}'", [response.Code, response.Status]);
                    else
                    {
                        Console.WriteLine("resizePages(): Pages successfully resized.");
                        await _helper.DownloadFile(outputDocument, "resized_doc_");
                    }
                }

            }
        }
    }