PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

RTF Writer: PreserveText - Create

Open rasamassen opened this issue 5 months ago • 3 comments

Description

Create PreserveText

Checklist:

  • [x] My CI is :green_circle:
  • [x] I have covered by unit tests my new code (check build/coverage for coverage report)
  • [x] I have updated the documentation to describe the changes
  • [x] I have updated the changelog

rasamassen avatar Sep 13 '25 05:09 rasamassen

Coverage Status

coverage: 96.622% (-0.1%) from 96.757% when pulling c58ea5e2bb65895a23fdbffbc775670576680d00 on rasamassen:preserveText into 0ab0b4940bc52c7183e82ab2fd55324607037a73 on PHPOffice:master.

coveralls avatar Sep 13 '25 05:09 coveralls

The description of preserveText in (Samples)[https://github.com/PHPOffice/PHPWord/blob/master/docs/usage/elements/preservetext.md] suggests that preserveText can be used to add Fields. This feels odd since there is already a field element? My current commit adds fields as described.

But what is the point of preserveText? preserveText sounds like it's supposed to be used for adding things like whitespace and special characters (like braces and slashes), but text already does that just fine. Instead of "preserving" the text, it currently adds fields.

So though I've built this like described, I'm confused what the purpose of the element is?

rasamassen avatar Oct 03 '25 17:10 rasamassen

You are correct that PreserveText isn't absolutely required, but it can make things a lot simpler.

$footer->addPreserveText('Page {PAGE} of {NUMPAGES}');

is much easier than adding a TextRun consisting of Text/Field/Text/Field.

oleibman avatar Nov 21 '25 21:11 oleibman