CommentsNoPdf.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Linq;
  9. using GrapeCity.Documents.Word;
  10. using GrapeCity.Documents.Word.Layout;
  11.  
  12. namespace DsWordWeb.Demos
  13. {
  14. // This sample is identical to Comments. The only difference is
  15. // that in PDF export, comments are ignored. This is achieved by
  16. // providing a GetPdfConversionOptions method used by the sample
  17. // browser's infrastructure when it calls the SaveAsPdf method
  18. // on the generated document.
  19. public class CommentsNoPdf
  20. {
  21. public GcWordDocument CreateDocx()
  22. {
  23. var user1 = "Jaime Smith"; // user name for comments' author
  24. var user2 = "Jane Donahue"; // user name for comments' author
  25.  
  26. var doc = new GcWordDocument();
  27.  
  28. var pars = doc.Body.Paragraphs;
  29.  
  30. var p1 = pars.Add("Paragraph 1: This is a paragraph of text with a comment added to the whole paragraph. ");
  31. var c1 = p1.GetRange().Comments.Add("Comment added to paragraph 1.", user1, Util.TimeNow(), "J.S.");
  32. var c2 = c1.Reply("Reply to comment 1.", user2);
  33. var c3 = c2.Reply("Reply to comment 2, closing the thread.", user1);
  34. c3.Done = true;
  35.  
  36. var p2 = pars.Add("Paragraph 2: This is another paragraph of text, with a comment added to 3rd run. ");
  37. p2.GetRange().Runs.Add("This is run 2 of paragraph 2. ");
  38. var r = p2.GetRange().Runs.Add("This is run 3 of paragraph 2 with a comment. ");
  39. r.GetRange().Comments.Insert("Comment on run 3 of paragraph 2", user2, RangeLocation.Whole);
  40. p2.GetRange().Runs.Add("This is run 4 of paragraph 2. ");
  41. p2.GetRange().Runs.Add("This is run 5 of paragraph 2. ");
  42. p2.GetRange().Runs.Add("This is run 6 of paragraph 2. ");
  43.  
  44. // Done:
  45. return doc;
  46. }
  47.  
  48. // Optional static method. If it is defined on a sample class,
  49. // these options are used when saving the document to PDF.
  50. public static WordLayoutSettings GetWordLayoutSettings()
  51. {
  52. return new WordLayoutSettings()
  53. {
  54. CommentMode = WordCommentMode.None
  55. };
  56. }
  57. }
  58. }
  59.