تدوير الختم حول نقطة المركز

تفاصيل التنفيذ

تتيح لك فئة الختم إضافة علامة مائية في ملف PDF. يمكنك تحديد الصورة التي سيتم إضافتها كختم باستخدام طريقة BindImage. تتيح لك طريقة SetOrigin تعيين نقطة الأصل للختم المضاف؛ هذه النقطة هي إحداثيات الزاوية السفلى اليسرى للختم. يمكنك أيضًا تعيين حجم الصورة باستخدام طريقة SetImageSize.

الآن، نرى كيف يمكن تدوير الختم حول مركز الختم. توفر فئة الختم خاصية تسمى Rotation. تقوم هذه الخاصية بتعيين أو الحصول على التدوير من 0 إلى 360 لمحتوى الختم. يمكننا تحديد أي قيمة تدوير من 0 إلى 360. من خلال تحديد قيمة التدوير، يمكننا تدوير الختم حول نقطة مركزه. إذا كان الختم كائنًا من نوع الختم، فيمكن تحديد قيمة التدوير كالتالي: aStamp.Rotation = 90. في هذه الحالة، سيتم تدوير الختم بزاوية 90 درجة حول مركز محتوى الختم. يوضح لك مقتطف الكود التالي كيفية تدوير الختم حول نقطة المركز:

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddRotatingStampToPdf()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();  

    // Create PdfFileInfo object to get height and width of the pages
    using (var fileInfo = new Aspose.Pdf.Facades.PdfFileInfo(dataDir + "RotatingStamp.pdf"))
    {
        // Create Stamp object
        var aStamp = new Aspose.Pdf.Facades.Stamp();

        // Bind image file with the Stamp object
        aStamp.BindImage(dataDir + "RotatingStamp.jpg");

        // Specify whether the stamp will be added as a background or not
        aStamp.IsBackground = false;

        // Specifies at which pages to add the watermark
        aStamp.Pages = new int[] { 1 };

        // Specifies the watermark rotation - rotate at 90 degrees
        aStamp.Rotation = 90;

        // Specifies the position of stamp - lower left corner of the stamp
        aStamp.SetOrigin(fileInfo.GetPageWidth(1) / 2, fileInfo.GetPageHeight(1) / 2);

        // Set the size of the watermark
        aStamp.SetImageSize(100, 100);

        // Open PDF document
        using (var document = new Aspose.Pdf.Document(dataDir + "RotatingStamp_out.pdf"))
        {
            // Create PdfFileStamp class to bind input and output files
            using (var stamper = new Aspose.Pdf.Facades.PdfFileStamp(document))
            {
                // Add the stamp in the PDF file
                stamper.AddStamp(aStamp);
            }
        }
    }
}