I have a situation where I want to create a template in word, fill it in using aspose.words except I want to leave some fields blank. These fields are used by a later process.
Thanks for your inquiry. Aspose.Words uses our own Rendering Engine to layout documents into pages. The Aspose.Words.Layout namespace provides
classes that allow to access information such as on what page and where
on a page particular document elements are positioned, when the document
is formatted into pages. Please read about LayoutCollector and
LayoutEnumerator from here:
I also need to be able to tell that system about the unfilled fields either by name or by X,Y location.
Please use following code example to get the X,Y location of a Field.
Document doc = new Document(MyDir + “in.docx”);
LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);
var collection = doc.GetChildNodes(NodeType.FieldStart, true);
foreach (FieldStart fStart in collection)
var renderObject = layoutCollector.GetEntity(fStart);
layoutEnumerator.Current = renderObject;
RectangleF location = layoutEnumerator.Rectangle;
Is there an elegant way in aspose.total to have fields in a word form and “convert” them to fields in a PDF form?
Could you please share some more detail about this query along with input Word document and expected output Pdf? We will then provide you more information about your query.
Tahir, excellent reply thank you for that information.
The control used in your sample document is a content control (structured document tag). PreserveFormFields option supports the legacy form fields and not the content controls.
You can use form fields in your case or let us know if you want to use content controls in any case. We will log a new feature request in case of content controls because this feature is not supported at the moment.
Muhammad, thank you for the reply. Yes, in my case the older form fields are less than ideal so please put in that feature request.
This issue has been logged into our issue tracking system as WORDSNET-11148. We will keep you updated on this issue in this thread.
As far as order and X, Y, Width and Height etc. are concerned, these should remain the same because content controls are rendered like shapes, but still there is no guaranty if this is a reliable solution until preserve content controls feature is available.
- Set PdfSaveOptions.PreserveFormFields to true when saving to pdf, to save the SDT nodes as AcroFrom fields in PDF.
- Use StructuredDocumentTag.Id to specify the AcroForm name.