• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp.Pdf / 14305897173

07 Apr 2025 09:38AM UTC coverage: 2.035% (-73.9%) from 75.959%
14305897173

push

github

DomCR
version 0.1.0-beta

125 of 8279 branches covered (1.51%)

Branch coverage included in aggregate %.

648 of 29704 relevant lines covered (2.18%)

4.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ACadSharp.Pdf/PdfExporter.cs
1
using ACadSharp.Entities;
2
using ACadSharp.Objects;
3
using ACadSharp.Pdf.Core;
4
using ACadSharp.Tables;
5
using System.Collections.Generic;
6
using System.IO;
7

8
namespace ACadSharp.Pdf
9
{
10
        /// <summary>
11
        /// Exporter to create a pdf document.
12
        /// </summary>
13
        public class PdfExporter
14
        {
15
                /// <summary>
16
                /// Configuration for the <see cref="PdfExporter"/> instance.
17
                /// </summary>
18
                public PdfConfiguration Configuration { get; } = new PdfConfiguration();
×
19

20
                private readonly PdfDocument _pdf;
21
                private readonly Stream _stream;
22

23
                /// <summary>
24
                /// Initialize an instance of <see cref="PdfExporter"/>.
25
                /// </summary>
26
                /// <param name="path">Path where the pdf will be saved.</param>
27
                public PdfExporter(string path) : this(File.Create(path))
×
28
                {
×
29
                }
×
30

31
                /// <summary>
32
                /// Initialize an instance of <see cref="PdfExporter"/>.
33
                /// </summary>
34
                /// <param name="stream">Stream where the pdf will be saved.</param>
35
                public PdfExporter(Stream stream)
×
36
                {
×
37
                        this._stream = stream;
×
38
                        this._pdf = new PdfDocument();
×
39
                }
×
40

41
                /// <summary>
42
                /// Add the model space from a cad document.
43
                /// </summary>
44
                /// <param name="document"></param>
45
                /// <remarks>
46
                /// This method does not import the <see cref="TableEntry"/> from the document.
47
                /// </remarks>
48
                public void AddModelSpace(CadDocument document)
49
                {
×
50
                        this.Add(document.ModelSpace);
×
51
                }
×
52

53
                /// <summary>
54
                /// Add all the paper layouts 
55
                /// </summary>
56
                public void AddPaperLayouts(CadDocument document)
57
                {
×
58
                        this.Add(document.Layouts);
×
59
                }
×
60

61
                /// <summary>
62
                /// Add layouts to the pdf as pages.
63
                /// </summary>
64
                /// <param name="layouts"></param>
65
                public void Add(IEnumerable<Layout> layouts)
66
                {
×
67
                        foreach (var layout in layouts)
×
68
                        {
×
69
                                if (!layout.IsPaperSpace)
×
70
                                {
×
71
                                        continue;
×
72
                                }
73

74
                                this.Add(layout);
×
75
                        }
×
76
                }
×
77

78
                /// <summary>
79
                /// Add a <see cref="Layout"/> to the pdf as a page.
80
                /// </summary>
81
                /// <param name="layout"></param>
82
                public void Add(Layout layout)
83
                {
×
84
                        PdfPage page = this._pdf.Pages.AddPage();
×
85

86
                        page.Layout = layout;
×
87

88
                        foreach (Entity e in layout.AssociatedBlock.Entities)
×
89
                        {
×
90
                                if (e is Viewport)
×
91
                                {
×
92
                                        continue;
×
93
                                }
94

95
                                page.Entities.Add(e);
×
96
                        }
×
97

98
                        foreach (Viewport vp in layout.Viewports)
×
99
                        {
×
100
                                if (vp.RepresentsPaper)
×
101
                                {
×
102
                                        continue;
×
103
                                }
104

105
                                page.Viewports.Add(vp);
×
106
                        }
×
107
                }
×
108

109
                /// <summary>
110
                /// Add a <see cref="BlockRecord"/> as a page.
111
                /// </summary>
112
                /// <param name="block"></param>
113
                public void Add(BlockRecord block)
114
                {
×
115
                        PdfPage page = this._pdf.Pages.AddPage();
×
116

117
                        page.Add(block);
×
118
                }
×
119

120
                /// <summary>
121
                /// Close the document and save it.
122
                /// </summary>
123
                public void Close()
124
                {
×
125
                        using (PdfWriter writer = new PdfWriter(this._stream, this._pdf, this.Configuration))
×
126
                        {
×
127
                                writer.Write();
×
128
                        }
×
129
                }
×
130
        }
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc