refactor(pdf): optimize background rendering with single concat per page
- Added `System.Linq` import to enable distinct and ordered page index selection - Applied `ConcatMatrix` transformation once per page instead of per signature - Improved performance and reduced redundant operations in `Background` method
This commit is contained in:
parent
06431028cb
commit
6f31d7b1d0
@ -6,6 +6,7 @@ using iText.Kernel.Geom;
|
||||
#if NETFRAMEWORK
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
#endif
|
||||
@ -82,6 +83,16 @@ namespace EnvelopeGenerator.PdfEditor
|
||||
public Pdf<TInputStream, TOutputStream> Background<TSignature>(IEnumerable<TSignature> signatures)
|
||||
where TSignature : ISignature
|
||||
{
|
||||
// once per page
|
||||
var pageIndexes = signatures.Select(signature => signature.Page).Distinct().OrderBy(index => index);
|
||||
foreach(var pageIndex in pageIndexes)
|
||||
{
|
||||
var page = _doc.GetPage(pageIndex);
|
||||
Rectangle pageSize = page.GetPageSize();
|
||||
var canvas = new PdfCanvas(page);
|
||||
canvas.ConcatMatrix(1, 0, 0, -1, 0, pageSize.GetHeight());
|
||||
}
|
||||
|
||||
foreach (var signature in signatures)
|
||||
Page(signature.Page, page =>
|
||||
{
|
||||
@ -95,10 +106,6 @@ namespace EnvelopeGenerator.PdfEditor
|
||||
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user