clean up pages, dont send the document to server
This commit is contained in:
192
EnvelopeGenerator.Web/Classes/PDFBurner.cs
Normal file
192
EnvelopeGenerator.Web/Classes/PDFBurner.cs
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using DigitalData.Modules.Base;
|
||||||
|
using DigitalData.Modules.Logging;
|
||||||
|
using GdPicture14;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace EnvelopeGenerator.Web.Classes
|
||||||
|
{
|
||||||
|
public partial class PDFBurner : BaseClass
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly string LicenseKey;
|
||||||
|
private readonly AnnotationManager Manager;
|
||||||
|
private readonly LicenseManager LicenseManager;
|
||||||
|
|
||||||
|
private const string ANNOTATION_TYPE_IMAGE = "pspdfkit/image";
|
||||||
|
private const string ANNOTATION_TYPE_INK = "pspdfkit/ink";
|
||||||
|
|
||||||
|
public PDFBurner(LogConfig pLogConfig, string pGDPictureLicenseKey) : base(pLogConfig)
|
||||||
|
{
|
||||||
|
|
||||||
|
LicenseKey = pGDPictureLicenseKey;
|
||||||
|
LicenseManager = new LicenseManager();
|
||||||
|
LicenseManager.RegisterKEY(pGDPictureLicenseKey);
|
||||||
|
|
||||||
|
Manager = new AnnotationManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool BurnInstantJSONAnnotationsToPDF(string pSourcePath, List<string> pInstantJSONList, string pDestinationPath)
|
||||||
|
{
|
||||||
|
if (Manager.InitFromFile(pSourcePath) != GdPictureStatus.OK)
|
||||||
|
{
|
||||||
|
Logger.Warn("Could not open file [{0}] for burning.", pSourcePath);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var oJSON in pInstantJSONList)
|
||||||
|
{
|
||||||
|
if (AddInstantJSONAnnotationToPDF(oJSON) == false)
|
||||||
|
{
|
||||||
|
Logger.Warn("Adding Annotation failed. Exiting");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Manager.BurnAnnotationsToPage(RemoveInitialAnnots: true, VectorMode: true);
|
||||||
|
Manager.SaveDocumentToPDF(pDestinationPath);
|
||||||
|
Manager.Close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Warn("Could not burn and save annotations to file [{0}]!", pDestinationPath);
|
||||||
|
Logger.Error(ex);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool AddInstantJSONAnnotationToPDF(string pInstantJSON)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var oAnnotationData = JsonConvert.DeserializeObject<AnnotationData>(pInstantJSON);
|
||||||
|
|
||||||
|
foreach (Annotation oAnnotation in oAnnotationData.annotations)
|
||||||
|
{
|
||||||
|
switch (oAnnotation.type)
|
||||||
|
{
|
||||||
|
case ANNOTATION_TYPE_IMAGE:
|
||||||
|
{
|
||||||
|
AddImageAnnotation(oAnnotation, oAnnotationData.attachments);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ANNOTATION_TYPE_INK:
|
||||||
|
{
|
||||||
|
AddInkAnnotation(oAnnotation);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Warn("Could not create annotation from InstantJSON");
|
||||||
|
Logger.Error(ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool AddImageAnnotation(Annotation pAnnotation, Dictionary<string, Attachment> pAttachments)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var oAttachment = pAttachments.Where(a => (a.Key ?? "") == (pAnnotation.imageAttachmentId ?? "")).SingleOrDefault();
|
||||||
|
|
||||||
|
// Convert pixels to Inches
|
||||||
|
var oBounds = pAnnotation.bbox.Select(ToInches).ToList();
|
||||||
|
|
||||||
|
float oX = oBounds[0];
|
||||||
|
float oY = oBounds[1];
|
||||||
|
float oWidth = oBounds[2];
|
||||||
|
float oHeight = oBounds[3];
|
||||||
|
|
||||||
|
Manager.AddEmbeddedImageAnnotFromBase64(oAttachment.Value.binary, oX, oY, oWidth, oHeight);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Warn("Could not add image annotation!");
|
||||||
|
Logger.Error(ex);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool AddInkAnnotation(Annotation pAnnotation)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var oSegments = pAnnotation.lines.points;
|
||||||
|
var oColor = ColorTranslator.FromHtml(pAnnotation.strokeColor);
|
||||||
|
Manager.SelectPage(pAnnotation.pageIndex);
|
||||||
|
|
||||||
|
foreach (List<List<float>> oSegment in oSegments)
|
||||||
|
{
|
||||||
|
var oPoints = oSegment.Select(ToPointF).ToArray();
|
||||||
|
Manager.AddFreeHandAnnot(oColor, oPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Warn("Could not add image annotation!");
|
||||||
|
Logger.Error(ex);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private PointF ToPointF(List<float> pPoints)
|
||||||
|
{
|
||||||
|
var oPoints = pPoints.Select(ToInches).ToList();
|
||||||
|
return new PointF(oPoints[0], oPoints[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float ToInches(float pValue)
|
||||||
|
{
|
||||||
|
return pValue / 72f;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal partial class AnnotationData
|
||||||
|
{
|
||||||
|
public List<Annotation> annotations { get; set; }
|
||||||
|
public Dictionary<string, Attachment> attachments { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal partial class Annotation
|
||||||
|
{
|
||||||
|
public string id { get; set; }
|
||||||
|
public List<float> bbox { get; set; }
|
||||||
|
public string type { get; set; }
|
||||||
|
public bool isSignature { get; set; }
|
||||||
|
public string imageAttachmentId { get; set; }
|
||||||
|
public Lines lines { get; set; }
|
||||||
|
public int pageIndex { get; set; }
|
||||||
|
public string strokeColor { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal partial class Lines
|
||||||
|
{
|
||||||
|
public List<List<List<float>>> points { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal partial class Attachment
|
||||||
|
{
|
||||||
|
public string binary { get; set; }
|
||||||
|
public string contentType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="NLog" Version="5.2.5" />
|
<PackageReference Include="NLog" Version="5.2.5" />
|
||||||
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
|
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
@@ -32,6 +33,9 @@
|
|||||||
<Reference Include="DigitalData.Modules.Logging">
|
<Reference Include="DigitalData.Modules.Logging">
|
||||||
<HintPath>..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
|
<HintPath>..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="GdPicture.NET.14">
|
||||||
|
<HintPath>D:\ProgramFiles\GdPicture.NET 14\Redist\GdPicture.NET (.NET Framework 4.5)\GdPicture.NET.14.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Privacy Policy";
|
ViewData["Title"] = "Dokument unterschrieben";
|
||||||
}
|
}
|
||||||
|
|
||||||
<div id="page-success" class="container p-5">
|
<div id="page-success" class="container p-5">
|
||||||
@@ -10,11 +10,11 @@
|
|||||||
<path d="M15.354 3.354a.5.5 0 0 0-.708-.708L8 9.293 5.354 6.646a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l7-7z" />
|
<path d="M15.354 3.354a.5.5 0 0 0-.708-.708L8 9.293 5.354 6.646a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l7-7z" />
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<h1>Umschlag erfolgreich signiert!</h1>
|
<h1>Dokument erfolgreich signiert!</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<section class="text-center">
|
<section class="text-center">
|
||||||
<p>Sie haben das Dokument erfolgreich signiert. Im Anschluss erhalten Sie eine schriftliche Bestätigung.</p>
|
<p>Sie haben das Dokument signiert. Im Anschluss erhalten Sie eine schriftliche Bestätigung.</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,18 +20,5 @@
|
|||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
|
||||||
<a href="#" id="url" target="_blank">Show image</a>
|
|
||||||
<img src="#" id="img" />
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
document.addEventListener("DOMContentLoaded", function() {
|
|
||||||
const anno = new Annotation()
|
|
||||||
anno.createAnnotationFrameBlob("Deine Mudda", 200, 80).then(url => document.getElementById("img").src = url)
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Privacy Policy";
|
ViewData["Title"] = "Dokument unterschreiben";
|
||||||
}
|
}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -64,8 +64,7 @@
|
|||||||
id: id,
|
id: id,
|
||||||
pageIndex: pageIndex,
|
pageIndex: pageIndex,
|
||||||
formFieldName: id,
|
formFieldName: id,
|
||||||
boundingBox: new PSPDFKit.Geometry.Rect({ width, height, top, left }),
|
boundingBox: new PSPDFKit.Geometry.Rect({ width, height, top, left })
|
||||||
backgroundColor: new PSPDFKit.Color({ r: 225, g: 29, b: 72 })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return annotation
|
return annotation
|
||||||
|
|||||||
@@ -185,19 +185,6 @@ class App {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flatten the annotations and save the document to disk
|
|
||||||
try {
|
|
||||||
const buffer = await this.Instance.exportPDF({ flatten: true });
|
|
||||||
const postDocumentResult = await this.Network.postDocument(this.envelopeKey, this.currentDocument.id, buffer);
|
|
||||||
|
|
||||||
if (postDocumentResult === false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user