EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
289 stars 50 forks source link

Add tests for Watermark Image + Fix Heigh / Width for headers/footers #254

Open PrzemyslawKlys opened 2 months ago

PrzemyslawKlys commented 2 months ago

When using:

public static void Watermark_SampleImage1(string folderPath, bool openWord) {
    Console.WriteLine("[*] Creating standard document with Watermark Image 1");
    var imagePaths = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "Images");
    string filePath = System.IO.Path.Combine(folderPath, "Basic Document with Watermark Image 1.docx");

    using (WordDocument document = WordDocument.Create(filePath)) {
        document.AddParagraph("Section 0");
        document.AddHeadersAndFooters();

        var imagePathToAdd = System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg");
        var watermark = document.Sections[0].Header.Default.AddWatermark(WordWatermarkStyle.Image, imagePathToAdd);

        // TODO: Add handling for watermark image
        Console.WriteLine(watermark.Height);
        Console.WriteLine(watermark.Width);

        document.Save(false);
    }

    using (WordDocument document = WordDocument.Load(filePath)) {

        document.Save(openWord);
    }
}

The console lines throw an error since it only expects picture in document not headers/footers.

https://github.com/EvotecIT/OfficeIMO/blob/850f61707ddf23af1ea2f36e301c264ad3197e47/OfficeIMO.Examples/Word/Watermark/Watermark.SampleImage1.cs#L26-L27

PrzemyslawKlys commented 2 months ago

Linked PR: