Class PdfManager
يمثل مكون Documentize.PdfManager. يُستخدم لدمج، تقسيم، تحسين، تدوير، تغيير حجم، ضغط مستندات PDF وإضافة جدول، وإضافة جدول محتويات لمستندات PDF. يمكن دمج مستندات PDF متعددة في ملف PDF واحد. يمكن تقسيم مستندات PDF إلى صفحات منفصلة. يمكن تحسين، تدوير، تغيير حجم، ضغط مستندات PDF. يمكن تدوير، تغيير حجم صفحات مستند PDF. يمكن إضافة جدول إلى مستند PDF. يمكن إضافة جدول محتويات إلى مستند PDF.
يمثل مكون Documentize.PdfManager. يُستخدم لدمج، تقسيم، تحسين، تدوير، تغيير حجم، ضغط مستندات PDF وإضافة جدول، وإضافة جدول محتويات لمستندات PDF. يمكن دمج مستندات PDF متعددة في ملف PDF واحد. يمكن تقسيم مستندات PDF إلى صفحات منفصلة. يمكن تحسين، تدوير، تغيير حجم، ضغط مستندات PDF. يمكن تدوير، تغيير حجم صفحات مستند PDF. يمكن إضافة جدول إلى مستند PDF. يمكن إضافة جدول محتويات إلى مستند PDF.
public static class PdfManagerInheritance
Inherited Members
- object.GetType(),
- object.MemberwiseClone(),
- object.ToString(),
- object.Equals(object?),
- object.Equals(object?, object?),
- object.ReferenceEquals(object?, object?),
- object.GetHashCode()
Examples
The example demonstrates how to Merge two PDF documents.
// Create MergeOptions object to set instructions
var options = new MergeOptions();
// Add input file paths
options.AddInput(new FileDataSource("path_to_your_pdf_file_1.pdf"));
options.AddInput(new FileDataSource("path_to_your_pdf_file_2.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Merge(options);The example demonstrates how to Split PDF document.
// Create SplitOptions object to set instructions
var options = new SplitOptions();
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file paths
options.AddOutput(new FileDataSource("path_to_result_pdf_file_1.pdf"));
options.AddOutput(new FileDataSource("path_to_result_pdf_file_2.pdf"));
// Perform the process
PdfManager.Split(options);The example demonstrates how to Optimize PDF document.
// Create OptimizeOptions object to set instructions
var options = new OptimizeOptions();
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Optimize(options);The example demonstrates how to Rotate PDF document.
// Create RotateOptions object to set instructions
var options = new RotateOptions();
// Set new Rotation
options.Rotation = Rotation.On90;
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Rotate(options);The example demonstrates how to Resize PDF document.
// Create ResizeOptions object to set instructions
var options = new ResizeOptions();
// Set new PageSize
options.PageSize = PageSize.A3;
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Resize(options);The example demonstrates how to Compress PDF document.
// Create CompressOptions object to set instructions
var options = new CompressOptions();
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Compress(options);The example demonstrates how to Add Table to PDF file.
// 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 FileDataSource("path_to_input.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_output.pdf"));
// Perform the process
PdfManager.AddTable(options);The example demonstrates how to add Table of Contents to PDF file.
// 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 FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.AddTableOfContents(options);The example demonstrates how to add Table of Contents to PDF file with generating bookmarks.
// 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 FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.AddTableOfContents(options);The example demonstrates how to add Table of Contents to PDF file and save as stream.
// 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 FileDataSource("path_to_your_pdf_file.pdf"));
// Set output stream
var outputStream = new MemoryStream();
options.AddOutput(new StreamDataSource(outputStream));
options.CloseOutputStreams = false;
// Perform the process
PdfManager.AddTableOfContents(options);The example demonstrates how to use ChatGpt by adding messages to the request.
var options = new ChatGptRequestOptions();
// Set output file path
options.AddOutput(new FileDataSource("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.The example demonstrates how to use ChatGpt by adding one message to the request.
var options = new ChatGptRequestOptions();
options.AddOutput(new FileDataSource("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.The example demonstrates how to use Chat by adding file(s) as the message source(s).
var options = new ChatGptRequestOptions();
// Set output file path
options.AddOutput(new FileDataSource("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 FileDataSource("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.Methods
AddTable(TableOptions)
إضافة جدول إلى مستند PDF.
public static ResultContainer AddTable(TableOptions options)Parameters
optionsTableOptions: كائن خيارات يحتوي على تعليمات للعملية.
Returns
ResultContainer : كائن يحتوي على نتيجة العملية.
Exceptions
إذا لم يتم تعيين الخيارات.
AddTableOfContents(TocOptions)
إضافة جدول محتويات (TOC) إلى مستند PDF.
public static ResultContainer AddTableOfContents(TocOptions options)Parameters
optionsTocOptions: كائن خيارات يحتوي على تعليمات للعملية.
Returns
ResultContainer : كائن يحتوي على نتيجة العملية.
Exceptions
إذا لم يتم تعيين الخيارات.
Compress(CompressOptions)
ضغط مستند PDF. محاولة تقليل حجم المستند.
public static ResultContainer Compress(CompressOptions options)Parameters
optionsCompressOptions: كائن خيارات يحتوي على تعليمات للعملية.
Returns
ResultContainer : كائن يحتوي على نتيجة العملية.
Exceptions
إذا لم يتم تعيين الخيارات.
CreatePdfByChatGptRequestAsync(ChatGptRequestOptions)
إنشاء مستند PDF بواسطة رد ChatGpt. يُستخدم لإرسال الطلبات إلى ChatGPT مباشرةً أو من خلال إضافة مصادر ملفات PDF وحفظ الرد إلى مصدر الإخراج.
public static Task<resultcontainer> CreatePdfByChatGptRequestAsync(ChatGptRequestOptions options)Parameters
optionsChatGptRequestOptions: كائن خيارات يحتوي على تعليمات للعملية.
Returns
كائن يحتوي على نتيجة العملية.
Exceptions
ArgumentException : إذا لم يتم تعيين الخيارات.
Merge(MergeOptions)
دمج مستندات PDF.
public static ResultContainer Merge(MergeOptions options)Parameters
optionsMergeOptions: كائن خيارات يحتوي على تعليمات للعملية.
Returns
ResultContainer : كائن يحتوي على نتيجة العملية.
Exceptions
إذا لم يتم تعيين الخيارات.
Optimize(OptimizeOptions)
تحسين مستند PDF. توزيع المستند بشكل خطي لتحقيق:
- فتح الصفحة الأولى في أسرع وقت ممكن;
- عرض الصفحة التالية أو المتابعة من خلال الرابط إلى الصفحة التالية في أسرع وقت ممكن;
- عرض الصفحة بشكل تدريجي عند وصول البيانات للصفحة عبر قناة بطيئة (عرض البيانات الأكثر فائدة أولاً);
- السماح بالتفاعل مع المستخدم، مثل المتابعة عبر رابط، يتم تنفيذها حتى قبل استلام وعرض الصفحة بالكامل.
public static ResultContainer Optimize(OptimizeOptions options)Parameters
optionsOptimizeOptions: كائن خيارات يحتوي على تعليمات للعملية.
Returns
ResultContainer : كائن يحتوي على نتيجة العملية.
Exceptions
إذا لم يتم تعيين الخيارات.
Resize(ResizeOptions)
تغيير حجم صفحات مستند PDF.
public static ResultContainer Resize(ResizeOptions options)Parameters
optionsResizeOptions: كائن خيارات يحتوي على تعليمات للعملية.
Returns
ResultContainer : كائن يحتوي على نتيجة العملية.
Exceptions
إذا لم يتم تعيين الخيارات.
Rotate(RotateOptions)
تدوير صفحات مستند PDF.
public static ResultContainer Rotate(RotateOptions options)Parameters
optionsRotateOptions: كائن خيارات يحتوي على تعليمات للعملية.
Returns
ResultContainer : كائن يحتوي على نتيجة العملية.
Exceptions
إذا لم يتم تعيين الخيارات.
Split(SplitOptions)
تقسيم مستند PDF حسب الصفحات.
public static ResultContainer Split(SplitOptions options)Parameters
optionsSplitOptions: كائن خيارات يحتوي على تعليمات للعملية.
Returns
ResultContainer : كائن يحتوي على نتيجة العملية.
Exceptions
إذا لم يتم تعيين الخيارات.
Namespace: Documentize Assembly: Documentize.dll