StructuredDocumentTag "PlainText" and placeholder text

Hi,

just struggled a bit with the placeholder text for “plain text” input fields: in a german word installation, they have the placeholder text “Klicken oder tippen Sie hier, um Text einzugeben.”. But when creating a StructuredDocumentTag using Aspose.Words, it has the default text “Click here to enter text”.

It would be perfect if Aspose.Words could create those placeholders based on the current locale: doc.Styles.DefaultFont.LocaleId = (int)EditingLanguage.GermanGermany;

I found a workaround, based on https://reference.aspose.com/net/words/aspose.words.markup/structureddocumenttag/properties/placeholder

Unfortunately, those placeholders will have black font instead of gray.

I managed to set the the style to the builtin style “Placeholder text”, and now I have german texts in the expected color.

Here is the full code:
StructuredDocumentTag textBox2 = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);

  GlossaryDocument glossaryDoc = doc.GlossaryDocument;

  BuildingBlock substituteBlock = new BuildingBlock(glossaryDoc);
  substituteBlock.Name = "Custom Placeholder";
  substituteBlock.AppendChild(new Section(glossaryDoc));
  substituteBlock.FirstSection.AppendChild(new Body(glossaryDoc));

  Paragraph p = substituteBlock.FirstSection.Body.AppendParagraph("Text eingeben.");
  p.Runs[0].Font.StyleIdentifier = StyleIdentifier.PlaceholderText;

  glossaryDoc.AppendChild(substituteBlock);

  textBox2.PlaceholderName = "Custom Placeholder";

  docBuilder.InsertNode(textBox2);

Attached is also a full sample.
AsposeWordsPlaceholder.zip (4.9 MB)

Is there a better workaround for german textbox texts?

Maybe someone finds this post helpful - at least I did not find this information ;-), and maybe the Aspose guys have some idea to improve this. It would be ideal if the text box has the correct localized text by default.

Best regards

Wolfgang

One more question about those placeholders: when saving to PDF using “PdfSaveOptions.PreserveFormFields = true”, the resulting PDF contains the placeholder text in the textbox. You have to delete it first before editing the field. Is this the expected behavior?

Best regards

Wolfgang

@wknauf

You are setting the style of paragraph correctly.

Yes, it is expected behavior. The PdfSaveOptions.PreserveFormFields preserves Microsoft Word form fields in output PDF. It does not preserve content controls in output PDF.

Thanks for the reply!

Wolfgang