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,
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,