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.