Closed MVKozlov closed 3 years ago
Register-PDFFont
must be within New-PDF
.
New-PDF -FilePath "$PSScriptRoot\Example01_Simple1.pdf" -PDFContent {
Register-PDFFont -FontName 'Verdana' -FontPath 'C:\Windows\fonts\verdana.ttf' -Encoding IDENTITY_H -Cached -Default
New-PDFText -Text 'Hello ', 'Привет !'
} -Show
New-PDF -FilePath "$PSScriptRoot\Example01_Simple2.pdf" -PDFContent {
Register-PDFFont -FontName 'Verdana' -FontPath 'C:\Windows\fonts\verdana.ttf' -Encoding IDENTITY_H -Cached -Default
New-PDFText -Text 'Hello ', 'Привет !'
} -Show
OK I understood.
but Register-PDFFont
really needs help text :)
While testing your example, I ran into another problem PS just closes instead of creating a file. It seems because it cannot write to C: \ (I am running your code from cmdline, not from script)
Should I create a separate issue?
So you mean when the file cannot be saved because you chose the wrong file path it should save to temp file instead? It's something to think about - but the last time I tried to detect this it wasn't working.
No, I mean it should not close powershell window but write error instead :) I found message like "Application closed because 0xc0000005" in application event log
I don't know if I can control this. I've seen this a few times and I couldn't "catch" it. It's like it crashes whole NET and closes PowerShell
Here's the same issue: https://github.com/EvotecIT/PSWritePDF/issues/14
Seems I found it
function New-InternalPDF {
....
catch
...
exit
...
}
You should use Write-Error
, throw
or return
instead of "exit" because exit closes current session
That's my mistake of using Exit instead of return. Will fix.
Please test new version
PS D:\> New-PDF -FilePath "C:\Example01_Simple2.pdf" -PDFContent {}
WARNING: New-InternalPDF - Terminating error: Exception calling ".ctor" with "1" argument(s): "Access to the path 'C:\Example01_Simple2.pdf' is denied."
Remove-EmptyValue: D:\PowerShell\Modules\PSWritePDF\0.0.12\PSWritePDF.psm1:267
Line |
267 | Remove-EmptyValue -Hashtable $Splat
| ~~~~~~
| Cannot bind argument to parameter 'Hashtable' because it is null.
If content not emply we gef a bunch of "You cannot call a method on a null-valued expression." I think throw will be better :) or there is a need $null checking
I've improved error handling.
still not perfect
PS D:\> New-PDF -FilePath "C:\Example01_Simple2.pdf" -PDFContent { New-PDFText -Text 'Hello ', 'Привет !' }
WARNING: New-InternalPDF - Terminating error: Exception calling ".ctor" with "1" argument(s): "Access to the path 'C:\Example01_Simple2.pdf' is denied."
InvalidOperation: D:\PowerShell\Modules\PSWritePDF\0.0.13\PSWritePDF.psm1:470
Line |
470 | $null = $Script:PDF.AddNewPage()
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| You cannot call a method on a null-valued expression.
MethodInvocationException: D:\PowerShell\Modules\PSWritePDF\0.0.13\PSWritePDF.psm1:472
Line |
472 | $Script:Document = [iText.Layout.Document]::new($Script:PDF)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling ".ctor" with "1" argument(s): "Object reference not set to an instance of an object."
InvalidOperation: D:\PowerShell\Modules\PSWritePDF\0.0.13\PSWritePDF.psm1:470
Line |
470 | $null = $Script:PDF.AddNewPage()
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| You cannot call a method on a null-valued expression.
MethodInvocationException: D:\PowerShell\Modules\PSWritePDF\0.0.13\PSWritePDF.psm1:472
Line |
472 | $Script:Document = [iText.Layout.Document]::new($Script:PDF)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling ".ctor" with "1" argument(s): "Object reference not set to an instance of an object."
InvalidOperation: D:\PowerShell\Modules\PSWritePDF\0.0.13\PSWritePDF.psm1:22
Line |
22 | $null = $Script:Document.Add($Object)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| You cannot call a method on a null-valued expression.
When I try to use new font feature I meet a problem when repeat pdf creation
May be I use it wrong ?