In questo tutorial passo dopo passo, elaboreremo come inserire una filigrana bozza in PowerPoint Presentation in C# senza PowerPoint installato. Il formato PPTX è un formato ampiamente utilizzato per le presentazioni PowerPoint al giorno d’oggi, ma questo esempio è applicabile anche al PPT legacy per l’aggiunta di filigrane riservate PowerPoint.
Passaggi per aggiungere filigrana riservata a PowerPoint in C#
- Ottieni il pacchetto Aspose.Slides for .NET da NuGet.org
- Utilizza lo spazio dei nomi Aspose.Slides per caricare la presentazione e inserire la filigrana
- Impostare la licenza utilizzando il metodo SetLicense
- Carica la presentazione PowerPoint per inserire la filigrana nell’oggetto Presentation Class
- Accedi e ripeti attraverso Master Slide/s all’interno della presentazione
- Per ogni diapositiva master, aggiungi una forma automatica
- Inserisci bozza di testo riservato per la forma aggiunta TextFrame
- Formatta la forma e le proprietà testuali
- Applicare il blocco sulla forma aggiunta per proteggere la filigrana
- Salva la presentazione con filigrana
In precedenza, abbiamo esaminato Come proteggere la presentazione di PowerPoint in C# .NET in un altro argomento di istruzioni. Ma questo argomento descrive i passaggi per aggiungere una filigrana riservata in PowerPoint in C#. Non sei dipendente da Microsoft PowerPoint o Interop per utilizzare questa funzionalità e puoi eseguire questo codice senza problemi su tutte le piattaforme.
Inoltre, la funzione di blocco della forma è una funzionalità unica offerta da Aspose.Slides che non è nemmeno disponibile pubblicamente in PowerPoint. È possibile salvaguardare i diritti di proprietà intellettuale della presentazione utilizzando la funzione di blocco e applicandola alla forma della filigrana e impedendo a chiunque di modificarla o rimuoverla in PowerPoint.
Codice per aggiungere una bozza di filigrana in PowerPoint in C# senza interoperabilità
using System; | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
namespace WatermarkPPTXinC_Sharp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string PathForWatermarkPptFile = @".\"; | |
//Loading the product license | |
License license = new License(); | |
license.SetLicense(PathForWatermarkPptFile+"Conholdate.Total.Product.Family.lic"); | |
//Load the presentation to insert watermark | |
Presentation WatermarkPptxPresentation = new Presentation(PathForWatermarkPptFile + "Draft.pptx"); | |
//Accessing the master slides for adding watermark | |
foreach (IMasterSlide masterSlide in WatermarkPptxPresentation.Masters) | |
{ | |
//Adding a Ppt watermark shape | |
IAutoShape PptxWatermark = masterSlide.Shapes.AddAutoShape(ShapeType.Rectangle, | |
WatermarkPptxPresentation.SlideSize.Size.Width / 2 - 50, | |
WatermarkPptxPresentation.SlideSize.Size.Height / 2 - 50, | |
200, 50); | |
//Setting rotation angle and fill type of the shape | |
PptxWatermark.Rotation = 325; | |
PptxWatermark.FillFormat.FillType = FillType.NoFill; | |
//Adding Text frame with watermark text | |
ITextFrame WatermarkText = PptxWatermark.AddTextFrame("Confidential Draft"); | |
//Setting textual properties of the watermark text | |
IPortionFormat WatermarkTextFormat = WatermarkText.Paragraphs[0].Portions[0].PortionFormat; | |
WatermarkTextFormat.FontBold = NullableBool.True; | |
WatermarkTextFormat.FontItalic = NullableBool.True; | |
WatermarkTextFormat.FontHeight = 20; | |
WatermarkTextFormat.FillFormat.FillType = FillType.Solid; | |
WatermarkTextFormat.FillFormat.SolidFillColor.Color = System.Drawing.Color.Red; | |
//Locking Pptx watermark shape to be uneditable in PowerPoint | |
PptxWatermark.AutoShapeLock.TextLocked=true; | |
PptxWatermark.AutoShapeLock.SelectLocked = true; | |
PptxWatermark.AutoShapeLock.PositionLocked = true; | |
} | |
//Saving the watermark PowerPoint presentation file | |
WatermarkPptxPresentation.Save(PathForWatermarkPptFile+"WatermarkPresentation.pptx", | |
SaveFormat.Pptx); | |
} | |
} | |
} |
L’esempio può essere usato in qualsiasi ambiente applicativo .NET usando il codice C#, sia che si tratti di un’applicazione Web ASP.NET, di un’applicazione Windows Form o basata su console. Puoi anche usarlo sul tuo computer di lavoro locale o su qualsiasi server su cui è installato .NET Framework.