|
1 | 1 | # PdfSharpCore
|
2 | 2 |
|
| 3 | +[](https://www.nuget.org/packages/PdfSharpCore/) |
| 4 | +[](https://github.com/ststeiger/PdfSharpCore/actions/workflows/build.yml) |
3 | 5 | [](https://codecov.io/github/ststeiger/PdfSharpCore?branch=master)
|
4 | 6 |
|
5 |
| -**PdfSharpCore** is a partial port of [PdfSharp.Xamarin](https://github.com/roceh/PdfSharp.Xamarin/) for .NET Standard |
| 7 | +**PdfSharpCore** is a partial port of [PdfSharp.Xamarin](https://github.com/roceh/PdfSharp.Xamarin/) for .NET Standard. |
6 | 8 | Additionally MigraDoc has been ported as well (from version 1.32).
|
7 |
| -Images have been implemented with [ImageSharp](https://github.com/JimBobSquarePants/ImageSharp/), which is still in Alpha. They State on their readme that it is still in Alpha status and shouldn't be used in productive environments. Since I didn't find any good alternatives it's still used. |
| 9 | +Image support has been implemented with [SixLabors.ImageSharp](https://github.com/JimBobSquarePants/ImageSharp/) and Fonts support with [SixLabors.Fonts](https://github.com/SixLabors/Fonts). |
8 | 10 |
|
9 |
| -ImageSharp being Alpha isn't a big issue either since this code isn't by far done yet. So please chime in ;) |
10 | 11 |
|
11 |
| -###### Example project |
| 12 | +## Table of Contents |
12 | 13 |
|
13 |
| -There was an example project here. <br /> |
14 |
| -I've removed it from this project, and put it into a separate solution. |
15 |
| -You can find it [here](https://github.com/ststeiger/Stammbaum).<br /> |
16 |
| -There's a default font-resolver in [FontResolver.cs](https://github.com/ststeiger/PdfSharpCore/blob/master/PdfSharpCore/Utils/FontResolver.cs).<br /> |
17 |
| -It should work on Windows, Linux, OSX and Azure. <br /> |
18 |
| -Some limitations apply. <br /> |
19 |
| -See open issues. |
| 14 | +- [Documentation](docs/index.md) |
| 15 | +- [Example](#example) |
| 16 | +- [Contributing](#contributing) |
| 17 | +- [License](#license) |
20 | 18 |
|
21 |
| -## Example usage |
| 19 | + |
| 20 | +## Example |
22 | 21 |
|
23 | 22 | ```cs
|
24 |
| -//See the "Example" Project for a MigraDoc example |
25 | 23 | static void Main(string[] args)
|
26 | 24 | {
|
27 |
| - GlobalFontSettings.FontResolver = new FontResolver(); |
28 |
| - |
29 | 25 | var document = new PdfDocument();
|
30 | 26 | var page = document.AddPage();
|
31 | 27 | var gfx = XGraphics.FromPdfPage(page);
|
32 | 28 | var font = new XFont("OpenSans", 20, XFontStyle.Bold);
|
33 | 29 |
|
34 |
| - gfx.DrawString("Hello World!", font, XBrushes.Black, new XRect(20, 20, page.Width, page.Height), XStringFormats.Center); |
| 30 | + gfx.DrawString( |
| 31 | + "Hello World!", font, XBrushes.Black, |
| 32 | + new XRect(20, 20, page.Width, page.Height), |
| 33 | + XStringFormats.Center); |
35 | 34 |
|
36 | 35 | document.Save("test.pdf");
|
37 | 36 | }
|
38 |
| - |
39 |
| -// This implementation is obviously not very good --> Though it should be enough for everyone to implement their own. |
40 |
| -public class FontResolver : IFontResolver |
41 |
| -{ |
42 |
| - public byte[] GetFont(string faceName) |
43 |
| - { |
44 |
| - using(var ms = new MemoryStream()) |
45 |
| - { |
46 |
| - using(var fs = File.Open(faceName, FileMode.Open)) |
47 |
| - { |
48 |
| - fs.CopyTo(ms); |
49 |
| - ms.Position = 0; |
50 |
| - return ms.ToArray(); |
51 |
| - } |
52 |
| - } |
53 |
| - } |
54 |
| - public FontResolverInfo ResolveTypeface(string familyName, bool isBold, bool isItalic) |
55 |
| - { |
56 |
| - if (familyName.Equals("OpenSans", StringComparison.CurrentCultureIgnoreCase)) |
57 |
| - { |
58 |
| - if (isBold && isItalic) |
59 |
| - { |
60 |
| - return new FontResolverInfo("OpenSans-BoldItalic.ttf"); |
61 |
| - } |
62 |
| - else if (isBold) |
63 |
| - { |
64 |
| - return new FontResolverInfo("OpenSans-Bold.ttf"); |
65 |
| - } |
66 |
| - else if (isItalic) |
67 |
| - { |
68 |
| - return new FontResolverInfo("OpenSans-Italic.ttf"); |
69 |
| - } |
70 |
| - else |
71 |
| - { |
72 |
| - return new FontResolverInfo("OpenSans-Regular.ttf"); |
73 |
| - } |
74 |
| - } |
75 |
| - return null; |
76 |
| - } |
77 |
| - } |
78 |
| -} |
79 | 37 | ```
|
80 | 38 |
|
81 |
| -## License |
82 | 39 |
|
83 |
| -Copyright (c) 2005-2007 empira Software GmbH, Cologne (Germany) |
84 |
| -Modified work Copyright (c) 2016 David Dunscombe |
| 40 | +## Contributing |
| 41 | + |
| 42 | +We appreciate feedback and contribution to this repo! |
85 | 43 |
|
86 |
| -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
87 | 44 |
|
88 |
| -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 45 | +## License |
89 | 46 |
|
90 |
| -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 47 | +This software is released under the MIT License. See the [LICENSE](LICENCE.md) file for more info. |
0 commit comments