Updating
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using PdfSharp.Pdf;
|
||||
using PdfSharp.Pdf.IO;
|
||||
using LCU.Library.Internal.FileOperationsModels.Models;
|
||||
namespace LCU.Api.Internal.FileOperations.Validations;
|
||||
|
||||
public static class PdfValidations
|
||||
{
|
||||
private const string PdfPageDoesntExist = "PDF Page Doesn't Exist.";
|
||||
private const string PdfPageCantBeLessThanOne = "PDF Page Can't Be Less Than 1.";
|
||||
|
||||
public static RequestResponse ValidatePdfPageExists(RequestResponse requestResponse, string pdfName, int pageNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
PdfDocument inputDocument = PdfReader.Open(pdfName, PdfDocumentOpenMode.Import);
|
||||
|
||||
if(pageNumber <= 0)
|
||||
{
|
||||
requestResponse.IsSuccessful = false;
|
||||
requestResponse.MessageStack.Add(PdfPageCantBeLessThanOne);
|
||||
}
|
||||
|
||||
if (pageNumber > inputDocument.PageCount)
|
||||
{
|
||||
requestResponse.IsSuccessful = false;
|
||||
requestResponse.MessageStack.Add(PdfPageDoesntExist);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
requestResponse.IsSuccessful = false;
|
||||
requestResponse.MessageStack.Add(exception.Message);
|
||||
}
|
||||
|
||||
return requestResponse;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user