Wrong Document Sent Back

We are experiencing an issue where documents sent to Aspose for signing are returned incorrectly — with the wrong document content.

We are currently leveraging Aspose.PDF for .NET, which is specifically used for manipulating PDF documents within our workflow. The key operations performed using the library include:

  • Dynamically populating data fields onto a cover page,
  • Applying a stamp image onto the PDF where required,
  • Converting a cover page (originally provided as a Word document link) and appending it to the beginning of the PDF,
  • Saving the final, updated PDF document back to its original storage location.

Our configurations is set to support a range of advanced PDF processing features, such as:

  • Adding metadata (title, author, subject, keywords),
  • Setting custom margins and header layouts,
  • Encrypting PDF documents,
  • Digitally signing documents with specified reason, contact, and location fields,
  • Utilizing predefined templates (e.g., for court-related documents).

While Word documents are referenced for cover pages, these are converted and embedded into the final PDF. We are not currently using Aspose.Words or Aspose.Cells directly, and PDF is the exclusive output format used in this workflow.

I have attached our process for uploading documents.
Filing documents on CRM.docx (754.7 KB)

@ttseabi

Could you please provide more details about the specific steps you are taking when sending documents for signing and how you determine that the wrong document content is being returned?

The full process is on the attached document, it also has screenshots.
Filing documents on CRM.docx (754.7 KB)

@ttseabi

You have shared a very high level information of your process. Can you please share the code snippet that is being used behind it? A sample PDF or set of PDF files is also needed to test the scenario. Please share some technical details and the minimal code part that seems to be culprit so that we can try to investigate the scenario in our environment and address it accordingly.

public static void UpdateCourtFile(CRMHelper crmHelper, CommonHelper helper, Entity courtFile, string courtFileDoctitle)
{
try
{
EntityCollection workingDocumentEntityCollection = null;
if (courtFile.Attributes.ContainsKey(Constants.CourtFileEntity.Attributes.claim))
{
DateTime dateOfService;
DateTime dateOfApplication;
string timeofService;
List workingDocumentList = new List();
WorkingDocumentCollection workingDocumentCollection = GetWorkingDocumentColl(crmHelper, courtFile.GetAttributeValue(Constants.CourtFileEntity.Attributes.claim).Id, courtFile, true);

         if (!courtFile.GetAttributeValue<bool>(Constants.CourtFileEntity.Attributes.IsFromClaim))
         {
             if (courtFile.GetAttributeValue<EntityReference>(Constants.CourtFileEntity.Attributes.application) != null)
             {
                 workingDocumentCollection.Application = courtFile.GetAttributeValue<EntityReference>(Constants.CourtFileEntity.Attributes.application).Id.ToString();
             }
         }
         if (courtFile.Attributes.Contains(Constants.CourtFileEntity.Attributes.Signature))
         {
             workingDocumentCollection.Signature = courtFile.GetAttributeValue<string>(Constants.CourtFileEntity.Attributes.Signature);
         }

         workingDocumentCollection.ClaimType = courtFileDoctitle;//+ DateTime.Now.ToString("yyyyMMddhhmmssfff");
         workingDocumentCollection.CourtFileTitle = courtFileDoctitle;


         if (courtFile.Attributes.ContainsKey(Constants.CourtFileEntity.Attributes.DateFiled)

&& courtFile.Attributes[Constants.CourtFileEntity.Attributes.DateFiled] != null
&& ((DateTime)courtFile.Attributes[Constants.CourtFileEntity.Attributes.DateFiled]) != DateTime.MinValue)
{
dateOfApplication = (DateTime)courtFile.Attributes[Constants.CourtFileEntity.Attributes.DateFiled];
workingDocumentCollection.ApplicationCreationDate = string.Format(
“{0}/{1}/{2}-{3}”,
dateOfApplication.Day,
dateOfApplication.Month,
dateOfApplication.Year,
DateTime.Now.ToLongTimeString());
}
else
{
dateOfApplication = DateTime.Now;
}

         ////if (courtFile.Attributes.ContainsKey(Constants.CourtFileEntity.Attributes.ListingDate)
         ////&& courtFile.Attributes[Constants.CourtFileEntity.Attributes.ListingDate] != null
         ////&& ((DateTime)courtFile.Attributes[Constants.CourtFileEntity.Attributes.ListingDate]) != DateTime.MinValue)
         ////{
         ////    dateOfService = (DateTime)courtFile.Attributes[Constants.CourtFileEntity.Attributes.ListingDate];
         ////    timeofService = dateOfService.ToLongTimeString();
         ////}
         ////else
         ////{
         dateOfService = DateTime.Now;
         timeofService = dateOfService.ToLongTimeString();
         ////}                    

         workingDocumentCollection.DateOfService = string.Format(
             CultureInfo.CurrentCulture,
             "{0}/{1}/{2}",
                     dateOfService.Day,
                     dateOfService.Month,
                     dateOfService.Year);
         //// Get Case - Attaching Documents

         workingDocumentCollection.TimeOfService = timeofService;
         //LogException(crmHelper._service, "UpdateCourtFile", $"courtFile::{courtFile.Id} workingDocumentCollection_ClaimType::{workingDocumentCollection.ClaimType}", "BusinessLogic", new Exception());

         workingDocumentEntityCollection = GetWorkingDocList(courtFile, crmHelper);
         if (workingDocumentEntityCollection != null && workingDocumentEntityCollection.Entities.Count > 0)
         {
             //// List all the Attaching Documents
             workingDocumentList.AddRange(from workingDocumentEntity in workingDocumentEntityCollection.Entities
                                          let workingDocumentModel = new WorkingDocument()
                                          select workingDocumentEntity.MapperOut(workingDocumentModel));
         }

         if (workingDocumentList.Count > 0)
         {
             //// Assign the list of working documents to Collection
             workingDocumentCollection.DocumentCollection = workingDocumentList;

             //MB 2025-03-22: this is where the document type is. trace where its coming from and change it to document title

             //// Pattern to match the first _YYYYMMDD_HHMMSS.pdf
             //string patterns = @"_[0-9]{7,8}_[0-9]{5,6}";

             //// Use Regex.Replace with MatchEvaluator to replace only the first occurrence
             //string fileNames = Regex.Replace(workingDocumentCollection.DocumentCollection.FirstOrDefault().DocTitle, patterns + @"$|\.pdf$", match => "", RegexOptions.None);


             // Pattern to match the first _YYYYMMDD_HHMMSS.pdf
             string pattern = @"_[0-9]{7,8}_[0-9]{5,6}";

             // Use Regex.Replace with MatchEvaluator to replace only the first occurrence
             string fileName = Regex.Replace(workingDocumentCollection.DocumentCollection.FirstOrDefault().DocTitle, pattern, match => "", RegexOptions.None);

             Console.WriteLine("After first regex: " + fileName); // Debugging step

             // Ensure we only keep the first ".pdf" and remove everything after
             //fileName = Regex.Replace(fileName, @"(\.pdf).*", "$1");
             fileName = Regex.Replace(fileName, @"\.pdf", "", RegexOptions.None);
             //string results = Regex.Replace((string)courtFile.Attributes[Constants.CourtFileEntity.Attributes.docTitle], pattern, "");
             workingDocumentCollection.CourtFileTitle = (string)courtFile.Attributes[Constants.CourtFileEntity.Attributes.docTitle];
             workingDocumentCollection.ClaimType = fileName;// + DateTime.Now.ToString("yyyyMMddhhmmssfff");

             //// Call Azure API here
             DocManagementHelper apiHelper = new DocManagementHelper(crmHelper);
             DispatcherRequest disp = new DispatcherRequest
             {
                 Operation = Constants.Setting.GetSharepointPath,
                 Input = new CommonHelper().SerializeJson(workingDocumentCollection)
             };

             var input = disp.Input;

             // LogException(crmHelper._service, "UpdateWorkingDocumentSharepointUrl", input, Constants.Setting.PluginClass, null);

             //MB to work here - call to Aspose here
             LogException(crmHelper._service, "AsposeDataForFileAproval", input, "BusinessProcess", new Exception("Test"), message: input);
             //// Get the courtFile response from ApproveClaim API
             string courtFileDocumentCollect = apiHelper.InvokeDocManagementAPI(disp);
             // LogException(crmHelper._service, "AsposeDataForFileAproval-Results", courtFileDocumentCollect, "BusinessProcess", new Exception("Test"), message: courtFileDocumentCollect);

             if (!string.IsNullOrEmpty(courtFileDocumentCollect))
             {
                 List<DocManagementAPIResponses> docManagementAPIResponses = helper.DeserializeJson<List<DocManagementAPIResponses>>(courtFileDocumentCollect);

                 WorkingDocumentCollection coll = new Models.WorkingDocumentCollection();
                 WorkingDocument doc = new Models.WorkingDocument();
                 if (docManagementAPIResponses != null && docManagementAPIResponses.Count > 0)
                 {
                     doc.SharePointLink = docManagementAPIResponses[0].SharePointURL;
                     doc.BlobLink = docManagementAPIResponses[0].blobURL;
                     coll.DocumentCollection = new List<WorkingDocument>();
                     /*Commenting the below code and adding the logic in newcaselinecontroller-UpdateCourtFileData*/
                     /* coll.DocumentCollection.Add(doc);
                      Entity updateEntity = new Entity(Constants.Entities.courtFile);
                      // Bug 297: Documents "Misfiled" by system
                      // updateEntity.Id = courtFile.Id;
                      updateEntity.Id = new Guid(docManagementAPIResponses[0].AcitivityID.ToString());
                      updateEntity[Constants.CourtFileEntity.Attributes.sharePointUrl] = docManagementAPIResponses[0].SharePointURL;
                      updateEntity[Constants.CourtFileEntity.Attributes.BlobLink] = coll.DocumentCollection[0].BlobLink;
                      crmHelper._service.Update(updateEntity);*/
                 }
             }
         }
     }
 }
 catch (Exception ex)
 {
     LogException(crmHelper._service, "UpdateCourtFile-exc", string.Empty, "BusinessProcess", ex, message: ex.Message);
     throw;
 }

}

@ttseabi

We are afraid that this code also does not contain any Aspose API related calls or methods. It will be a great help from you if you can share some details of the issue that you are facing with Aspose APIs and share the relevant code with us so that we can test the scenario in our environment and address it accordingly.

Good Day,

Please see this code

public string InvokeDocManagementAPI(DispatcherRequest dispatcher)
{
using (HttpClient _client = new HttpClient())
{
_client.BaseAddress = new Uri(baseAddress + dispatcher.Operation);
BusinessLogic.LogException(_crmHelper._service, “InvokeDocManagementAPI”, $“dispatcher.Operation::{dispatcher.Operation} dispatcher.address::{_client.BaseAddress}”, “DocManagementHelper”, new Exception());
HttpContent content = new StringContent(dispatcher.Input, Encoding.UTF8, “application/json”);
try
{
BusinessLogic.LogException(_crmHelper._service, “InvokeDocManagementAPI”, $“inside try - calling aspose:”, “DocManagementHelper”, new Exception());

              // content = new StringContent(dispatcher.Input);
              var result = _client.PostAsync(_client.BaseAddress, content).Result;
              //To Do : catch the correct error
              BusinessLogic.LogException(_crmHelper._service, "InvokeDocManagementAPI", $"Aspose _ result::{result.Content.ReadAsStringAsync().Result}", "DocManagementHelper", new Exception());

              result.EnsureSuccessStatusCode();
              return result.Content.ReadAsStringAsync().Result;
          }
          catch (Exception ex)
          {
              BusinessLogic.LogException(_crmHelper._service, "InvokeDocManagementAPI", $"we failed - calling aspose we now on the catch:{ex.Message}", "DocManagementHelper", ex.InnerException);

              BusinessLogic.LogException(_crmHelper._service, "InvokeDocManagementAPI", $"dispatcher.Operation::{dispatcher.Operation}  error : {ex.Message}", "DocManagementHelper", ex.InnerException,ex.Message);
              //BusinessLogic.LogException(_crmHelper._service, dispatcher.Operation, dispatcher.Input, "DocManagementHelper", ex);
              throw new Exception(
                  string.Format(CultureInfo.CurrentCulture,"Error while invoking the Doc Management API APP. Resource - {0} , Request Message - {1} , Reason - {2}", this.baseAddress, dispatcher.Input, ex.Message));
          }
      }
  }

This is the sample data

{
    "Application": "e9af3409-b167-f011-a86d-0022481361af",
    "ApplicationCreationDate": "23/7/2025-12:37:33 PM",
    "AttachCoverPage": true,
    "BlobUrlAttributeLogicalName": "ecfs_bloburl",
    "Case": "26bbd813-ab67-f011-a86d-0022481361af",
    "CaseNumber": "2025-096",
    "CaseReferenceNumber": "HCGS14926",
    "CaseTitle": "popies  Mashaba  v. Mack  Malungane # 2025-096 # TestingwithteamCase",
    "ClaimType": "TestResults",
    "Court": "johannesburg",
    "CourtDivision": "Gauteng Local Division",
    "CourtFileTitle": "Answering Affidavit",
    "CourtLocation": "Appeal",
    "DateOfService": "23/7/2025",
    "Defendant": "Mack  Malungane ",
    "Division": "Gauteng Local Division",
    "DocumentCollection": [
        {
            "ApplicationId": "Answering Affidavit",
            "ApplicationReferenceNumber": null,
            "BlobFileName": null,
            "BlobLink": "https://ocjsndynusta01.blob.core.windows.net/applicationcontainer/TestResults_2025723_103713.pdf",
            "CaseId": "popies  Mashaba  v. Mack  Malungane # 2025-096 # TestingwithteamCase",
            "CourtFileDocumentId": null,
            "DocSequencenumber": "1",
            "DocTitle": "TestResults_2025723_103713",
            "DocumentType": null,
            "Id": null,
            "IsManual": false,
            "JudgementId": null,
            "OrderId": null,
            "SharePointLink": "https://ocjsndynusta01.blob.core.windows.net/applicationcontainer/TestResults_2025723_103713.pdf",
            "StatusOfDocument": "1",
            "VersionNumber": "1"
        }
    ],
    "EntityGuid": "faaf3409-b167-f011-a86d-0022481361af",
    "EntityLogicalName": "ecfs_courtfile",
    "HasDocumentChanged": false,
    "Location": "Appeal",
    "Plaintiff": "popies  Mashaba ",
    "Registrar": "SYSTEM",
    "SharepointUrlAttributeLogicalName": "ecfs_sharepointlink",
    "Signature": null,
    "TimeOfService": "12:37:33 PM"
}

@ttseabi

We understand that the code provided does not clearly demonstrate how Aspose.PDF is being utilized. However, we noticed a link to the PDF file within the sample data you shared. We will continue investigating to identify the potential issue.

To clarify, are you downloading the PDF from the sample data, signing it using Aspose.PDF for .NET, and then uploading it back to the server? If so, is the problem occurring when the uploaded PDF is returned incorrectly?

Good Day,

Yes you are correct the issue is when the document is sent back to us from Aspose.

Please do let me know if you have identified the issue.

Kind Regards

@ttseabi

Are you saying the returned document is a completely different PDF than the one provided, or is it the same PDF but contains incorrect information or issues that shouldn’t be there?

The document is completely different from the one that was sent.

@ttseabi

It is logically improbable for the API to return an incorrect document unless it receives such a document for processing and saving. There is a strong likelihood that, during the code execution, the API is being supplied with a different document to save and send.

This has made it challenging to replicate the issue in our environment. Therefore, we kindly request you to provide a sample application capable of reproducing a similar scenario. Unfortunately, the information provided so far is insufficient for us to recreate the issue and address it effectively. If you could share specific steps or additional details to help us reproduce the problem, we will proceed accordingly.