refactor(Pdf): Add Background-method to place a background behind the signatures.
This commit is contained in:
@@ -21,4 +21,8 @@
|
||||
<PackageReference Include="itext.bouncy-castle-adapter" Version="8.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EnvelopeGenerator.Domain\EnvelopeGenerator.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
using iText.Kernel.Pdf;
|
||||
using iText.Kernel.Pdf.Canvas;
|
||||
using EnvelopeGenerator.Domain.Interfaces;
|
||||
using iText.Kernel.Colors;
|
||||
using iText.Kernel.Geom;
|
||||
|
||||
#if NETFRAMEWORK
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
#endif
|
||||
|
||||
namespace EnvelopeGenerator.PdfEditor
|
||||
@@ -76,6 +80,40 @@ namespace EnvelopeGenerator.PdfEditor
|
||||
});
|
||||
#endregion
|
||||
|
||||
public Pdf<TInputStream, TOutputStream> Background<TSignature>(IEnumerable<TSignature> signatures)
|
||||
where TSignature : ISignature
|
||||
{
|
||||
foreach (var signature in signatures)
|
||||
Page(signature.Page, page =>
|
||||
{
|
||||
var canvas = new PdfCanvas(page);
|
||||
double inchFactor = 72;
|
||||
double magin = .2;
|
||||
double x = (signature.X - .7 - magin) * inchFactor;
|
||||
double y = (signature.Y - .5 - magin) * inchFactor;
|
||||
double width = 1.9500000000000002 * inchFactor;
|
||||
double height = 2.52 * inchFactor;
|
||||
|
||||
double bottomLineLength = 2.5;
|
||||
|
||||
Rectangle pageSize = page.GetPageSize();
|
||||
|
||||
canvas.ConcatMatrix(1, 0, 0, -1, 0, pageSize.GetHeight());
|
||||
|
||||
// draw background
|
||||
canvas.SetFillColor(new DeviceRgb(222, 220, 215))
|
||||
.Rectangle(x, y, width, height)
|
||||
.Fill();
|
||||
|
||||
// draw bottom line
|
||||
canvas.SetFillColor(new DeviceRgb(204, 202, 198))
|
||||
.Rectangle(x, y + height - bottomLineLength, width, bottomLineLength)
|
||||
.Fill();
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
#region Finalizer
|
||||
private bool _disposed = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user