Publié Fri, 12 May 2023 07:41:06 GMT par Sebastian Schultz Regional Sales & Consultancy Manager - Indirect Sales Division
Hello,<br> <br> i use the following code to stamp a document: <pre class="linenums prettyprint">&#160; &#160; &#160; &#160;public static void SetStampOnPageWithBestPosition(Document document, string stampID, string sectionID, int layer, string stampTextValue) &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; DWPoint bestPosition; &#160; &#160; &#160; &#160; &#160; &#160; if (document == null) &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; MessageBox.Show(&quot;Document is null!&quot;); &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; else &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; document = document.GetDocumentFromSelfRelation(); &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Section section = document.Sections.FirstOrDefault(s =&gt; s.Id == sectionID); &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (section == null) &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; MessageBox.Show(&quot;Section is null&quot;); &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; else &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; section = section.GetSectionFromSelfRelation(); &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Page page = section.Pages.GetPagesFromNextBlockRelation().Page.FirstOrDefault(); &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (page == null) &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; MessageBox.Show(&quot;Page is null!&quot;); &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; else &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; bestPosition = page.PostToStampBestPositionRelationForDWPoint(new StampFormFieldValues() { StampId = stampID }); &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (bestPosition == null) &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; MessageBox.Show(&quot;BestPositon is null!&quot;); &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; else &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; StampPlacement stampPlacement = new StampPlacement() &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; StampId = stampID, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Layer = layer, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Location = bestPosition, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Field = new List&lt;FormFieldValue&gt;() &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; new FormFieldValue() &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Name = &quot;&lt;#1&gt;&quot;, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; TypedValue = new DocumentIndexFieldValue() &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; { &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; ItemElementName = ItemChoiceType.String, &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Item = stampTextValue &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; Annotation annotation = page.PostToStampRelationForAnnotation(stampPlacement); &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; &#160; &#160; } &#160; &#160; &#160; &#160; } </pre> <br> I run it with my document object: <pre class="linenums prettyprint">&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; SetStampOnPageWithBestPosition(document, &quot;7876f88d-6b76-4c3c-afb6-7af5df823cc6&quot;, &quot;1-1&quot;, 1, &quot;This is a test&quot;); </pre> <br> <br> As in the screenshot you can see the document has a section 1-1?!<br> <br> But everytime I get the error &quot;section is null&quot;?!<br> <br> Do you have any diea?<br> Is it possible to retreive the section id automatically via code?
Publié Fri, 12 May 2023 08:04:59 GMT par Simon H. Hellmann Toshiba Tec Germany Imaging Systems GmbH IT-Consultant Document Management Solutions
Hi Sebastian,&#160;<br> <br> your section id should be numeric, starting at 0.<br> In your example, you only have one section, so instead of &quot;1-1&quot; you should use &quot;0&quot;.<br> Same goes for page number, the first page is page 0.<br> <br> Hope this helps.&#160;<br> <br> Greetings from Germany,<br> Simon H. Hellmann<br> DocuWare System Consultant
Publié Fri, 12 May 2023 08:11:40 GMT par Sebastian Schultz Regional Sales & Consultancy Manager - Indirect Sales Division
Hey Simon,<br> <br> thank you in advance for your help.&#160;<br> <br> It works :)

You must be signed in to post in this forum.