Search code examples
filenamespptxgenjs

How to save file name with special characters (eg with < > : / \) using pptxgenjs


I am using pptxgenjs to create ppt and trying to save file name with special characters.

E.g.: Filename- Version:1_DataModel. By default, the microsoft power point is not allowing the certain special char in their file name.

Sample Code:

const saveFileName = `Version:1_${stateVariableValue}`;
pptx.writeFile({ fileName: saveFileName });

expected o/p: Version:1_DataModel

Actual o/p: Version_1_DataModel

When the file save automatically the : gets replaced with _. Then I tried to manually save the ppt with colon its showed the certain special chars are not allowed. Is there any way to achieve this?


Solution

  • The issue here isn't with pptxgenjs, but generally with the filesystem not allowing some special characters (as, e.g., described in What characters are forbidden in Windows and Linux directory names?).

    Since the filesystem doesn't allow some characters, there's no way to save a file name with those characters (unless you escape/replace them, as you've seen in the example above).