ExPdfExport.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. function main() {
  20. //! [main]
  21. //! [include]
  22. // include class Print:
  23. include("scripts/File/Print/Print.js");
  24. //! [include]
  25. //! [init]
  26. // init application name:
  27. qApp.applicationName = "MyApplication";
  28. //! [document]
  29. var storage = new RMemoryStorage();
  30. var spatialIndex = new RSpatialIndexSimple();
  31. var document = new RDocument(storage, spatialIndex);
  32. document.setUnit(RS.Millimeter);
  33. // create document interface (needed for file export functionality):
  34. var di = new RDocumentInterface(document);
  35. //! [document]
  36. //! [operation]
  37. // create an operation:
  38. var operation = new RAddObjectsOperation();
  39. // corner point of the triangle::
  40. var p1 = new RVector(0, 0);
  41. var p2 = new RVector(10, 0);
  42. var p3 = new RVector(5, Math.sin(RMath.deg2rad(60))*10);
  43. // add line entity to operation:
  44. operation.addObject(new RLineEntity(document, new RLineData(p1, p2)));
  45. operation.addObject(new RLineEntity(document, new RLineData(p2, p3)));
  46. operation.addObject(new RLineEntity(document, new RLineData(p3, p1)));
  47. // apply operation to document:
  48. operation.apply(document);
  49. //! [operation]
  50. //! [view]
  51. var scene = new RGraphicsSceneQt(di);
  52. var view = new RGraphicsViewImage();
  53. view.setScene(scene);
  54. //! [view]
  55. //! [settings]
  56. // set up page and paper settings as document variables:
  57. var pageWidth = 210;
  58. var pageHeight = 297;
  59. var bb = document.getBoundingBox(true, true);
  60. var scale = 10.0;
  61. // paper unit:
  62. document.setVariable("PageSettings/PaperUnit", RS.Millimeter);
  63. // paper width:
  64. document.setVariable("PageSettings/PaperWidth", pageWidth);
  65. // paper height:
  66. document.setVariable("PageSettings/PaperHeight", pageHeight);
  67. // page orientation ("Portrait" | "Landscape"):
  68. document.setVariable("PageSettings/PageOrientation", "Portrait");
  69. // color mode ("FullColor" | "GrayScale" | "BlackWhite"):
  70. document.setVariable("ColorSettings/ColorMode", "FullColor");
  71. // background color:
  72. document.setVariable("ColorSettings/BackgroundColor", new RColor("white"));
  73. // drawing scale as string:
  74. document.setVariable("PageSettings/Scale", "10:1");
  75. // offset of drawing origin to lower left corner in drawing units:
  76. document.setVariable("PageSettings/OffsetX", -(pageWidth/scale - bb.getWidth()) / 2);
  77. document.setVariable("PageSettings/OffsetY", -(pageHeight/scale - bb.getHeight()) / 2);
  78. // number of pages (rows / columns):
  79. document.setVariable("MultiPageSettings/Rows", 1);
  80. document.setVariable("MultiPageSettings/Columns", 1);
  81. // switch on / off crop marks:
  82. document.setVariable("MultiPageSettings/PrintCropMarks", false);
  83. // switch on / off page tags:
  84. document.setVariable("PageTagSettings/EnablePageTags", false);
  85. //! [settings]
  86. //! [export]
  87. var print = new Print(undefined, document, view);
  88. print.print("example.pdf");
  89. //! [export]
  90. //! [main]
  91. }
  92. if (typeof(including)=='undefined' || including===false) {
  93. main();
  94. }