have been working on this code for the past few months in which I am attempting to take the byte array of a pdf document, pass it through a memory stream and eventually parse the stream using Aspose.Pdf in order to read it and make a comparison. However, any time I reach the part of the code that is writing the stream, I receive an error message stating that “timeouts are not supported on this stream”. Can you please assist with this or know anyone that can help?
using System;
using System.Collections.Generic;
using System.Text;
namespace xxxxxxxx.Models
{
public class PDFDocuments
{
public string documentA { get; set; }
public string documentB { get; set; }
}
}
// POST api/
[HttpPost]
public async Task PostAsync([FromBody] PDFDocuments documents)
{
var documentA = documents.documentA;
var documentB = documents.documentB;
var result = ComparePdfs(documentA, documentB);
return result;
}
public static Bitmap ComparePdfs(string documentA, string documentB)
{
//Set License
SetLicense();
// Load the PDF files
byte[] firstpdfbytes = System.Text.Encoding.UTF8.GetBytes(documentA);
MemoryStream stream1 = new MemoryStream(firstpdfbytes);
stream1.Write(firstpdfbytes, 0, firstpdfbytes.Length);
Document document = new Document();
document.Pages.Add();
document.Save(stream1);
var doc1 = stream1;
byte[] secondPdfBytes = System.Text.Encoding.UTF8.GetBytes(documentB);
MemoryStream stream2 = new MemoryStream();
stream2.Write(secondPdfBytes, 0, secondPdfBytes.Length);
Document document2 = new Document();
document2.Pages.Add();
document2.Save(stream2);
var doc2 = stream2;
// Extract text from the first PDF
Document pdfDocument1 = new Document(doc1);
TextAbsorber textAbsorber1 = new TextAbsorber();
pdfDocument1.Pages.Accept(textAbsorber1);
string text1 = textAbsorber1.Text;