Posted By

greg002 on 12/28/12


Tagged

basic fop


Versions (?)

Fop basic


 / Published in: C#
 

Fo basic

  1. public static void generateFo()
  2. {
  3.  
  4. String formatNameSpace = "http://www.w3.org/1999/XSL/Format";
  5.  
  6.  
  7. XmlDocument xmlDocument = new XmlDocument();
  8.  
  9. XmlNode dec = xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", null);
  10.  
  11. xmlDocument.AppendChild(dec);
  12.  
  13. XmlElement xmlRoot = xmlDocument.CreateElement("fo:root", formatNameSpace);
  14.  
  15. XmlElement item1 = xmlDocument.CreateElement("fo:layout-master-set", formatNameSpace);
  16.  
  17. XmlElement itemChild11 = xmlDocument.CreateElement("fo:simple-page-master", formatNameSpace);
  18. itemChild11.SetAttribute("master-name", "simple");
  19. itemChild11.SetAttribute("height", "29.7cm");
  20. itemChild11.SetAttribute("width", "21cm");
  21.  
  22. XmlElement itemItemChild11 = xmlDocument.CreateElement("fo:region-body", formatNameSpace);
  23. itemItemChild11.SetAttribute("margin-top", "3cm");
  24. itemItemChild11.SetAttribute("margin-left", "1cm");
  25. itemItemChild11.SetAttribute("margin-right", "1cm");
  26. itemItemChild11.SetAttribute("margin-bottom", "1cm");
  27.  
  28.  
  29. XmlElement itemItemChild12 = xmlDocument.CreateElement("fo:region-before", formatNameSpace);
  30. itemItemChild12.SetAttribute("extent", "3cm");
  31.  
  32. XmlElement itemItemChild13 = xmlDocument.CreateElement("fo:region-after", formatNameSpace);
  33. itemItemChild13.SetAttribute("extent", "3cm");
  34.  
  35.  
  36. xmlRoot.AppendChild(item1);
  37. item1.AppendChild(itemChild11);
  38. itemChild11.AppendChild(itemItemChild11);
  39. itemChild11.AppendChild(itemItemChild12);
  40. itemChild11.AppendChild(itemItemChild13);
  41.  
  42.  
  43. //ITEM 2
  44. //----------------THE ACTUAL PAGES----------------
  45. XmlElement item2 = xmlDocument.CreateElement("fo:page-sequence", formatNameSpace);
  46. item2.SetAttribute("master-reference", "simple");
  47.  
  48. XmlElement itemChild21 = xmlDocument.CreateElement("fo:flow", formatNameSpace);
  49. itemChild21.SetAttribute("flow-name", "xsl-region-body");
  50.  
  51. XmlElement itemItemChild21 = xmlDocument.CreateElement("fo:block", formatNameSpace);
  52. itemItemChild21.SetAttribute("font-size", "18pt");
  53. itemItemChild21.SetAttribute("font-family", "sans-serif");
  54. itemItemChild21.SetAttribute("height", "24pt");
  55. itemItemChild21.SetAttribute("space-after.optimum", "15pt");
  56. itemItemChild21.SetAttribute("color", "darkslategray");
  57. itemItemChild21.SetAttribute("text-align", "center");
  58. itemItemChild21.InnerText = "FO Example";
  59.  
  60. XmlElement itemItemChild22 = xmlDocument.CreateElement("fo:block", formatNameSpace);
  61. itemItemChild22.SetAttribute("font-size", "12pt");
  62. itemItemChild22.SetAttribute("font-family", "sans-serif");
  63. itemItemChild22.SetAttribute("height", "15pt");
  64. itemItemChild22.SetAttribute("space-after.optimum", "15pt");
  65. itemItemChild22.SetAttribute("text-align", "center");
  66. itemItemChild22.InnerText = "This is normal text, centered.";
  67.  
  68. XmlElement itemItemChild23 = xmlDocument.CreateElement("fo:block", formatNameSpace);
  69. itemItemChild23.SetAttribute("font-size", "12pt");
  70. itemItemChild23.SetAttribute("font-family", "sans-serif");
  71. itemItemChild23.SetAttribute("height", "15pt");
  72. itemItemChild23.SetAttribute("space-after.optimum", "3pt");
  73. itemItemChild23.SetAttribute("text-align", "justify");
  74. itemItemChild23.InnerText = "This is normal text, justified. So to show it works, it should be text that runs over more than 1 line. Maybe this will be enough.";
  75.  
  76. xmlRoot.AppendChild(item2);
  77.  
  78. item2.AppendChild(itemChild21);
  79. itemChild21.AppendChild(itemItemChild21);
  80. itemChild21.AppendChild(itemItemChild22);
  81. itemChild21.AppendChild(itemItemChild23);
  82.  
  83. xmlDocument.AppendChild(xmlRoot);
  84.  
  85.  
  86. xmlDocument.Save("1.fo");
  87.  
  88. }

Report this snippet  

You need to login to post a comment.