Rotación de sello alrededor del punto central

Detalles de implementación

La clase Stamp le permite agregar una marca de agua en un archivo PDF. Puede especificar la imagen que se agregará como un sello utilizando el método BindImage. El método SetOrigin le permite establecer el origen del sello agregado; este origen son las coordenadas inferiores izquierdas del sello. También puede establecer el tamaño de la imagen utilizando el método SetImageSize.

Ahora, veremos cómo se puede rotar el sello alrededor del centro del sello. La clase Stamp proporciona una propiedad llamada Rotation. Esta propiedad establece o obtiene la rotación de 0 a 360 del contenido del sello. Podemos especificar cualquier valor de rotación de 0 a 360. Al especificar el valor de rotación, podemos rotar el sello alrededor de su punto central. Si un Sello es un objeto del tipo Stamp, entonces el valor de rotación se puede especificar como aStamp.Rotation = 90. En este caso, el sello se rotará 90 grados alrededor del centro del contenido del sello. El siguiente fragmento de código le muestra cómo rotar el sello alrededor del punto central:

// 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);
            }
        }
    }
}