Skip to content

Commit 1aee09e

Browse files
committed
Added initial project state + sample project
1 parent b5746d6 commit 1aee09e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2269
-1
lines changed

.editorconfig

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
# http://EditorConfig.org
2+
3+
#################
4+
# Common Settings
5+
#################
6+
7+
# This file is the top-most EditorConfig file
8+
root = true
9+
10+
# All Files
11+
[*]
12+
charset = utf-8
13+
end_of_line = crlf
14+
indent_style = space
15+
indent_size = 4
16+
insert_final_newline = false
17+
trim_trailing_whitespace = true
18+
19+
#########################
20+
# File Extension Settings
21+
#########################
22+
23+
# Visual Studio Solution Files
24+
[*.sln]
25+
indent_style = tab
26+
27+
# Visual Studio XML Project Files
28+
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
29+
indent_size = 2
30+
31+
# XML Configuration Files
32+
[*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct}]
33+
indent_size = 2
34+
35+
# JSON Files
36+
[*.{json,json5}]
37+
indent_size = 2
38+
39+
# Markdown Files
40+
[*.md]
41+
trim_trailing_whitespace = false
42+
43+
# Web Files
44+
[*.{htm,html,js,ts,tsx,css,sass,scss,less,svg,vue}]
45+
indent_size = 2
46+
insert_final_newline = true
47+
48+
# C# Code Style Settings
49+
[*.{cs,csx,cake}]
50+
# Implicit and explicit types
51+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#implicit-and-explicit-types
52+
csharp_style_var_for_built_in_types = false:none
53+
csharp_style_var_when_type_is_apparent = true:warning
54+
csharp_style_var_elsewhere = false:none
55+
# Expression-bodied members
56+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_bodied_members
57+
csharp_style_expression_bodied_methods = false:none
58+
csharp_style_expression_bodied_constructors = false:suggestion
59+
csharp_style_expression_bodied_operators = true:suggestion
60+
csharp_style_expression_bodied_properties = true:suggestion
61+
csharp_style_expression_bodied_indexers = true:suggestion
62+
csharp_style_expression_bodied_accessors = true:suggestion
63+
# Pattern matching
64+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#pattern_matching
65+
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
66+
csharp_style_pattern_matching_over_as_with_null_check = true:warning
67+
# Inlined variable declarations
68+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#inlined_variable_declarations
69+
csharp_style_inlined_variable_declaration = true:warning
70+
# Expression-level preferences
71+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_level_csharp
72+
csharp_prefer_simple_default_expression = true:warning
73+
csharp_style_deconstructed_variable_declaration = true:warning
74+
csharp_style_pattern_local_over_anonymous_function = true:none
75+
# "Null" checking preferences
76+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#null_checking_csharp
77+
csharp_style_throw_expression = true:warning
78+
csharp_style_conditional_delegate_call = true:warning
79+
# Code block preferences
80+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#code_block
81+
csharp_prefer_braces = false:suggestion
82+
83+
###########################
84+
# .NET Language Conventions
85+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#language-conventions
86+
###########################
87+
88+
# .NET Code Style Settings
89+
[*.{cs,csx,cake,vb}]
90+
# "this." and "Me." qualifiers
91+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#this_and_me
92+
dotnet_style_qualification_for_field = false:suggestion
93+
dotnet_style_qualification_for_property = false:suggestion
94+
dotnet_style_qualification_for_method = false:suggestion
95+
dotnet_style_qualification_for_event = false:suggestion
96+
# Language keywords instead of framework type names for type references
97+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#language_keywords
98+
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
99+
dotnet_style_predefined_type_for_member_access = true:warning
100+
# Modifier preferences
101+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#normalize_modifiers
102+
dotnet_style_require_accessibility_modifiers = always:warning
103+
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:warning
104+
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:warning
105+
dotnet_style_readonly_field = true:warning
106+
# Parentheses preferences
107+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#parentheses
108+
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning
109+
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning
110+
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
111+
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
112+
# Expression-level preferences
113+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#expression_level
114+
dotnet_style_object_initializer = true:warning
115+
dotnet_style_collection_initializer = true:warning
116+
dotnet_style_explicit_tuple_names = true:warning
117+
dotnet_style_prefer_inferred_tuple_names = true:warning
118+
dotnet_style_prefer_inferred_anonymous_type_member_names = false:suggestion
119+
dotnet_style_prefer_auto_properties = true:warning
120+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
121+
dotnet_style_prefer_conditional_expression_over_assignment = false:suggestion
122+
dotnet_style_prefer_conditional_expression_over_return = false:suggestion
123+
# Null-checking preferences
124+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#null_checking
125+
dotnet_style_coalesce_expression = true:warning
126+
dotnet_style_null_propagation = true:warning
127+
128+
#############################
129+
# .NET Formatting Conventions
130+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions
131+
#############################
132+
133+
# Organize usings
134+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#usings
135+
dotnet_sort_system_directives_first = false
136+
# C# formatting settings
137+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#c-formatting-settings
138+
csharp_new_line_before_open_brace = all
139+
csharp_new_line_before_else = true
140+
csharp_new_line_before_catch = true
141+
csharp_new_line_before_finally = true
142+
csharp_new_line_before_members_in_object_initializers = true
143+
csharp_new_line_before_members_in_anonymous_types = true
144+
csharp_new_line_between_query_expression_clauses = true
145+
# Indentation options
146+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#indent
147+
csharp_indent_case_contents = true
148+
csharp_indent_switch_labels = true
149+
csharp_indent_labels = no_change
150+
# Spacing options
151+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#spacing
152+
csharp_space_after_cast = false
153+
csharp_space_after_keywords_in_control_flow_statements = true
154+
csharp_space_between_method_declaration_parameter_list_parentheses = false
155+
csharp_space_between_method_call_parameter_list_parentheses = false
156+
csharp_space_between_parentheses = expressions
157+
csharp_space_before_colon_in_inheritance_clause = true
158+
csharp_space_after_colon_in_inheritance_clause = true
159+
csharp_space_around_binary_operators = before_and_after
160+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
161+
csharp_space_between_method_call_name_and_opening_parenthesis = false
162+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
163+
# Wrapping options
164+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference#wrapping
165+
csharp_preserve_single_line_statements = true
166+
csharp_preserve_single_line_blocks = true
167+
# More Indentation options (Undocumented)
168+
csharp_indent_block_contents = true
169+
csharp_indent_braces = false
170+
# Spacing Options (Undocumented)
171+
csharp_space_after_comma = true
172+
csharp_space_after_dot = false
173+
csharp_space_after_semicolon_in_for_statement = true
174+
csharp_space_around_declaration_statements = do_not_ignore
175+
csharp_space_before_comma = false
176+
csharp_space_before_dot = false
177+
csharp_space_before_semicolon_in_for_statement = false
178+
csharp_space_before_open_square_brackets = false
179+
csharp_space_between_empty_square_brackets = false
180+
csharp_space_between_method_declaration_name_and_open_parenthesis = false
181+
csharp_space_between_square_brackets = false
182+
183+
#########################
184+
# .NET Naming conventions
185+
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions
186+
#########################
187+
188+
# Naming Symbols
189+
# constant_fields - Define constant fields
190+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
191+
dotnet_naming_symbols.constant_fields.required_modifiers = const
192+
# non_private_readonly_fields - Define public, internal and protected readonly fields
193+
dotnet_naming_symbols.non_private_readonly_fields.applicable_accessibilities = public, internal, protected
194+
dotnet_naming_symbols.non_private_readonly_fields.applicable_kinds = field
195+
dotnet_naming_symbols.non_private_readonly_fields.required_modifiers = readonly
196+
# static_readonly_fields - Define static and readonly fields
197+
dotnet_naming_symbols.static_readonly_fields.applicable_kinds = field
198+
dotnet_naming_symbols.static_readonly_fields.required_modifiers = static, readonly
199+
# private_readonly_fields - Define private readonly fields
200+
dotnet_naming_symbols.private_readonly_fields.applicable_accessibilities = private
201+
dotnet_naming_symbols.private_readonly_fields.applicable_kinds = field
202+
dotnet_naming_symbols.private_readonly_fields.required_modifiers = readonly
203+
# public_internal_fields - Define public and internal fields
204+
dotnet_naming_symbols.public_internal_fields.applicable_accessibilities = public, internal
205+
dotnet_naming_symbols.public_internal_fields.applicable_kinds = field
206+
# private_protected_fields - Define private and protected fields
207+
dotnet_naming_symbols.private_protected_fields.applicable_accessibilities = private, protected
208+
dotnet_naming_symbols.private_protected_fields.applicable_kinds = field
209+
# private_symbols - Define any private symbol
210+
dotnet_naming_symbols.private_symbols.applicable_accessibilities = private
211+
dotnet_naming_symbols.private_symbols.applicable_kinds = method, property, event, delegate
212+
# public_symbols - Define any public symbol
213+
dotnet_naming_symbols.public_symbols.applicable_accessibilities = public, internal, protected, protected_internal
214+
dotnet_naming_symbols.public_symbols.applicable_kinds = method, property, event, delegate
215+
# parameters - Defines any parameter
216+
dotnet_naming_symbols.parameters.applicable_kinds = parameter
217+
# non_interface_types - Defines class, struct, enum and delegate types
218+
dotnet_naming_symbols.non_interface_types.applicable_kinds = class, struct, enum, delegate
219+
# interface_types - Defines interfaces
220+
dotnet_naming_symbols.interface_types.applicable_kinds = interface
221+
222+
# Naming Styles
223+
# all_upper_with_underscore - Define the ALL_UPPER_WITH_UNDERSCORE
224+
dotnet_naming_style.all_upper_with_underscore.capitalization = all_upper
225+
dotnet_naming_style.all_upper_with_underscore.word_separator = _
226+
# camel_case - Define the camelCase style
227+
dotnet_naming_style.camel_case.capitalization = camel_case
228+
# underscore_camel_case - Define the _camelCase style
229+
dotnet_naming_style.underscore_camel_case.capitalization = camel_case
230+
dotnet_naming_style.underscore_camel_case.required_prefix = _
231+
# pascal_case - Define the Pascal_case style
232+
dotnet_naming_style.pascal_case.capitalization = pascal_case
233+
# first_upper - The first character must start with an upper-case character
234+
dotnet_naming_style.first_upper.capitalization = first_word_upper
235+
# prefix_interface_interface_with_i - Interfaces must be PascalCase and the first character of an interface must be an 'I'
236+
dotnet_naming_style.prefix_interface_interface_with_i.capitalization = pascal_case
237+
dotnet_naming_style.prefix_interface_interface_with_i.required_prefix = I
238+
239+
# Naming Rules
240+
# Constant fields must be ALL_UPPER_CASE
241+
dotnet_naming_rule.constant_fields_must_be_all_upper.severity = warning
242+
dotnet_naming_rule.constant_fields_must_be_all_upper.symbols = constant_fields
243+
dotnet_naming_rule.constant_fields_must_be_all_upper.style = all_upper_with_underscore
244+
# Public, internal and protected readonly fields must be PascalCase
245+
dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.severity = warning
246+
dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.symbols = non_private_readonly_fields
247+
dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.style = pascal_case
248+
# Static readonly fields must be PascalCase
249+
dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.severity = warning
250+
dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.symbols = static_readonly_fields
251+
dotnet_naming_rule.static_readonly_fields_must_be_pascal_case.style = pascal_case
252+
# Private readonly fields must be _camelCase
253+
dotnet_naming_rule.private_readonly_fields_must_be_underscore_camel_case.severity = warning
254+
dotnet_naming_rule.private_readonly_fields_must_be_underscore_camel_case.symbols = private_readonly_fields
255+
dotnet_naming_rule.private_readonly_fields_must_be_underscore_camel_case.style = underscore_camel_case
256+
# Public and internal fields must be PascalCase
257+
dotnet_naming_rule.public_internal_fields_must_be_pascal_case.severity = warning
258+
dotnet_naming_rule.public_internal_fields_must_be_pascal_case.symbols = public_internal_fields
259+
dotnet_naming_rule.public_internal_fields_must_be_pascal_case.style = pascal_case
260+
# Private and protected fields must be _camelCase
261+
dotnet_naming_rule.private_protected_fields_must_be_underscore_camel_case.severity = warning
262+
dotnet_naming_rule.private_protected_fields_must_be_underscore_camel_case.symbols = private_protected_fields
263+
dotnet_naming_rule.private_protected_fields_must_be_underscore_camel_case.style = underscore_camel_case
264+
# Public members must be capitalized
265+
dotnet_naming_rule.public_members_must_be_capitalized.severity = warning
266+
dotnet_naming_rule.public_members_must_be_capitalized.symbols = public_symbols
267+
dotnet_naming_rule.public_members_must_be_capitalized.style = first_upper
268+
# Private symbols must be _camelCase
269+
dotnet_naming_rule.private_members_must_be_underscore_camel_case.severity = warning
270+
dotnet_naming_rule.private_members_must_be_underscore_camel_case.symbols = private_symbols
271+
dotnet_naming_rule.private_members_must_be_underscore_camel_case.style = underscore_camel_case
272+
# Parameters must be camelCase
273+
dotnet_naming_rule.parameters_must_be_camel_case.severity = warning
274+
dotnet_naming_rule.parameters_must_be_camel_case.symbols = parameters
275+
dotnet_naming_rule.parameters_must_be_camel_case.style = camel_case
276+
# Class, struct, enum and delegates must be PascalCase
277+
dotnet_naming_rule.non_interface_types_must_be_pascal_case.severity = warning
278+
dotnet_naming_rule.non_interface_types_must_be_pascal_case.symbols = non_interface_types
279+
dotnet_naming_rule.non_interface_types_must_be_pascal_case.style = pascal_case
280+
# Interfaces must be PascalCase and start with an 'I'
281+
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.severity = warning
282+
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.symbols = interface_types
283+
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = prefix_interface_interface_with_i

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,58 @@
1-
# FileFormats.Pdf
1+
# FileFormats.Pdf
2+
3+
This project was created to enable PDF creation on .NETStandard. This because multiple libraries did not suit my purpose of working on .NET Core & .NET Framework the same way. Some alternatives supported settings the different boxes (Media, Crop, Bleed & Trim) but did not fully supported images on all platforms. Others supported images but not the different boxes, and again others did not work at all on .NET Core.
4+
5+
Because of those reasons this libary was created.
6+
7+
## License
8+
This project is licensed under MIT license.
9+
10+
## Specifications used
11+
This library was created using the specifications lay out in ["PDF 32000-1:2008, Document management – Portable document format – Part 1: PDF 1.7"](https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf).
12+
13+
The full specifications are not implemented. This library currently only supports placements of images and setting the different boxes.
14+
15+
## Remarks
16+
Unlike most PDF libraries this library does not create the entire PDF model in memory before writing the PDF to a (file)stream. Most libaries support editing capabilities, because this libary only supports creating files, it was not necessary to keep the PDF model in memory. This results in less memory usage.
17+
18+
To place the images this library makes use of [SixLabors/ImageSharp](https://github.com/SixLabors/ImageSharp). All images that are placed in the PDF will be saved internally as a JPG file. This means that this library currently does **NOT** support transparency.
19+
20+
### Output pdfs
21+
The PDF files created in this library are PDF 1.7 compliant.
22+
23+
24+
### Sample program images
25+
The sample project called *Synercoding.FileFormats.Pdf.ConsoleTester* uses multiple images. Those images were taken from [Pexels.com](https://www.pexels.com/royalty-free-images/) and are licensed under the [Pexels License](https://www.pexels.com/photo-license/).
26+
27+
## Sample usage
28+
29+
<pre><code>using (var fs = File.OpenWrite(fileName))
30+
using (var writer = new PdfWriter(fs))
31+
{
32+
double _mmToPts(double mm) => mm / 25.4d * 72;
33+
34+
writer
35+
.AddPage(page =&gt;
36+
{
37+
var bleed = _mmToPts(3);
38+
// Mediabox = A4 Portrait with 3mm bleed all around
39+
page.MediaBox = new Primitives.Rectangle(0, 0, _mmToPts(216), _mmToPts(303));
40+
page.TrimBox = new Primitives.Rectangle(
41+
page.MediaBox.LLX + bleed,
42+
page.MediaBox.LLY + bleed,
43+
page.MediaBox.URX - bleed,
44+
page.MediaBox.URY - bleed
45+
);
46+
47+
using (var eyeStream = File.OpenRead("Pexels_com/adult-blue-blue-eyes-865711.jpg"))
48+
{
49+
var scale = 3456d / 5184;
50+
51+
var width = _mmToPts(100);
52+
var height = _mmToPts(100 * scale);
53+
54+
var offSet = _mmToPts(6);
55+
page.AddImage(eyeStream, new Primitives.Rectangle(offSet, offSet, width + offSet, height + offSet));
56+
}
57+
});
58+
}</code></pre>

0 commit comments

Comments
 (0)