Closed mc1903 closed 1 year ago
Hi Martin,
To what end? Can you provide a sample of what you're trying to achieve?
To my knowledge, in order to display an image you should use the Image cmdlet. This will ensure it's displayed correctly with the correct styling options applied. Here's an example:
[CmdletBinding()]
param (
[System.String[]] $Format = 'Html',
[System.String] $Path = '~\Desktop',
[System.Management.Automation.SwitchParameter] $PassThru
)
Import-Module PScribo -Force -Verbose:$false
$test = Document -Name 'Test' {
Image -Path 'byah.jpg' -Text 'BYAH'
}
$test | Export-Document -Path $Path -Format $Format -PassThru:$PassThru
Example output:
Hi Chris,
Thanks for your help, I thought I had the basics of Image
& Paragraph
; but I cannot quite get what I want.
Example code:
[CmdletBinding()]
param (
[System.String[]] $Format = 'Word',
[System.String] $Path = '~\Desktop',
[System.Management.Automation.SwitchParameter] $PassThru
)
Import-Module PScribo -Force -Verbose:$false
$doc = Document -Name 'Testing' {
Paragraph -Style Heading1 "Errors & Warnings"
BlankLine
Image -Path 'error-icon.jpg' -Text 'Error' -Align 'Left' -Percent 75
Paragraph -Style Normal "Some error text here"
BlankLine
Image -Path 'warning-icon.jpg' -Text 'Warning' -Align 'Left' -Percent 75
Paragraph -Style Normal "Some warning text here"
BlankLine
}
$doc | Export-Document -Path $Path -Format $Format -PassThru:$PassThru
Gets me the Image
on one line and the Paragraph
text on the line below:
What I would prefer is to put the Image
& Paragraph
text on the same line:
If I can do that with a Table, similar to this, that would also be OK. (I probably wouldn't bother with the table header row or gridlines)
Any thoughts?
Cheers Martin
I could be wrong but I don't believe that's currently possible. As a workaround, you could leverage built-in styles capability to do something like this:
[CmdletBinding()]
param (
[System.String[]] $Format = 'Html',
[System.String] $Path = '~\Desktop',
[System.Management.Automation.SwitchParameter] $PassThru
)
Import-Module PScribo -Force -Verbose:$false
$doc = Document -Name 'Testing' {
# You can define colors by name...
Style -Name 'Error' -BackgroundColor red
Style -Name 'Warning' -BackgroundColor yellow
# or you can use hex color codes...
Style -Name 'Good' -BackgroundColor 00ff00
$services = Get-Service | Select-Object Name, StartType, Status -Last 5
# You can highlight the entire row a specific color
$services | Where-Object { $_.'Status' -eq 'Running'} | Set-Style -Style Good
# Or you can change the color of a specific cell in the table
$services | Where-Object { $_.'StartType' -eq 'Disabled'} | Set-Style -Style Warning -Property 'StartType'
$services | Where-Object { $_.'Status' -eq 'Stopped'} | Set-Style -Style Error -Property 'Status'
$services | Table
}
$doc | Export-Document -Path $Path -Format $Format -PassThru:$PassThru
Thanks again Chris.
I didn't think it was currently possible. My original question to Iain was more for clarification, in case I had just missed an option/method.
I did look at using similar styles in tables, but I really wanted to combine the status image icon with some paragraph text on the same line, as it looked a bit cleaner. I will stick with my 2 line Image & Paragraph method for now.
Images in tables or the ability to place multiple images at the same horizontal position on a page, would be very helpful. The project I am working on has lots of charts (generated by PScriboCharts) and the ability to place 2 or 3 pie charts at the same position on a page would help to keep the report much shorter.
I will leave this issue open, as an informal FR, for now.
Cheers M
I don't think this is currently possible. Historically, you could have embedded inline HTML (if that was the only format you were interested in) but this is now escaped :(
The Paragraph/Text implementation could be expanded to allow embedding images, but I feel that generating consistent output between the HTML and Word plugins would be incredibly difficult.
Thanks for the feedback Iain.
Hi Iain,
Is it possible to place an image within a cell of a table or at the beginning of a line of paragraph text?
Thanks Martin