تحديث الروابط في PDF
تعمل مقتطفات الشيفرة التالية أيضًا مع مكتبة Aspose.PDF.Drawing .
تحديث الروابط في ملف PDF
كما تم مناقشته في إضافة رابط تشعبي في ملف PDF، فإن فئة LinkAnnotation تجعل من الممكن إضافة روابط في ملف PDF. هناك أيضًا فئة مشابهة تُستخدم للحصول على الروابط الموجودة داخل ملفات PDF. استخدم هذا إذا كنت بحاجة إلى تحديث رابط موجود. لتحديث رابط موجود:
قم بتحميل ملف PDF.
انتقل إلى صفحة معينة في ملف PDF.
حدد وجهة الرابط باستخدام خاصية Destination لكائن GoToAction .
يتم تحديد الصفحة الوجهة باستخدام مُنشئ XYZExplicitDestination .
تعيين هدف الرابط إلى صفحة في نفس المستند
تظهر مقتطفات الشيفرة التالية كيفية تحديث رابط في ملف PDF وتعيين هدفه إلى الصفحة الثانية من المستند.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void UpdateLinkAnnotation ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_LinksActions ();
// Open PDF document
using ( var document = new Aspose . Pdf . Document ( dataDir + "UpdateLinks.pdf" ))
{
// Get the first link annotation from first page of document
var linkAnnot = ( Aspose . Pdf . Annotations . LinkAnnotation ) document . Pages [ 1 ]. Annotations [ 1 ];
// Modification link: change link destination
var goToAction = ( Aspose . Pdf . Annotations . GoToAction ) linkAnnot . Action ;
// Specify the destination for link object
// The first parameter is document object, second is destination page number.
// The 5ht argument is zoom factor when displaying the respective page. When using 2, the page will be displayed in 200% zoom
goToAction . Destination = new Aspose . Pdf . Annotations . XYZExplicitDestination ( 1 , 1 , 2 , 2 );
// Save PDF document
document . Save ( dataDir + "UpdateLinks_out.pdf" );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void UpdateLinkAnnotation ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_LinksActions ();
// Open PDF document
using var document = new Aspose . Pdf . Document ( dataDir + "UpdateLinks.pdf" );
// Get the first link annotation from first page of document
var linkAnnot = ( Aspose . Pdf . Annotations . LinkAnnotation ) document . Pages [ 1 ]. Annotations [ 1 ];
// Modification link: change link destination
var goToAction = ( Aspose . Pdf . Annotations . GoToAction ) linkAnnot . Action ;
// Specify the destination for link object
// The first parameter is document object, second is destination page number.
// The 5ht argument is zoom factor when displaying the respective page. When using 2, the page will be displayed in 200% zoom
goToAction . Destination = new Aspose . Pdf . Annotations . XYZExplicitDestination ( 1 , 1 , 2 , 2 );
// Save PDF document
document . Save ( dataDir + "UpdateLinks_out.pdf" );
}
تعيين وجهة الرابط إلى عنوان ويب
لتحديث الرابط التشعبي بحيث يشير إلى عنوان ويب، قم بإنشاء كائن GoToURIAction ومرره إلى خاصية Action لفئة LinkAnnotation. تُظهر مقتطفات الشيفرة التالية كيفية تحديث رابط في ملف PDF وتعيين هدفه إلى عنوان ويب.
تعيين هدف الرابط إلى ملف PDF آخر
تظهر مقتطفات الشيفرة التالية كيفية تحديث رابط في ملف PDF وتعيين هدفه إلى ملف PDF آخر.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void UpdateLinkAnnotation ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_LinksActions ();
// Open PDF document
using ( var document = new Aspose . Pdf . Document ( dataDir + "UpdateLinks.pdf" ))
{
var linkAnnot = ( Aspose . Pdf . Annotations . LinkAnnotation ) document . Pages [ 1 ]. Annotations [ 1 ];
var goToR = ( Aspose . Pdf . Annotations . GoToRemoteAction ) linkAnnot . Action ;
// Next line update destination, do not update file
goToR . Destination = new Aspose . Pdf . Annotations . XYZExplicitDestination ( 2 , 0 , 0 , 1.5 );
// Next line update file
goToR . File = new Aspose . Pdf . FileSpecification ( dataDir + "input.pdf" );
// Save PDF document
document . Save ( dataDir + "SetTargetLink_out.pdf" );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void UpdateLinkAnnotation ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_LinksActions ();
// Open PDF document
using var document = new Aspose . Pdf . Document ( dataDir + "UpdateLinks.pdf" );
var linkAnnot = ( Aspose . Pdf . Annotations . LinkAnnotation ) document . Pages [ 1 ]. Annotations [ 1 ];
var goToR = ( Aspose . Pdf . Annotations . GoToRemoteAction ) linkAnnot . Action ;
// Next line update destination, do not update file
goToR . Destination = new Aspose . Pdf . Annotations . XYZExplicitDestination ( 2 , 0 , 0 , 1.5 );
// Next line update file
goToR . File = new Aspose . Pdf . FileSpecification ( dataDir + "input.pdf" );
// Save PDF document
document . Save ( dataDir + "SetTargetLink_out.pdf" );
}
تحديث لون نص LinkAnnotation
لا تحتوي التعليقات التوضيحية للرابط على نص. بدلاً من ذلك، يتم وضع النص في محتويات الصفحة تحت التعليق التوضيحي. لذلك، لتغيير لون النص، استبدل لون نص الصفحة بدلاً من محاولة تغيير لون التعليق التوضيحي. تُظهر مقتطفات الشيفرة التالية كيفية تحديث لون التعليق التوضيحي للرابط في ملف PDF.