Im using Spire.Doc to convert docx to pdf.
I have a singleton service to handle a long running tasks like docx to pdf generation.
Solution is a Asp.net MVC 5 website hosted to Azure.
- Code: Select all
private void BuildInvoice( ... )
{
var repo = IoC.Resolve<IInvoiceRepository>();
Task.Factory.StartNew(() =>
{
lock (_lock)
{
using (Stream docStream = new MemoryStream())
using (Stream pdfStream = new MemoryStream())
{
using (DocX document = DocX.Load(template))
{
document.ReplaceText("{{CompanyName}}", company.Name);
document.ReplaceText("{{CompanyAddress}}", company.Contact.PostalAddress);
document.ReplaceText("{{Number}}", invoice.Reference);
document.ReplaceText("{{Date}}", DateTime.UtcNow.Date.ToShortDateString());
document.SaveAs(docStream);
}
Document doc = new Document();
doc.LoadFromStream(docStream, FileFormat.Docx);
doc.SaveToStream(pdfStream, FileFormat.PDF);
byte[] invoiceContent = StreamHelper.ToByteArray(pdfStream);
UpdateInvoice(repo, invoice.Id, invoiceContent);
SendInvoice(contacts, invoiceContent, invoice.Type, company);
}
}
});
}
Locally everything runs great, on azure it fails at line:
doc.SaveToStream(pdfStream, FileFormat.PDF);
with message:
A generic error occurred in GDI+
any ideas ?
Regards
Rasmus K.