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
261 stars 47 forks source link

Image layout options #210

Closed stefanstranger closed 4 months ago

stefanstranger commented 4 months ago

I'm using the PowerShell Module PSWriteOffice for Word document creation and I'm trying to insert an image using the following code:

elseif ($Paragraph.Text -like "<TODO: Insert  Image>") {
            $Paragraph.Text = ''
            $Paragraph.AddImage("C:\temp\image.png")
            $Paragraph.ParagraphAlignment = 'Center'
            $Paragraph.IndentationBefore = 1
            $Paragraph.IndentationAfter = 1
        }

But I need to apply the following layout configuration.

image

How can this be done programmatically?

Regards, Stefan Stranger

PrzemyslawKlys commented 4 months ago

Hi,

I need to update PSWriteOffice to newest library version, because we already support those layouts in newest one

var pargraphWithImage = paragraph.AddImage(file, 100, 100, WrapTextImage.InLineWithText, "Przemek and Kulek on an image");

In PowerShell it will be like

$pargraphWithImage = $paragraph.AddImage(file, 100, 100, [WrapTextImage]::InLineWithText, "Przemek and Kulek on an image");

Probably the WrapTextImage will need a full type or using to work. New version also allows switching between TextWrappings

image

So as soon as the image is added you can also change it on the fly. I'm neglegtic powershell version a bit, but OfficeIMO alone is hard to manage ;)

stefanstranger commented 4 months ago

Hi Przemysław,

Thanks for your fast response. Do I understand I need to wait for you to update the PowerShell module to use the latest library?

When I try to do it using the existing library I get the following error:

$Paragraph.Image.WrapText = 'BehindText'
SetValueInvocationException: Exception setting "WrapText": "This needs to be implemented properly!"

Regards, Stefan Stranger

PrzemyslawKlys commented 4 months ago

Ye, I'll try to release it tonight. I've not updated the library for a bit. Also keep in mind that when you switch between different Wraps (Inline vs Anchor) it looses certain prroperties. Inline has minimal set properties because it's kind of bound to paragraph, and the rest is basically anchored, so you would need to play with positioning after doing changes like that.

PrzemyslawKlys commented 4 months ago

I've released new version - you can try it out.

stefanstranger commented 4 months ago

@PrzemyslawKlys

I tried to update the PSWriteOffice module via the PowerShell gallery but got this error message: Install-Package: Authenticode issuer 'CN=Przemysław Kłys EVOTEC, O=Przemysław Kłys EVOTEC, L=Mikołów, C=PL' of the new module 'PSWriteOffice' with version '0.2.0' from root certificate authority 'CN=DigiCert Trusted Root G4, OU=www.digicert.com, O=DigiCert Inc, C=US' is not matching with the authenticode issuer 'CN=Przemysław Kłys EVOTEC, O=Przemysław Kłys EVOTEC, L=Katowice, S=Śląskie, C=PL' of the previously-installed module 'PSWriteOffice' with version '0.1.0' from root certificate authority 'CN=DigiCert Assured ID Root CA, OU=www.digicert.com, O=DigiCert Inc, C=US'. If you still want to install or update, use -SkipPublisherCheck parameter.

PrzemyslawKlys commented 4 months ago

Install-Module PSWriteOffice -Force -Verbose -SkipPublisherCheck

I changed certificate some time ago, as my last one expired and there's no other way around it.

stefanstranger commented 4 months ago

Ok I did the use the -skippublishercheck option to resolve this.

Should I ask internally on how above error can be fixed?

Stefan Stranger [MSFT]

PrzemyslawKlys commented 4 months ago

The error above is not really an error. Once you install module with certain certificate it's there to protect you a bit from changes or dropping non-signed versions. However when my 3 year certificate expired and it changes - that is the cert warning you get. I wish it was easier, but you can either delete the old versions and do install-module without skippublishercheck, or use skippublishercheck. Otherwise that's the warning you get.

In theory maybe if the whole issuer/subject name would be the same it could work, but DigiCert gave me new data so it's a mismatch.