Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ charset = utf-8
end_of_line = crlf
indent_style = space
indent_size = 4
insert_final_newline = false
tab_width = 4
insert_final_newline = true
trim_trailing_whitespace = true

#########################
Expand Down Expand Up @@ -43,7 +44,6 @@ trim_trailing_whitespace = false
# Web Files
[*.{htm,html,js,ts,tsx,css,sass,scss,less,svg,vue}]
indent_size = 2
insert_final_newline = true

###########################
# C# code style settings
Expand Down Expand Up @@ -72,6 +72,9 @@ csharp_style_expression_bodied_local_functions = false:silent
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#pattern-matching
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning
csharp_style_prefer_pattern_matching = true:silent
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion

# Inlined variable declarations
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#inlined-variable-declarations
Expand Down Expand Up @@ -104,6 +107,20 @@ csharp_style_prefer_range_operator = true:suggestion
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#miscellaneous-preferences
csharp_style_deconstructed_variable_declaration = true:warning
csharp_style_pattern_local_over_anonymous_function = true:none
csharp_prefer_simple_using_statement = false:suggestion
csharp_prefer_static_local_function = true:suggestion
csharp_using_directive_placement = outside_namespace:silent
csharp_style_namespace_declarations = file_scoped:suggestion
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = false:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
csharp_style_prefer_parameter_null_checking = true:suggestion
csharp_style_prefer_switch_expression = true:suggestion

###########################
# .NET code style settings
Expand Down Expand Up @@ -147,15 +164,23 @@ dotnet_style_prefer_inferred_tuple_names = true:warning
dotnet_style_prefer_inferred_anonymous_type_member_names = false:suggestion
dotnet_style_prefer_auto_properties = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_prefer_compound_assignment = true:suggestion

# Null-checking preferences
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#null-checking-preferences
dotnet_style_coalesce_expression = true:warning
dotnet_style_null_propagation = true:warning

# Miscellaneous preferences
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_allow_multiple_blank_lines_experimental = true:suggestion
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent

#############################
# .NET code quality settings
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#net-code-quality-settings
Expand Down Expand Up @@ -249,8 +274,13 @@ dotnet_naming_symbols.private_static_readonly_fields.applicable_accessibilities
dotnet_naming_symbols.private_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.private_static_readonly_fields.required_modifiers = static, readonly

# public_static_readonly_fields - Define static and readonly fields
dotnet_naming_symbols.public_static_readonly_fields.applicable_accessibilities = public
dotnet_naming_symbols.public_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.public_static_readonly_fields.required_modifiers = static, readonly

# non_private_static_readonly_fields - Define static and readonly fields
dotnet_naming_symbols.non_private_static_readonly_fields.applicable_accessibilities = public, internal, protected
dotnet_naming_symbols.non_private_static_readonly_fields.applicable_accessibilities = internal, protected
dotnet_naming_symbols.non_private_static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.non_private_static_readonly_fields.required_modifiers = static, readonly

Expand Down Expand Up @@ -317,7 +347,12 @@ dotnet_naming_rule.non_private_static_readonly_fields_must_be_pascal_case.severi
dotnet_naming_rule.non_private_static_readonly_fields_must_be_pascal_case.symbols = non_private_static_readonly_fields
dotnet_naming_rule.non_private_static_readonly_fields_must_be_pascal_case.style = pascal_case

# Public, internal and protected readonly fields must be PascalCase
# Public static readonly fields must be ALL_UPPER_CASE
dotnet_naming_rule.public_static_readonly_fields_must_be_all_upper.severity = warning
dotnet_naming_rule.public_static_readonly_fields_must_be_all_upper.symbols = public_static_readonly_fields
dotnet_naming_rule.public_static_readonly_fields_must_be_all_upper.style = all_upper_with_underscore

# Internal and protected readonly fields must be PascalCase
dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.severity = warning
dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.symbols = non_private_readonly_fields
dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.style = pascal_case
Expand Down Expand Up @@ -365,4 +400,4 @@ dotnet_naming_rule.non_interface_types_must_be_pascal_case.style = pascal_case
# Interfaces must be PascalCase and start with an 'I'
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.severity = warning
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.symbols = interface_types
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = prefix_interface_interface_with_i
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = prefix_interface_interface_with_i
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net5.0'))">
<DefineConstants>$(DefineConstants);SUPPORTS_MEMBERNOTNULL</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_INIT</DefineConstants>
<DefineConstants>$(DefineConstants);SUPPORTS_TYPED_ENUM_ISDEFINED</DefineConstants>
</PropertyGroup>

</Project>
</Project>
4 changes: 2 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Update="SixLabors.ImageSharp" Version="2.1.*" />
<PackageReference Update="Synercoding.Primitives" Version="1.0.0-rc08" />
<PackageReference Update="Synercoding.Primitives" Version="1.0.0-rc09" />
</ItemGroup>

</Project>
</Project>
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[nuget-badge]: https://img.shields.io/nuget/v/Synercoding.FileFormats.Pdf.svg?label=Synercoding.FileFormats.Pdf


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.
This project was created to enable PDF creation on .NETStandard 2.1, .NET 6 & .NET 7. 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.

Because of those reasons this libary was created.

Expand All @@ -15,16 +15,30 @@ This project is licensed under MIT license.
## Specifications used
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).

The full specifications are not implemented. This library currently only supports placements of images, drawing of vector shapes (CMYK, RGB & gray scale), and setting the different boxes.
The full specifications are not implemented.
This library currently only supports:
- Images
- *No transparency support at the moment*
- Text
- *Only the 14 standard fonts are available*
- *See "9.6.2.2 Standard Type 1 Fonts (Standard 14 Fonts)" in the specifications.*
- Shapes
- Setting page boxes (Media, Crop, Bleed, Trim & Art)
- Color model limited to:
- DeviceGray
- DeviceRGB
- DeviceCMYK
- Separations/Spotcolor (with a linearized type 2 method to portay the tint)

## Remarks
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.

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.

### Output pdfs
The PDF files created in this library are PDF 1.7 compliant.
The PDF files created in this library are not fully PDF 1.7 compliant, because the standard 14 fonts are partially written to the Font Dictionary, The **FirstChar**, **LastChar**. **Widths** and **FontDescriptor** values are omitted, which is was acceptable prior to PDF 1.5. This special treatment of the 14 standard fonts was deprecated in PDF 1.5. The PDF's that are generated will work in conforming readers because as the specification states: *"For backwards capability, conforming readers shall still provide the special treatment identified for the standard 14 fonts."*.

This shortcoming shall be remedied when broader font support is implemented.

### Sample program images
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/).
Expand All @@ -35,21 +49,18 @@ The sample project called *Synercoding.FileFormats.Pdf.ConsoleTester* uses multi
using (var writer = new PdfWriter(fs))
{
writer
.AddPage(page =&gt;
.AddPage(page =>
{
var bleed = new Spacing(3, Unit.Millimeters);
page.MediaBox = Sizes.A4Portrait.Expand(bleed).AsRectangle();
var bleed = Mm(3);
page.MediaBox = Sizes.A4.Expand(bleed).AsRectangle();
page.TrimBox = page.MediaBox.Contract(bleed);

using (var eyeStream = File.OpenRead("Pexels_com/adult-blue-blue-eyes-865711.jpg"))

using (var barrenStream = File.OpenRead("Pexels_com/arid-barren-desert-1975514.jpg"))
using (var barrenImage = SixLabors.ImageSharp.Image.Load(barrenStream))
{
var scale = 3456d / 5184;

var width = 100;
var height = 100 * scale;
var scale = (double)barrenImage.Width / barrenImage.Height;

var offSet = 6;
page.AddImage(eyeStream, new Rectangle(offSet, offSet, width + offSet, height + offSet, Unit.Millimeters));
page.Content.AddImage(barrenImage, new Rectangle(0, 0, scale * 303, 303, Unit.Millimeters));
}
});
}</code></pre>
})
}</code></pre>
Loading