The DRAFT watermark is now added to the master slides with a lighter color

This commit is contained in:
2025-03-10 20:15:04 +01:00
parent deeed2a735
commit e8a41e9206
+54 -62
View File
@@ -40,41 +40,33 @@ export const DraftButtons: React.FC = () => {
setIsProcessing(true);
try {
await PowerPoint.run(async (context) => {
// Get all slides in the presentation
const slides = context.presentation.slides;
slides.load("items");
// Get the slide masters collection
const masters = context.presentation.slideMasters;
masters.load("items");
await context.sync();
// Get a reference slide to determine dimensions
// Since we can't access presentation width/height directly
if (slides.items.length === 0) {
setStatusMessage("No slides found in the presentation.");
setStatusType("warning");
if (masters.items.length === 0) {
setStatusMessage("Could not access slide masters.");
setStatusType("error");
return;
}
// Process counter
let processedSlides = 0;
let errorSlides = 0;
let processedMasters = 0;
let errorMasters = 0;
// Process each slide
for (let i = 0; i < slides.items.length; i++) {
// Process each slide master (usually there's just one)
for (let i = 0; i < masters.items.length; i++) {
try {
const slide = slides.items[i];
const master = masters.items[i];
//const positionFromTop = slideHeight - 23;
// Create the textbox on the master slide
const textBox = master.shapes.addTextBox("");
// Create the textbox - make sure it spans the full width of the slide
// This is important for proper centering
const textBox = slide.shapes.addTextBox("");
// Make it span most of the width of the slide (90% centered)
// This ensures we have room for the text to be centered
//const textBoxWidth = slideWidth * 1; // 0.9
textBox.left = 0; // Center it horizontally
textBox.top = 0;
textBox.width = 960;
textBox.height = 540; // Smaller height for footer text
textBox.height = 540;
await context.sync();
@@ -103,12 +95,12 @@ export const DraftButtons: React.FC = () => {
textBox.textFrame.textRange.font.bold = true;
textBox.textFrame.verticalAlignment = "MiddleCentered"
// Set the color to RGB(218, 19, 53)
// Set the color to RGB(255, 233, 232)
// Different APIs may need different color formats
textBox.textFrame.textRange.font.color = "#DA1335";
textBox.textFrame.textRange.font.color = "#FFE9E8";
// Set the text
textBox.textFrame.textRange.text = "DRAFT";
// Set the text
textBox.textFrame.textRange.text = "DRAFT";
} catch (fontError) {
console.error("Error setting font properties:", fontError);
// Even if we can't set the font properties exactly, continue with default font
@@ -118,25 +110,25 @@ export const DraftButtons: React.FC = () => {
textBox.name = "DraftWatermark";
await context.sync();
processedSlides++;
processedMasters++;
}
} catch (slideError) {
console.error(`Error processing slide ${i+1}:`, slideError);
errorSlides++;
// Continue to the next slide
} catch (masterError) {
console.error(`Error processing master ${i+1}:`, masterError);
errorMasters++;
// Continue to the next master
continue;
}
}
// Report results
if (processedSlides > 0) {
setStatusMessage(`Added draft watermark to ${processedSlides} slides.`);
if (processedMasters > 0) {
setStatusMessage(`Added draft watermark to ${processedMasters} master slide${processedMasters > 1 ? 's' : ''}.`);
setStatusType("success");
} else if (errorSlides > 0) {
setStatusMessage(`Failed to add markings. Errors on ${errorSlides} slides.`);
} else if (errorMasters > 0) {
setStatusMessage(`Failed to add markings. Errors on ${errorMasters} master slide${errorMasters > 1 ? 's' : ''}.`);
setStatusType("error");
} else {
setStatusMessage("No slides found to add draft watermark.");
setStatusMessage("No master slides found to add draft watermark.");
setStatusType("warning");
}
@@ -155,63 +147,63 @@ export const DraftButtons: React.FC = () => {
try {
await PowerPoint.run(async (context) => {
try {
// Get all slides in the presentation
const slides = context.presentation.slides;
slides.load("items");
// Get the slide masters collection
const masters = context.presentation.slideMasters;
masters.load("items");
await context.sync();
if (slides.items.length === 0) {
setStatusMessage("No slides found in the presentation.");
setStatusType("warning");
if (masters.items.length === 0) {
setStatusMessage("Could not access slide masters.");
setStatusType("error");
return;
}
// Process counter
let processedSlides = 0;
let errorSlides = 0;
let processedMasters = 0;
let errorMasters = 0;
let removedCount = 0;
// Process each slide
for (let i = 0; i < slides.items.length; i++) {
// Process each master slide
for (let i = 0; i < masters.items.length; i++) {
try {
const slide = slides.items[i];
const master = masters.items[i];
// Load all shapes on the slide
slide.shapes.load("items");
// Load all shapes on the master slide
master.shapes.load("items");
await context.sync();
// Find shapes with name "ConfidentialMarking"
for (let j = 0; j < slide.shapes.items.length; j++) {
const shape = slide.shapes.items[j];
// Find shapes with name "DraftWatermark"
for (let j = 0; j < master.shapes.items.length; j++) {
const shape = master.shapes.items[j];
shape.load("name");
await context.sync();
if (shape.name === "DraftWatermark") {
// Delete the confidential marking shape
// Delete the draft watermark shape
shape.delete();
removedCount++;
}
}
await context.sync();
processedSlides++;
} catch (slideError) {
console.error(`Error processing slide ${i+1}:`, slideError);
errorSlides++;
// Continue to the next slide
processedMasters++;
} catch (masterError) {
console.error(`Error processing master slide ${i+1}:`, masterError);
errorMasters++;
// Continue to the next master slide
continue;
}
}
// Report results
if (removedCount > 0) {
setStatusMessage(`Removed ${removedCount} draft watermark from ${processedSlides} slides.`);
setStatusMessage(`Removed ${removedCount} draft watermark${removedCount > 1 ? 's' : ''} from ${processedMasters} master slide${processedMasters > 1 ? 's' : ''}.`);
setStatusType("success");
} else if (errorSlides > 0) {
setStatusMessage(`Failed to remove draft watermarks. Errors on ${errorSlides} slides.`);
} else if (errorMasters > 0) {
setStatusMessage(`Failed to remove draft watermarks. Errors on ${errorMasters} master slide${errorMasters > 1 ? 's' : ''}.`);
setStatusType("error");
} else {
setStatusMessage("No daft watermark found to remove.");
setStatusMessage("No draft watermark found to remove.");
setStatusType("info");
}
} catch (innerError) {