PDF FROM DOCX

Certified Senior Developer

I am generating pdf document but document  may contains special characters like (’,>,<,*,",) so i am getting error,

is there any way to resolve this ?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    DOCX is a XML document. You need to XML escape these characters.

  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

    a!localVariables(
      local!searchString: cons!GAI_XML_CHARS_TO_ESCAPE,
      local!replaceString: {
        "&",
        "'",
        "<",
        ">",
        """
      },
      local!indexFirstCharacter: if(
        a!isNullOrEmpty(ri!charsToEscape),
        null,
        cast(
          typeof(0),
          wherecontains(
            tostring(index(ri!charsToEscape, 1, null)),
            touniformstring(local!searchString)
          )
        )
      ),
      local!replaceFirstChar: if(
        a!isNullOrEmpty(ri!charsToEscape),
        null,
        regexreplaceall(
          tostring(
            local!searchString[local!indexFirstCharacter]
          ),
          ri!inputString,
          tostring(
            local!replaceString[local!indexFirstCharacter]
          )
        )
      ),
      local!nextCharsToEscape: remove(ri!charsToEscape, 1),
      if(
        a!isNullOrEmpty(local!nextCharsToEscape),
        local!replaceFirstChar,
        rule!GAI_Common_EscapeXMLCharacters(
          inputString: local!replaceFirstChar,
          charsToEscape: local!nextCharsToEscape
        )
      )
    )

    i am using above code to escape char, but in PDF instead of & showing &amp; 

Reply
  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

    a!localVariables(
      local!searchString: cons!GAI_XML_CHARS_TO_ESCAPE,
      local!replaceString: {
        "&",
        "'",
        "<",
        ">",
        """
      },
      local!indexFirstCharacter: if(
        a!isNullOrEmpty(ri!charsToEscape),
        null,
        cast(
          typeof(0),
          wherecontains(
            tostring(index(ri!charsToEscape, 1, null)),
            touniformstring(local!searchString)
          )
        )
      ),
      local!replaceFirstChar: if(
        a!isNullOrEmpty(ri!charsToEscape),
        null,
        regexreplaceall(
          tostring(
            local!searchString[local!indexFirstCharacter]
          ),
          ri!inputString,
          tostring(
            local!replaceString[local!indexFirstCharacter]
          )
        )
      ),
      local!nextCharsToEscape: remove(ri!charsToEscape, 1),
      if(
        a!isNullOrEmpty(local!nextCharsToEscape),
        local!replaceFirstChar,
        rule!GAI_Common_EscapeXMLCharacters(
          inputString: local!replaceFirstChar,
          charsToEscape: local!nextCharsToEscape
        )
      )
    )

    i am using above code to escape char, but in PDF instead of & showing &amp; 

Children