Class PdfManager
يمثل مكوّن Documentize.PdfManager. يُستخدم للدمج، التقسيم، التحسين، الدوران، تغيير الحجم، ضغط ملفات PDF وإضافة جدول، إضافة فهرس إلى ملفات PDF. يمكن دمج عدة ملفات PDF في ملف واحد. يمكن تقسيم ملفات PDF إلى صفحات منفصلة. يمكن تحسين، دوران، تغيير حجم، ضغط ملفات PDF. يمكن دوران وتغيير حجم صفحات ملف PDF. يمكن إضافة جدول إلى ملف PDF. يمكن إضافة فهرس إلى ملف PDF.
يمثل مكوّن Documentize.PdfManager. يُستخدم للدمج، التقسيم، التحسين، الدوران، تغيير الحجم، ضغط ملفات PDF وإضافة جدول، إضافة فهرس إلى ملفات PDF.
يمكن دمج عدة ملفات PDF في ملف واحد.
يمكن تقسيم ملفات PDF إلى صفحات منفصلة.
يمكن تحسين، دوران، تغيير حجم، ضغط ملفات PDF.
يمكن دوران وتغيير حجم صفحات ملف PDF.
يمكن إضافة جدول إلى ملف PDF.
يمكن إضافة فهرس إلى ملف PDF.
public static class PdfManagerالوراثة
الأعضاء الوراثية
- object.GetType(),
- object.MemberwiseClone(),
- object.ToString(),
- object.Equals(object?),
- object.Equals(object?, object?),
- object.ReferenceEquals(object?, object?),
- object.GetHashCode()
الأساليب
AddTable(TableOptions)
إضافة جدول إلى ملف PDF.
public static ResultContainer AddTable(TableOptions options)المعاملات
optionsTableOptions: كائن الخيارات الذي يحتوي على تعليمات العملية.
القيم المرجعة
ResultContainer : كائن يحتوي على نتيجة العملية.
أمثلة
يوضح المثال كيفية إضافة جدول إلى ملف PDF.
// Configure table options
var options = new TableOptions();
options.InsertPageBefore(1)
.AddTable()
.AddRow()
.AddCell().AddParagraph("Name")
.AddCell().AddParagraph("Age")
.AddRow()
.AddCell().AddParagraph("Bob")
.AddCell().AddParagraph("12")
.AddRow()
.AddCell().AddParagraph("Sam")
.AddCell().AddParagraph("20")
.AddRow()
.AddCell().AddParagraph("Sandy")
.AddCell().AddParagraph("26")
.AddRow()
.AddCell().AddParagraph("Tom")
.AddCell().AddParagraph("12")
.AddRow()
.AddCell().AddParagraph("Jim")
.AddCell().AddParagraph("27");
// Add input file path
options.AddInput(new FileData("path_to_input.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_output.pdf"));
// Perform the process
PdfManager.AddTable(options);يوضح المثال كيفية إضافة جدول إلى ملف PDF قبل الصفحة 2.
// Configure table options
var options = new TableOptions();
options.InsertPageBefore(2) // Add table before page 2
.AddTable()
.AddRow()
.AddCell().AddParagraph("Name")
.AddCell().AddParagraph("Age");
// Add input file path
options.AddInput(new FileData("path_to_input.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_output.pdf"));
// Perform the process
PdfManager.AddTable(options);الاستثناءات
إذا لم يتم تعيين الخيارات.
AddTableOfContents(TocOptions)
إضافة فهرس (TOC) إلى ملف PDF.
public static ResultContainer AddTableOfContents(TocOptions options)المعاملات
optionsTocOptions: كائن الخيارات الذي يحتوي على تعليمات العملية.
القيم المرجعة
ResultContainer : كائن يحتوي على نتيجة العملية.
أمثلة
يوضح المثال كيفية إضافة فهرس إلى ملف PDF.
// Create TocOptions object to set instructions
var options = new TocOptions();
// Set the Title
options.Title = "My Table of Contents";
// Design Headings
options.Headings.Add(new TocHeading("Introduction", 2));
options.Headings.Add(new TocHeading("Chapter I", 3));
options.Headings.Add(new TocHeading("Chapter II", 4));
options.Headings.Add(new TocHeading("Chapter III", 5));
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.AddTableOfContents(options);يوضح المثال كيفية إضافة فهرس إلى ملف PDF مع إنشاء إشارات مرجعية.
// Create TocOptions object to set instructions
var options = new TocOptions();
// Set the Title
options.Title = "My Table of Contents";
// Generate links in bookmarks
options.GenerateBookmarks = true;
// Design Headings
options.Headings.Add(new TocHeading("Introduction", 2, false, 1));
options.Headings.Add(new TocHeading("Chapter I", 3, true, 1));
options.Headings.Add(new TocHeading("Chapter II", 4, true, 1));
options.Headings.Add(new TocHeading("Example A", 4, true, 2));
options.Headings.Add(new TocHeading("Example B", 4, true, 2));
options.Headings.Add(new TocHeading("Example C", 4, true, 2));
options.Headings.Add(new TocHeading("Example D", 4, true, 2));
options.Headings.Add(new TocHeading("Chapter III", 5, true, 1));
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.AddTableOfContents(options);يوضح المثال كيفية إضافة فهرس إلى ملف PDF وحفظه كتيار.
// Create TocOptions object to set instructions
var options = new TocOptions();
// Set the Title
options.Title = "My Table of Contents";
// Design Headings
options.Headings.Add(new TocHeading("Introduction", 2, false, 1));
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output stream
var outputStream = new MemoryStream();
options.AddOutput(new StreamData(outputStream));
options.CloseOutputStreams = false;
// Perform the process
PdfManager.AddTableOfContents(options);يوضح المثال كيفية إضافة فهرس إلى ملف PDF مع تخصيص عنوان الفهرس.
// Create TocOptions object to set instructions
var heading = new TocHeading();
heading.Text = "Intro";
heading.PageNumber = 5;
heading.GenerateNumbering = true;
heading.Level = 2;
var tocOptions = new TocOptions();
tocOptions.Headings.Add(heading);
// Add input and output files
tocOptions.AddInput(new FileData("path_to_your_pdf_file.pdf"));
tocOptions.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Generate the TOC with customized options
PdfManager.AddTableOfContents(tocOptions);الاستثناءات
إذا لم يتم تعيين الخيارات.
Compress(CompressOptions)
ضغط ملف PDF. محاولة تقليل حجم المستند.
public static ResultContainer Compress(CompressOptions options)المعاملات
optionsCompressOptions: كائن الخيارات الذي يحتوي على تعليمات العملية.
القيم المرجعة
ResultContainer : كائن يحتوي على نتيجة العملية.
أمثلة
يوضح المثال كيفية ضغط ملف PDF.
// Create CompressOptions object to set instructions
var options = new CompressOptions();
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Compress(options);الاستثناءات
إذا لم يتم تعيين الخيارات.
CreatePdfByChatGptRequestAsync(ChatGptRequestOptions)
إنشاء مستند PDF بناءً على ردّ ChatGpt.
يُستخدم لإرسال طلبات إلى ChatGPT مباشرة أو عن طريق إضافة مصادر ملفات PDF وحفظ الرد في المصدر المحدد.
public static Task<resultcontainer> CreatePdfByChatGptRequestAsync(ChatGptRequestOptions options)المعاملات
optionsChatGptRequestOptions: كائن الخيارات الذي يحتوي على تعليمات العملية.
القيم المرجعة
كائن يحتوي على نتيجة العملية.
أمثلة
يوضح المثال كيفية استخدام ChatGpt بإضافة رسائل إلى الطلب.
var options = new ChatGptRequestOptions();
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
options.ApiKey = "Your API key."; // You need to provide the key to access the API.
options.MaxTokens = 1000; // The maximum number of tokens to generate in the chat completion.
// Add the request messages.
options.Messages.Add(new Message
{
Content = "You are a helpful assistant.",
Role = Role.System
});
options.Messages.Add(new Message
{
Content = "What is the biggest pizza diameter ever made?",
Role = Role.User
});
// Process the request.
var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.يوضح المثال كيفية استخدام ChatGpt بإضافة رسالة واحدة إلى الطلب.
var options = new ChatGptRequestOptions();
options.AddOutput(new FileData("path_to_result_pdf_file.pdf")); // Add the output file path.
options.ApiKey = "Your API key."; // You need to provide the key to access the API.
options.MaxTokens = 1000; // The maximum number of tokens to generate in the chat completion.
// Add the request message.
// In this case, the system message with Content = "You are a helpful assistant." is added by default.
// The role of the query message is "user" by default.
options.Query = "What is the lowest temperature recorded on the Earth?";
// Process the request.
var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.يوضح المثال كيفية استخدام الدردشة بإضافة ملف (ملفات) كمصدر للرسائل.
var options = new ChatGptRequestOptions();
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Add the PDF text source.
// In case of multiple sources, the text from each document will be added to the request message collection
// as a separate message with the role "user".
options.AddInput(new FileData("TextSource.pdf"));
options.ApiKey = "Your API key."; // You need to provide the key to access the API.
options.MaxTokens = 1000; // The maximum number of tokens to generate in the chat completion.
// Add the request message.
// In this case, the system message with Content = "You are a helpful assistant." is added by default.
// The role of the query message is "user" by default.
options.Query = "How many letters in the provided text?";
// Process the request.
var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.الاستثناءات
ArgumentException : إذا لم يتم تعيين الخيارات.
Merge(MergeOptions)
دمج ملفات PDF.
public static ResultContainer Merge(MergeOptions options)المعاملات
optionsMergeOptions: كائن الخيارات الذي يحتوي على تعليمات العملية.
القيم المرجعة
ResultContainer : كائن يحتوي على نتيجة العملية.
أمثلة
يوضح المثال كيفية دمج ملفين PDF.
// Create MergeOptions object to set instructions
var options = new MergeOptions();
// Add input file paths
options.AddInput(new FileData("path_to_your_pdf_file_1.pdf"));
options.AddInput(new FileData("path_to_your_pdf_file_2.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Merge(options);الاستثناءات
إذا لم يتم تعيين الخيارات.
Optimize(OptimizeOptions)
تحسين ملف PDF.
يتم تحسين المستند لجعله:
- فتح الصفحة الأولى بأسرع ما يمكن؛
- عرض الصفحة التالية أو الانتقال عبر رابط إلى الصفحة التالية بأسرع ما يمكن؛
- عرض الصفحة تدريجيًا عند وصول البيانات عبر قناة بطيئة (عرض أهم البيانات أولًا)؛
- السماح بالتفاعل (مثل اتباع رابط) قبل استلام وعرض الصفحة بالكامل.
public static ResultContainer Optimize(OptimizeOptions options)المعاملات
optionsOptimizeOptions: كائن الخيارات الذي يحتوي على تعليمات العملية.
القيم المرجعة
ResultContainer : كائن يحتوي على نتيجة العملية.
أمثلة
يوضح المثال كيفية تحسين ملف PDF.
// Create OptimizeOptions object to set instructions
var options = new OptimizeOptions();
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Optimize(options);الاستثناءات
إذا لم يتم تعيين الخيارات.
Resize(ResizeOptions)
تغيير حجم صفحات ملف PDF.
public static ResultContainer Resize(ResizeOptions options)المعاملات
optionsResizeOptions: كائن الخيارات الذي يحتوي على تعليمات العملية.
القيم المرجعة
ResultContainer : كائن يحتوي على نتيجة العملية.
أمثلة
يوضح المثال كيفية تغيير حجم ملف PDF.
// Create ResizeOptions object to set instructions
var options = new ResizeOptions();
// Set new PageSize
options.PageSize = PageSize.A3;
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Resize(options);الاستثناءات
إذا لم يتم تعيين الخيارات.
Rotate(RotateOptions)
دوران صفحات ملف PDF.
public static ResultContainer Rotate(RotateOptions options)المعاملات
optionsRotateOptions: كائن الخيارات الذي يحتوي على تعليمات العملية.
القيم المرجعة
ResultContainer : كائن يحتوي على نتيجة العملية.
أمثلة
يوضح المثال كيفية دوران ملف PDF.
// Create RotateOptions object to set instructions
var options = new RotateOptions();
// Set new Rotation
options.Rotation = Rotation.On90;
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Rotate(options);الاستثناءات
إذا لم يتم تعيين الخيارات.
Split(SplitOptions)
تقسيم ملف PDF حسب الصفحات.
public static ResultContainer Split(SplitOptions options)المعاملات
optionsSplitOptions: كائن الخيارات الذي يحتوي على تعليمات العملية.
القيم المرجعة
ResultContainer : كائن يحتوي على نتيجة العملية.
أمثلة
يوضح المثال كيفية تقسيم ملف PDF.
// Create SplitOptions object to set instructions
var options = new SplitOptions();
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output file paths
options.AddOutput(new FileData("path_to_result_pdf_file_1.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file_2.pdf"));
// Perform the process
PdfManager.Split(options);الاستثناءات
إذا لم يتم تعيين الخيارات.
Namespace: Documentize Assembly: Documentize.dll