We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

System.threading.threadabortexception while saving the document on to the client browser

aspose document.save causing Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

PdfStamper pdfStamper = new PdfStamper(TemplateName, CollectionOfStampTextDetails);
string id = Guid.NewGuid().ToString();
ld_document = pdfStamper.StampDetails();
response.Clear();
ld_document.Save(response, id + “.pdf”, ContentDisposition.Attachment, new PdfSaveOptions());
response.End();

Hi there,


Thanks for your inquriy. It seems you shave shared itext code. We will appreciate it if you please share your sample Aspose related code and input/output document, so we will look into it and guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

if (CollectionOfStampTextDetails.Count > 0)
{
PdfStamper pdfStamper = new PdfStamper(TemplateName, CollectionOfStampTextDetails);
string id = Guid.NewGuid().ToString();
ld_document = pdfStamper.StampDetails();
ld_document.Save(HttpContext.Current.Response, id + “.pdf”, ContentDisposition.Attachment, new PdfSaveOptions());
}

The above piece of code PdfStamper is a class which actually stamps the data on to a PDF document .
In the constructor event of PdfStamper we are applying the aspose license

public PdfStamper()
{
applyLicense();
}

private void applyLicense()

pdfStamper.StampDetails(); is the method which does the stamping and returns the document .

public Document StampDetails()
{
string PdftemplateFileloactionNotFound, NoPdfCollection, NoPages;
PdftemplateFileloactionNotFound = “PdftemplateFileloactionNotFound”;
NoPdfCollection = “NoPdfCollection”;
NoPages = “NoPages”;

if (String.IsNullOrEmpty(PdftemplateFileloaction))
{
throw new Exception(PdftemplateFileloactionNotFound);
}

if (CollectionOfPdfText == null || CollectionOfPdfText.Count() < 1)
{
throw new Exception(NoPdfCollection);
}

Document pdfDocument = new Document(PdftemplateFileloaction);
if (pdfDocument.Pages.Count < 1)
{
throw new Exception(NoPages);
}
Page pdfPage = (Page)pdfDocument.Pages[1];
int currentPageNo = 1;
foreach (StampTextDetails TestProperty in CollectionOfPdfText)
{
if (TestProperty.PdfText.Trim().Length > 0)
{
if (currentPageNo != TestProperty.PdfPageNumber)
{
pdfPage = (Page)pdfDocument.Pages[TestProperty.PdfPageNumber > 0 ? TestProperty.PdfPageNumber : 1];
currentPageNo = TestProperty.PdfPageNumber;
}
TextFragment textFragment = new TextFragment(TestProperty.PdfText);
textFragment.Position = new Position(TestProperty.PdfTextXpos, TestProperty.PdfTextYpos);
textFragment.TextState.FontSize = TestProperty.PdfTextFontSize > 0 ? TestProperty.PdfTextFontSize : 10;
textFragment.TextState.Font = FontRepository.FindFont(String.IsNullOrEmpty(TestProperty.PdfTextFont) ? “TimesNewRoman” : TestProperty.PdfTextFont);
textFragment.TextState.FontStyle = TestProperty.PdfTextBold?FontStyles.Bold: FontStyles.Regular;
TextBuilder textBuilder = new TextBuilder(pdfPage);
textBuilder.AppendText(textFragment);
}
}
return pdfDocument;
}

Using the returned document I am trying to send it to clients browser using

ld_document.Save(HttpContext.Current.Response, id + “.pdf”, ContentDisposition.Attachment, new PdfSaveOptions());

But here I get system.threading.threadabort exception as saveas dialogue box appears to the client to download the file and no further processing of code is happening .

Hi there,


Thanks for sharing your sample code. But I am afraid I am unable to test your code due to missing references. However I have tested your sample code with minor changes but I am getting NullPointerReference at Save() method. I will appreciate it if you please share a sample project, so we will try to replicate the issue at our end and will guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,