Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
تساعدك هذه الموضوعات على فهم كيفية الحصول على خصائص نافذة المستند، وتطبيق العرض، وكيفية عرض الصفحات. لتعيين هذه الخصائص:
افتح ملف PDF باستخدام Document class. الآن، يمكنك تعيين خصائص كائن Document، مثل
يعمل مقتطف الشيفرة التالي أيضًا مع مكتبة Aspose.PDF.Drawing.
يظهر مقتطف الشيفرة التالي كيفية الحصول على الخصائص باستخدام Document class.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetDocumentWindowProperties()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetDocumentWindow.pdf"))
{
// Get different document properties
// Position of document's window - Default: false
Console.WriteLine("CenterWindow : {0}", document.CenterWindow);
// Predominant reading order; determines the position of page
// When displayed side by side - Default: L2R
Console.WriteLine("Direction : {0}", document.Direction);
// Whether window's title bar should display document title
// If false, title bar displays PDF file name - Default: false
Console.WriteLine("DisplayDocTitle : {0}", document.DisplayDocTitle);
// Whether to resize the document's window to fit the size of
// First displayed page - Default: false
Console.WriteLine("FitWindow : {0}", document.FitWindow);
// Whether to hide menu bar of the viewer application - Default: false
Console.WriteLine("HideMenuBar : {0}", document.HideMenubar);
// Whether to hide tool bar of the viewer application - Default: false
Console.WriteLine("HideToolBar : {0}", document.HideToolBar);
// Whether to hide UI elements like scroll bars
// And leaving only the page contents displayed - Default: false
Console.WriteLine("HideWindowUI : {0}", document.HideWindowUI);
// Document's page mode. How to display document on exiting full-screen mode.
Console.WriteLine("NonFullScreenPageMode : {0}", document.NonFullScreenPageMode);
// The page layout i.e. single page, one column
Console.WriteLine("PageLayout : {0}", document.PageLayout);
// How the document should display when opened
// I.e. show thumbnails, full-screen, show attachment panel
Console.WriteLine("PageMode : {0}", document.PageMode);
}
}
تشرح هذه الموضوعات كيفية تعيين خصائص نافذة المستند، وتطبيق العرض، وعرض الصفحة. لتعيين هذه الخصائص المختلفة:
الخصائص المتاحة هي:
يتم استخدام كل منها ووصفها في الشيفرة أدناه. يظهر مقتطف الشيفرة التالي كيفية تعيين الخصائص باستخدام Document class.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetDocumentWindowProperties()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "SetDocumentWindow.pdf"))
{
// Set different document properties
// Specify to position document's window - Default: false
document.CenterWindow = true;
// Predominant reading order; determines the position of page
// When displayed side by side - Default: L2R
document.Direction = Aspose.Pdf.Direction.R2L;
// Specify whether window's title bar should display document title
// If false, title bar displays PDF file name - Default: false
document.DisplayDocTitle = true;
// Specify whether to resize the document's window to fit the size of
// First displayed page - Default: false
document.FitWindow = true;
// Specify whether to hide menu bar of the viewer application - Default: false
document.HideMenubar = true;
// Specify whether to hide tool bar of the viewer application - Default: false
document.HideToolBar = true;
// Specify whether to hide UI elements like scroll bars
// And leaving only the page contents displayed - Default: false
document.HideWindowUI = true;
// Document's page mode. Specify how to display document on exiting full-screen mode.
document.NonFullScreenPageMode = Aspose.Pdf.PageMode.UseOC;
// Specify the page layout i.e. single page, one column
document.PageLayout = Aspose.Pdf.PageLayout.TwoColumnLeft;
// Specify how the document should display when opened
// I.e. show thumbnails, full-screen, show attachment panel
document.PageMode = Aspose.Pdf.PageMode.UseThumbs;
// Save PDF document
document.Save(dataDir + "SetDocumentWindow_out.pdf");
}
}
تدعم قارئات PDF مجموعة أساسية من 14 خطًا بحيث يمكن عرض المستندات بنفس الطريقة بغض النظر عن النظام الأساسي الذي يتم عرض المستند عليه. عندما يحتوي PDF على خط ليس من بين الخطوط الأربعة عشر الأساسية، يجب تضمين الخط في ملف PDF لتجنب استبدال الخط.
يدعم Aspose.PDF for .NET تضمين الخطوط في ملفات PDF الموجودة. يمكنك تضمين خط كامل أو مجموعة فرعية من الخط. لتضمين الخط، افتح ملف PDF باستخدام Document class. ثم استخدم Aspose.Pdf.Text.Font class لتضمين الخط في ملف PDF. لتضمين الخط الكامل، استخدم خاصية IsEmbeded لفئة Font؛ لاستخدام مجموعة فرعية من الخط، استخدم خاصية IsSubset.
يظهر مقتطف الشيفرة التالي كيفية تضمين خط في ملف PDF.
تحتوي بعض مستندات PDF على خطوط من مجموعة خطوط Adobe الخاصة. تُسمى الخطوط من هذه المجموعة “خطوط قياسية من النوع 1”. تتضمن هذه المجموعة 14 خطًا ويتطلب تضمين هذا النوع من الخطوط استخدام علامات خاصة أي Aspose.Pdf.Document.EmbedStandardFonts. فيما يلي مقتطف الشيفرة الذي يمكن استخدامه للحصول على مستند مع جميع الخطوط المضمنة بما في ذلك خطوط قياسية من النوع 1:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void EmbedFontsType1ToPdf()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Set EmbedStandardFonts property of document
document.EmbedStandardFonts = true;
// Iterate through each page
foreach (var page in document.Pages)
{
if (page.Resources.Fonts != null)
{
foreach (var pageFont in page.Resources.Fonts)
{
// Check if font is already embedded
if (!pageFont.IsEmbedded)
{
pageFont.IsEmbedded = true;
}
}
}
}
// Save PDF document
document.Save(dataDir + "EmbeddedFontsUpdated_out.pdf");
}
}
إذا كنت بحاجة إلى استخدام أي خط بخلاف الخطوط الأربعة عشر الأساسية المدعومة من Adobe Reader، يجب عليك تضمين وصف الخط أثناء إنشاء ملف PDF. إذا لم يتم تضمين معلومات الخط، سيأخذ Adobe Reader ذلك من نظام التشغيل إذا كان مثبتًا على النظام، أو سيقوم بإنشاء خط بديل وفقًا لوصف الخط في PDF.
يرجى ملاحظة أنه يجب تثبيت الخط المضمن على الجهاز المضيف أي في حالة الشيفرة التالية تم تثبيت خط “Univers Condensed” على النظام.
نستخدم خاصية IsEmbedded لفئة Font لتضمين معلومات الخط في ملف PDF. تعيين قيمة هذه الخاصية إلى “True” سيقوم بتضمين ملف الخط الكامل في PDF، مع العلم أنه سيزيد من حجم ملف PDF. فيما يلي مقتطف الشيفرة الذي يمكن استخدامه لتضمين معلومات الخط في PDF.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void EmbedFontWhileCreatingPdf()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Create a section in the Pdf object
var page = document.Pages.Add();
// Create a TextFragment
var fragment = new Aspose.Pdf.Text.TextFragment("");
// Create a TextSegment with sample text
var segment = new Aspose.Pdf.Text.TextSegment(" This is a sample text using Custom font.");
// Create and configure TextState
var ts = new Aspose.Pdf.Text.TextState();
ts.Font = Aspose.Pdf.Text.FontRepository.FindFont("Arial");
ts.Font.IsEmbedded = true;
segment.TextState = ts;
// Add the segment to the fragment
fragment.Segments.Add(segment);
// Add the fragment to the page
page.Paragraphs.Add(fragment);
// Save PDF Document
document.Save(dataDir + "EmbedFontWhileDocCreation_out.pdf");
}
}
عندما يحتوي مستند PDF على خطوط غير متاحة في المستند نفسه وعلى الجهاز، يقوم API باستبدال هذه الخطوط بالخط الافتراضي. عندما يكون الخط متاحًا (مثبت على الجهاز أو مضمن في المستند)، يجب أن يحتوي PDF الناتج على نفس الخط (يجب ألا يتم استبداله بالخط الافتراضي). يجب أن تحتوي قيمة الخط الافتراضي على اسم الخط (ليس مسار ملفات الخط). لقد قمنا بتنفيذ ميزة لتعيين اسم الخط الافتراضي أثناء حفظ مستند كـ PDF. يمكن استخدام مقتطف الشيفرة التالي لتعيين الخط الافتراضي:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetDefaultFontOnDocumentSave(string documentName, string newName)
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open PDF document
using (var fs = new FileStream(dataDir + "GetDocumentWindow.pdf", FileMode.Open))
{
using (var document = new Aspose.Pdf.Document(fs))
{
// Create PdfSaveOptions and specify Default Font Name
var pdfSaveOptions = new Aspose.Pdf.PdfSaveOptions
{
DefaultFontName = newName
};
// Save PDF document
document.Save(dataDir + "DefaultFont_out.pdf", pdfSaveOptions);
}
}
}
في حالة رغبتك في الحصول على جميع الخطوط من مستند PDF، يمكنك استخدام طريقة FontUtilities.GetAllFonts() المقدمة في Document class. يرجى مراجعة مقتطف الشيفرة التالي للحصول على جميع الخطوط من مستند PDF موجود:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetAllFontsFromPdf()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Get all fonts used in the document
var fonts = document.FontUtilities.GetAllFonts();
// Iterate through each font and print its name
foreach (var font in fonts)
{
Console.WriteLine(font.FontName);
}
}
}
يوفر Aspose.PDF for .NET طرقًا للحصول على إشعارات حول استبدال الخطوط للتعامل مع حالات استبدال الخطوط. تظهر مقتطفات الشيفرة أدناه كيفية استخدام الوظائف المقابلة.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void NotificationFontSubstitution()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Attach the FontSubstitution event handler
document.FontSubstitution += OnFontSubstitution;
// You can use lambda
// (oldFont, newFont) => Console.WriteLine(string.Format("Font '{0}' was substituted with another font '{1}'",
// oldFont.FontName, newFont.FontName));
// Save PDF document
document.Save(dataDir + "NotificationFontSubstitution_out.pdf");
}
}
تظهر طريقة OnFontSubstitution كما هو مدرج أدناه.
private static void OnFontSubstitution(Aspose.Pdf.Text.Font oldFont, Aspose.Pdf.Text.Font newFont)
{
// Handle the font substitution event here
Console.WriteLine(string.Format("Font '{0}' was substituted with another font '{1}'",
oldFont.FontName, newFont.FontName));
}
يمكن تحقيق ميزة تضمين الخطوط كمجموعة فرعية باستخدام خاصية IsSubset، ولكن في بعض الأحيان تريد تقليل مجموعة الخطوط المضمنة بالكامل إلى فقط المجموعات الفرعية المستخدمة في المستند. تحتوي Aspose.Pdf.Document على خاصية FontUtilities التي تتضمن طريقة SubsetFonts(FontSubsetStrategy subsetStrategy). في طريقة SubsetFonts()، يساعد المعامل subsetStrategy في ضبط استراتيجية المجموعة الفرعية. تدعم FontSubsetStrategy نوعين من استبدال الخطوط.
يظهر مقتطف الشيفرة التالي كيفية تعيين FontSubsetStrategy:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetFontSubsetStrategy()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// All fonts will be embedded as subset into document in case of SubsetAllFonts.
document.FontUtilities.SubsetFonts(Aspose.Pdf.FontSubsetStrategy.SubsetAllFonts);
// Font subset will be embedded for fully embedded fonts but fonts which are not embedded into document will not be affected.
document.FontUtilities.SubsetFonts(Aspose.Pdf.FontSubsetStrategy.SubsetEmbeddedFontsOnly);
// Save PDF document
document.Save(dataDir + "SetFontSubsetStrategy_out.pdf");
}
}
في بعض الأحيان، تريد تحديد ما هو عامل التكبير الحالي لمستند PDF. مع Aspose.Pdf، يمكنك معرفة القيمة الحالية وكذلك تعيين واحدة.
تسمح خاصية Destination لفئة GoToAction بالحصول على قيمة التكبير المرتبطة بملف PDF. وبالمثل، يمكن استخدامها لتعيين عامل تكبير الملف.
يظهر مقتطف الشيفرة التالي كيفية تعيين عامل التكبير لملف PDF.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetZoomFactor()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "SetZoomFactor.pdf"))
{
// Create GoToAction with a specific zoom factor
var action = new Aspose.Pdf.Annotations.GoToAction(new Aspose.Pdf.Annotations.XYZExplicitDestination(1, 0, 0, 0.5));
document.OpenAction = action;
// Save PDF document
document.Save(dataDir + "ZoomFactor_out.pdf");
}
}
يظهر مقتطف الشيفرة التالي كيفية الحصول على عامل التكبير لملف PDF.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetZoomFactor()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "Zoomed_pdf.pdf"))
{
// Create GoToAction object
if (document.OpenAction is Aspose.Pdf.Annotations.GoToAction action)
{
// Get the Zoom factor of PDF file
if (action.Destination is Aspose.Pdf.Annotations.XYZExplicitDestination destination)
{
System.Console.WriteLine(destination.Zoom); // Document zoom value;
}
}
}
}
يسمح Aspose.PDF بتعيين خصائص إعدادات طباعة الحوار لمستند PDF. يسمح لك بتغيير خاصية DuplexMode لمستند PDF والتي يتم تعيينها على simplex بشكل افتراضي. يمكن تحقيق ذلك باستخدام طريقتين مختلفتين كما هو موضح أدناه.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetPrintDialogPresetProperties()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
document.Pages.Add();
// Set duplex printing to DuplexFlipLongEdge
document.Duplex = Aspose.Pdf.PrintDuplex.DuplexFlipLongEdge;
// Save PDF document
document.Save(dataDir + "SetPrintDlgPresetProperties_out.pdf", Aspose.Pdf.SaveFormat.Pdf);
}
}
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SetPrintDialogPresetPropertiesUsingPdfContentEditor()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
string inputFile = dataDir + "input.pdf";
using (var ed = new Aspose.Pdf.Facades.PdfContentEditor())
{
// Bind PDF document
ed.BindPdf(inputFile);
// Check if the file has duplex flip short edge
if ((ed.GetViewerPreference() & Aspose.Pdf.Facades.ViewerPreference.DuplexFlipShortEdge) > 0)
{
Console.WriteLine("The file has duplex flip short edge");
}
// Change the viewer preference to duplex flip short edge
ed.ChangeViewerPreference(Aspose.Pdf.Facades.ViewerPreference.DuplexFlipShortEdge);
// Save PDF document
ed.Save(dataDir + "SetPrintDlgPropertiesUsingPdfContentEditor_out.pdf");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.