Compare commits
13 Commits
0107602a84
...
ef28bbaaf1
| Author | SHA1 | Date | |
|---|---|---|---|
| ef28bbaaf1 | |||
| 258de6244c | |||
| a845b85a5c | |||
| 02a7b706cf | |||
| 7912469709 | |||
| 75d975223e | |||
| c456d67d03 | |||
| 241e59fc7e | |||
| f0d101bb23 | |||
| 8db5afae40 | |||
| b62cca5961 | |||
| 0e7b120ded | |||
| d8cbdb0c65 |
@@ -35,7 +35,7 @@ public class MappingProfile : Profile
|
||||
CreateMap<EnvelopeType, EnvelopeTypeDto>();
|
||||
CreateMap<Domain.Entities.Receiver, ReceiverDto>();
|
||||
CreateMap<Domain.Entities.EnvelopeReceiverReadOnly, EnvelopeReceiverReadOnlyDto>();
|
||||
CreateMap<Annotation, AnnotationDto>();
|
||||
CreateMap<ElementAnnotation, AnnotationDto>();
|
||||
|
||||
// DTO to Entity mappings
|
||||
CreateMap<ConfigDto, Config>();
|
||||
@@ -51,7 +51,7 @@ public class MappingProfile : Profile
|
||||
CreateMap<ReceiverDto, Domain.Entities.Receiver>().ForMember(rcv => rcv.EnvelopeReceivers, rcvReadDto => rcvReadDto.Ignore());
|
||||
CreateMap<EnvelopeReceiverReadOnlyCreateDto, Domain.Entities.EnvelopeReceiverReadOnly>();
|
||||
CreateMap<EnvelopeReceiverReadOnlyUpdateDto, Domain.Entities.EnvelopeReceiverReadOnly>();
|
||||
CreateMap<AnnotationCreateDto, Annotation>()
|
||||
CreateMap<AnnotationCreateDto, ElementAnnotation>()
|
||||
.ForMember(dest => dest.AddedWhen, opt => opt.MapFrom(_ => DateTime.UtcNow));
|
||||
|
||||
// Messaging mappings
|
||||
|
||||
@@ -12,13 +12,13 @@ public class AnnotationHandler : INotificationHandler<DocSignedNotification>
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private readonly IRepository<Annotation> _repo;
|
||||
private readonly IRepository<ElementAnnotation> _repo;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="repository"></param>
|
||||
public AnnotationHandler(IRepository<Annotation> repository)
|
||||
public AnnotationHandler(IRepository<ElementAnnotation> repository)
|
||||
{
|
||||
_repo = repository;
|
||||
}
|
||||
|
||||
@@ -9,13 +9,13 @@ namespace EnvelopeGenerator.Application.Common.Notifications.RemoveSignature.Han
|
||||
/// </summary>
|
||||
public class RemoveAnnotationHandler : INotificationHandler<RemoveSignatureNotification>
|
||||
{
|
||||
private readonly IRepository<Annotation> _repo;
|
||||
private readonly IRepository<ElementAnnotation> _repo;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="repository"></param>
|
||||
public RemoveAnnotationHandler(IRepository<Annotation> repository)
|
||||
public RemoveAnnotationHandler(IRepository<ElementAnnotation> repository)
|
||||
{
|
||||
_repo = repository;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.66" />
|
||||
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.3.7" />
|
||||
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.4.0" />
|
||||
<PackageReference Include="DigitalData.Core.Application" Version="3.4.0" />
|
||||
<PackageReference Include="DigitalData.Core.Client" Version="2.1.0" />
|
||||
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />
|
||||
|
||||
@@ -70,11 +70,11 @@
|
||||
<Reference Include="DigitalData.Controls.DocumentViewer, Version=1.9.8.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Controls.DocumentViewer.1.9.8\lib\net462\DigitalData.Controls.DocumentViewer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Core.Abstraction.Application, Version=1.3.7.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Core.Abstraction.Application.1.3.7\lib\net462\DigitalData.Core.Abstraction.Application.dll</HintPath>
|
||||
<Reference Include="DigitalData.Core.Abstraction.Application, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Core.Abstraction.Application.1.4.0\lib\net462\DigitalData.Core.Abstraction.Application.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Core.Abstractions, Version=4.1.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Core.Abstractions.4.1.1\lib\net462\DigitalData.Core.Abstractions.dll</HintPath>
|
||||
<Reference Include="DigitalData.Core.Abstractions, Version=4.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Core.Abstractions.4.2.0\lib\net462\DigitalData.Core.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Modules.Base, Version=1.3.8.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Modules.Base.1.3.8\lib\net462\DigitalData.Modules.Base.dll</HintPath>
|
||||
|
||||
@@ -5,10 +5,10 @@ Imports EnvelopeGenerator.CommonServices.Jobs
|
||||
Imports EnvelopeGenerator.CommonServices.Jobs.FinalizeDocument
|
||||
Imports GdPicture14
|
||||
Imports Newtonsoft.Json.Linq
|
||||
Imports DigitalData.Core.Abstraction.Application
|
||||
Imports EnvelopeGenerator.Infrastructure
|
||||
Imports Microsoft.EntityFrameworkCore
|
||||
Imports System.Text
|
||||
Imports DigitalData.Core.Abstractions
|
||||
|
||||
Public Class frmFinalizePDF
|
||||
Private Const CONNECTIONSTRING = "Server=sDD-VMP04-SQL17\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=+bk8oAbbQP1AzoHtvZUbd+Mbok2f8Fl4miEx1qssJ5yEaEWoQJ9prg4L14fURpPnqi1WMNs9fE4=;"
|
||||
@@ -24,7 +24,10 @@ Public Class frmFinalizePDF
|
||||
|
||||
Private Sub frmFinalizePDF_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, Application.StartupPath)
|
||||
Database = New MSSQLServer(LogConfig, MSSQLServer.DecryptConnectionString(CONNECTIONSTRING))
|
||||
|
||||
Dim dCnnStr As String = MSSQLServer.DecryptConnectionString(CONNECTIONSTRING)
|
||||
|
||||
Database = New MSSQLServer(LogConfig, dCnnStr)
|
||||
|
||||
#Disable Warning BC40000 ' Type or member is obsolete
|
||||
Factory.Shared.AddEnvelopeGeneratorInfrastructureServices(
|
||||
@@ -40,7 +43,7 @@ Public Class frmFinalizePDF
|
||||
End Sub)
|
||||
opt.AddDbContext(
|
||||
Sub(options)
|
||||
options.UseSqlServer(CONNECTIONSTRING) _
|
||||
options.UseSqlServer(dCnnStr) _
|
||||
.EnableSensitiveDataLogging() _
|
||||
.EnableDetailedErrors()
|
||||
End Sub)
|
||||
@@ -96,8 +99,9 @@ Public Class frmFinalizePDF
|
||||
Select(Function(r As DataRow) r.Item("VALUE").ToString()).
|
||||
ToList()
|
||||
|
||||
Dim oBuffer As Byte() = ReadEnvelope(CInt(txtEnvelope.Text))
|
||||
Dim oNewBuffer = PDFBurner.BurnInstantJSONAnnotationsToPDF(oBuffer, oJsonList)
|
||||
Dim envelopeId As Integer = CInt(txtEnvelope.Text)
|
||||
Dim oBuffer As Byte() = ReadEnvelope(envelopeId)
|
||||
Dim oNewBuffer = PDFBurner.BurnAnnotsToPDF(oBuffer, oJsonList, envelopeId)
|
||||
Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
|
||||
Dim oNewPath = Path.Combine(desktopPath, $"E{txtEnvelope.Text}R{txtReceiver.Text}.burned.pdf")
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
<package id="AutoMapper" version="10.1.1" targetFramework="net462" />
|
||||
<package id="BouncyCastle.Cryptography" version="2.5.0" targetFramework="net462" />
|
||||
<package id="DigitalData.Controls.DocumentViewer" version="1.9.8" targetFramework="net462" />
|
||||
<package id="DigitalData.Core.Abstraction.Application" version="1.3.7" targetFramework="net462" />
|
||||
<package id="DigitalData.Core.Abstractions" version="4.1.1" targetFramework="net462" />
|
||||
<package id="DigitalData.Core.Abstraction.Application" version="1.4.0" targetFramework="net462" />
|
||||
<package id="DigitalData.Core.Abstractions" version="4.2.0" targetFramework="net462" />
|
||||
<package id="DigitalData.Modules.Base" version="1.3.8" targetFramework="net462" />
|
||||
<package id="DigitalData.Modules.Config" version="1.3.0" targetFramework="net462" />
|
||||
<package id="DigitalData.Modules.Database" version="2.3.5.4" targetFramework="net462" />
|
||||
|
||||
@@ -72,11 +72,11 @@
|
||||
<Reference Include="DevExpress.XtraEditors.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
|
||||
<Reference Include="DevExpress.XtraGauges.v21.2.Core, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
|
||||
<Reference Include="DevExpress.XtraReports.v21.2, Version=21.2.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
|
||||
<Reference Include="DigitalData.Core.Abstraction.Application, Version=1.3.7.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Core.Abstraction.Application.1.3.7\lib\net462\DigitalData.Core.Abstraction.Application.dll</HintPath>
|
||||
<Reference Include="DigitalData.Core.Abstraction.Application, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Core.Abstraction.Application.1.4.0\lib\net462\DigitalData.Core.Abstraction.Application.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Core.Abstractions, Version=4.1.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Core.Abstractions.4.1.1\lib\net462\DigitalData.Core.Abstractions.dll</HintPath>
|
||||
<Reference Include="DigitalData.Core.Abstractions, Version=4.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Core.Abstractions.4.2.0\lib\net462\DigitalData.Core.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DigitalData.Modules.Base, Version=1.3.8.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DigitalData.Modules.Base.1.3.8\lib\net462\DigitalData.Modules.Base.dll</HintPath>
|
||||
|
||||
@@ -14,6 +14,7 @@ Imports EnvelopeGenerator.Domain.Entities
|
||||
Imports DigitalData.Core.Abstraction.Application
|
||||
Imports EnvelopeGenerator.Infrastructure
|
||||
Imports Microsoft.EntityFrameworkCore
|
||||
Imports DigitalData.Core.Abstractions
|
||||
|
||||
Namespace Jobs
|
||||
Public Class FinalizeDocumentJob
|
||||
@@ -403,7 +404,6 @@ Namespace Jobs
|
||||
ParentFolderUID = pEnvelopeData.EnvelopeUUID
|
||||
End If
|
||||
|
||||
|
||||
Logger.Info("ParentFolderUID: [{0}]", ParentFolderUID)
|
||||
Dim oInputDocumentBuffer As Byte()
|
||||
If Not IsNothing(pEnvelopeData.DocAsByte) Then
|
||||
@@ -416,7 +416,7 @@ Namespace Jobs
|
||||
End Try
|
||||
End If
|
||||
|
||||
Return PDFBurner.BurnInstantJSONAnnotationsToPDF(oInputDocumentBuffer, oAnnotations)
|
||||
Return PDFBurner.BurnAnnotsToPDF(oInputDocumentBuffer, oAnnotations, pEnvelopeData.EnvelopeId)
|
||||
End Function
|
||||
|
||||
Private Function GetEnvelopeData(pEnvelopeId As Integer) As EnvelopeData
|
||||
|
||||
@@ -2,10 +2,15 @@
|
||||
Imports System.Drawing
|
||||
Imports System.IO
|
||||
Imports DevExpress.DataProcessing
|
||||
Imports DigitalData.Core.Abstraction.Application.Repository
|
||||
Imports DigitalData.Core.Abstractions
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports EnvelopeGenerator.CommonServices.Jobs.FinalizeDocument.FinalizeDocumentExceptions
|
||||
Imports EnvelopeGenerator.Domain.Entities
|
||||
Imports EnvelopeGenerator.PdfEditor
|
||||
Imports GdPicture14
|
||||
Imports Microsoft.EntityFrameworkCore
|
||||
Imports Newtonsoft.Json
|
||||
|
||||
Namespace Jobs.FinalizeDocument
|
||||
@@ -15,9 +20,6 @@ Namespace Jobs.FinalizeDocument
|
||||
Private ReadOnly Manager As AnnotationManager
|
||||
Private ReadOnly LicenseManager As LicenseManager
|
||||
|
||||
Private Const ANNOTATION_TYPE_IMAGE = "pspdfkit/image"
|
||||
Private Const ANNOTATION_TYPE_INK = "pspdfkit/ink"
|
||||
Private Const ANNOTATION_TYPE_WIDGET = "pspdfkit/widget"
|
||||
Private Property _pdfBurnerParams As PDFBurnerParams
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pGDPictureLicenseKey As String, pdfBurnerParams As PDFBurnerParams)
|
||||
@@ -31,7 +33,28 @@ Namespace Jobs.FinalizeDocument
|
||||
_pdfBurnerParams = pdfBurnerParams
|
||||
End Sub
|
||||
|
||||
Public Function BurnInstantJSONAnnotationsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte()
|
||||
#Region "Burn PDF"
|
||||
Public Function BurnAnnotsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String), envelopeId As Integer) As Byte()
|
||||
'read the elements of envelope with their annotations
|
||||
Dim sigRepo = Factory.Shared.Repository(Of Signature)()
|
||||
Dim elements = sigRepo _
|
||||
.Where(Function(sig) sig.Document.EnvelopeId = envelopeId) _
|
||||
.Include(Function(sig) sig.Annotations) _
|
||||
.ToList()
|
||||
|
||||
Return If(elements.Any(),
|
||||
BurnElementAnnotsToPDF(pSourceBuffer, elements),
|
||||
BurnInstantJSONAnnotsToPDF(pSourceBuffer, pInstantJSONList))
|
||||
End Function
|
||||
|
||||
Public Function BurnElementAnnotsToPDF(pSourceBuffer As Byte(), elements As List(Of Signature)) As Byte()
|
||||
' Add background
|
||||
Using doc As Pdf(Of MemoryStream, MemoryStream) = Pdf.FromMemory(pSourceBuffer)
|
||||
Return doc.Background(elements).ExportStream().ToArray()
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function BurnInstantJSONAnnotsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String)) As Byte()
|
||||
Dim oResult As GdPictureStatus
|
||||
Using oSourceStream As New MemoryStream(pSourceBuffer)
|
||||
' Open PDF
|
||||
@@ -68,7 +91,9 @@ Namespace Jobs.FinalizeDocument
|
||||
End Using
|
||||
End Using
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
#Region "Add Value"
|
||||
Private Sub AddInstantJSONAnnotationToPDF(pInstantJSON As String)
|
||||
Dim oAnnotationData = JsonConvert.DeserializeObject(Of AnnotationData)(pInstantJSON)
|
||||
|
||||
@@ -78,16 +103,13 @@ Namespace Jobs.FinalizeDocument
|
||||
Logger.Debug("Adding AnnotationID: " + oAnnotation.id)
|
||||
|
||||
Select Case oAnnotation.type
|
||||
Case ANNOTATION_TYPE_IMAGE
|
||||
|
||||
Case AnnotationType.Image
|
||||
AddImageAnnotation(oAnnotation, oAnnotationData.attachments)
|
||||
Exit Select
|
||||
|
||||
Case ANNOTATION_TYPE_INK
|
||||
Case AnnotationType.Ink
|
||||
AddInkAnnotation(oAnnotation)
|
||||
Exit Select
|
||||
|
||||
Case ANNOTATION_TYPE_WIDGET
|
||||
Case AnnotationType.Widget
|
||||
'Add form field values
|
||||
Dim formFieldValue = oAnnotationData.formFieldValues.FirstOrDefault(Function(fv) fv.name = oAnnotation.id)
|
||||
If formFieldValue IsNot Nothing AndAlso Not _pdfBurnerParams.IgnoredLabels.Contains(formFieldValue.value) Then
|
||||
@@ -150,7 +172,9 @@ Namespace Jobs.FinalizeDocument
|
||||
ant.FontStyle = _pdfBurnerParams.FontStyle
|
||||
Manager.SaveAnnotationsToPage()
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
#Region "Helpers"
|
||||
Private Function ToPointF(pPoints As List(Of Single)) As PointF
|
||||
Dim oPoints = pPoints.Select(AddressOf ToInches).ToList()
|
||||
Return New PointF(oPoints.Item(0), oPoints.Item(1))
|
||||
@@ -163,6 +187,14 @@ Namespace Jobs.FinalizeDocument
|
||||
Private Function ToInches(pValue As Single) As Single
|
||||
Return pValue / 72
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
#Region "Model"
|
||||
Friend Class AnnotationType
|
||||
Public Const Image As String = "pspdfkit/image"
|
||||
Public Const Ink As String = "pspdfkit/ink"
|
||||
Public Const Widget As String = "pspdfkit/widget"
|
||||
End Class
|
||||
|
||||
Friend Class AnnotationData
|
||||
Public Property annotations As List(Of Annotation)
|
||||
@@ -293,5 +325,6 @@ Namespace Jobs.FinalizeDocument
|
||||
Public Property name As String
|
||||
Public Property value As String
|
||||
End Class
|
||||
#End Region
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
<packages>
|
||||
<package id="AutoMapper" version="10.1.1" targetFramework="net462" />
|
||||
<package id="BouncyCastle.Cryptography" version="2.5.0" targetFramework="net462" />
|
||||
<package id="DigitalData.Core.Abstraction.Application" version="1.3.7" targetFramework="net462" />
|
||||
<package id="DigitalData.Core.Abstractions" version="4.1.1" targetFramework="net462" />
|
||||
<package id="DigitalData.Core.Abstraction.Application" version="1.4.0" targetFramework="net462" />
|
||||
<package id="DigitalData.Core.Abstractions" version="4.2.0" targetFramework="net462" />
|
||||
<package id="DigitalData.Modules.Base" version="1.3.8" targetFramework="net462" />
|
||||
<package id="DigitalData.Modules.Config" version="1.3.0" targetFramework="net462" />
|
||||
<package id="DigitalData.Modules.Database" version="2.3.5.4" targetFramework="net462" />
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace EnvelopeGenerator.Domain.Entities
|
||||
#endif
|
||||
|
||||
[Table("TBSIG_DOCUMENT_RECEIVER_ELEMENT_ANNOTATION")]
|
||||
public class Annotation
|
||||
public class ElementAnnotation
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
@@ -114,7 +114,7 @@ public class Signature : ISignature, IHasReceiver
|
||||
#endif
|
||||
Receiver { get; set; }
|
||||
|
||||
public virtual IEnumerable<Annotation>
|
||||
public virtual IEnumerable<ElementAnnotation>
|
||||
#if NET
|
||||
?
|
||||
#endif
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<PackageReference Include="DigitalData.EmailProfilerDispatcher.Abstraction.Attributes" Version="1.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="UserManager.Domain" Version="3.2.3" />
|
||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="4.1.1" />
|
||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="4.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.66" />
|
||||
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.3.7" />
|
||||
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.4.0" />
|
||||
<PackageReference Include="DigitalData.Core.Infrastructure" Version="2.4.5" />
|
||||
<PackageReference Include="QuestPDF" Version="2025.7.1" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
using iText.Kernel.Pdf.Canvas;
|
||||
using EnvelopeGenerator.Domain.Interfaces;
|
||||
using iText.Kernel.Colors;
|
||||
using iText.Kernel.Geom;
|
||||
#if NETFRAMEWORK
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
#endif
|
||||
@@ -19,6 +17,15 @@ namespace EnvelopeGenerator.PdfEditor
|
||||
{
|
||||
return new Pdf<MemoryStream, MemoryStream>(new MemoryStream(documentBytes), new MemoryStream());
|
||||
}
|
||||
|
||||
public static Pdf<MemoryStream, MemoryStream> FromMemory(MemoryStream stream, MemoryStream
|
||||
#if NET
|
||||
?
|
||||
#endif
|
||||
outputStream = null)
|
||||
{
|
||||
return new Pdf<MemoryStream, MemoryStream>(stream, outputStream ?? new MemoryStream(), disposeInputStream: false, disposeOutputStream: outputStream is null);
|
||||
}
|
||||
}
|
||||
|
||||
public class Pdf<TInputStream, TOutputStream> : IDisposable, IAsyncDisposable
|
||||
@@ -31,13 +38,18 @@ namespace EnvelopeGenerator.PdfEditor
|
||||
private readonly PdfReader _reader;
|
||||
private readonly PdfWriter _writer;
|
||||
|
||||
public Pdf(TInputStream inputStream, TOutputStream outputStream)
|
||||
private readonly bool _disposeInputStream;
|
||||
private readonly bool _disposeOutputStream;
|
||||
|
||||
public Pdf(TInputStream inputStream, TOutputStream outputStream, bool disposeInputStream = true, bool disposeOutputStream = true)
|
||||
{
|
||||
_inputStream = inputStream;
|
||||
_outputStream = outputStream;
|
||||
_reader = new PdfReader(inputStream);
|
||||
_writer = new PdfWriter(outputStream);
|
||||
_doc = new PdfDocument(_reader, _writer);
|
||||
_disposeInputStream = disposeInputStream;
|
||||
_disposeOutputStream = disposeOutputStream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -149,16 +161,16 @@ namespace EnvelopeGenerator.PdfEditor
|
||||
{
|
||||
// Managed resources
|
||||
_doc?.Close();
|
||||
_inputStream?.Dispose();
|
||||
_outputStream?.Dispose();
|
||||
if (_disposeInputStream) _inputStream?.Dispose();
|
||||
if(_disposeOutputStream) _outputStream?.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
// When called by the finalizer, clean up only unmanaged resources
|
||||
// Unmanaged resources such as PdfDocument, PdfReader, and PdfWriter are already IDisposable; we close them here
|
||||
try { _doc?.Close(); } catch { }
|
||||
try { _inputStream?.Dispose(); } catch { }
|
||||
try { _outputStream?.Dispose(); } catch { }
|
||||
try { if(_disposeInputStream) _inputStream?.Dispose(); } catch { }
|
||||
try { if (_disposeOutputStream) _outputStream?.Dispose(); } catch { }
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
@@ -170,15 +182,21 @@ namespace EnvelopeGenerator.PdfEditor
|
||||
return;
|
||||
|
||||
_doc?.Close();
|
||||
if (_inputStream is IAsyncDisposable asyncInput)
|
||||
await asyncInput.DisposeAsync();
|
||||
else
|
||||
_inputStream.Dispose();
|
||||
if (_disposeInputStream)
|
||||
{
|
||||
if (_inputStream is IAsyncDisposable asyncInput)
|
||||
await asyncInput.DisposeAsync();
|
||||
else
|
||||
_inputStream.Dispose();
|
||||
}
|
||||
|
||||
if (_outputStream is IAsyncDisposable asyncOutput)
|
||||
await asyncOutput.DisposeAsync();
|
||||
else
|
||||
_outputStream?.Dispose();
|
||||
if (_disposeOutputStream)
|
||||
{
|
||||
if (_outputStream is IAsyncDisposable asyncOutput)
|
||||
await asyncOutput.DisposeAsync();
|
||||
else
|
||||
_outputStream?.Dispose();
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bogus" Version="35.6.3" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.3.7" />
|
||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="4.1.1" />
|
||||
<PackageReference Include="DigitalData.Core.Abstraction.Application" Version="1.4.0" />
|
||||
<PackageReference Include="DigitalData.Core.Abstractions" Version="4.2.0" />
|
||||
<PackageReference Include="DigitalData.Core.API" Version="2.2.1" />
|
||||
<PackageReference Include="DigitalData.Core.Application" Version="3.4.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.20" />
|
||||
|
||||
Reference in New Issue
Block a user