Content getting truncated when TypeTexting to word document

Viewed 80

When I try to TypeText a long text file to word document the content gets truncated by the 3200 character, with a total of 27 pages, even though the full content is something like 6000 characters and 60 pages long when I paste manually. Here is my code:

$Source1 = Get-Content -Path FileSystem::C:\Users\My_user\Desktop\file.txt -Raw;
$Word = New-Object -ComObject Word.Application;
$Word.Visible = $True;
$Document = $Word.Documents.Add();
$Selection = $Word.Selection;
$Selection.TypeText($source1);
1 Answers

The official documentation doesn't mention a length limit, although this forum post suggests that it is 64KB.

While that doesn't explain your problem with only 6,000 characters, consider using the .InsertFile method instead (untested):

$Selection.InsertFile('C:\Users\My_user\Desktop\file.txt')
Related