Hi we had Aspose.Total full license and we are using the same to generate PDF, Word and Excel documents. Even though we had a full license of aspose with us, while generating PDF’s, from last 4 months onwards we are facing this issue intermittently every week in any of the environment. Can you please help us asap as our clients are facing the issues in receiving notifications with pdf attachments.
Below is our code:
Void main ()
{
byte[] licenceBytes = GetLicenceBytes();
ValidateLicence(licenceBytes, fileExt);
GetHTMLtoPDF_V2(msHTMLStream, allowwatermark,isLandscape);
}
public byte[] GetLicenceBytes()
{
byte[] licence = null;
string asposeLicencePathUrl = null;
try
{
asposeLicencePathUrl = AppDomain.CurrentDomain.BaseDirectory + “/AsposeTotal/Aspose.Total.lic”;
licence = File.ReadAllBytes(asposeLicencePathUrl);
}
catch (CommunicationException ex)
{
// Log Exception here
throw;
}
return licence;
}
public void ValidateLicence(byte[] LicenceBytes, string fileExt)
{
try
{
Stream byteLicenceStream = new MemoryStream();
switch (fileExt)
{
case Gep.Cumulus.CSM.Entities.FileExtenstion.Word:
if (LicenceBytes == null)
{
BlValidateLicence = false;
break;
}
byteLicenceStream = new MemoryStream(LicenceBytes);
Aspose.Words.License licenseWord = new Aspose.Words.License();
licenseWord.SetLicense(byteLicenceStream);
BlValidateLicence = true;
break;
case Gep.Cumulus.CSM.Entities.FileExtenstion.PPT:
if (LicenceBytes == null)
{
BlValidateLicence = false;
break;
}
byteLicenceStream = new MemoryStream(LicenceBytes);
Aspose.Slides.License licensePpt = new Aspose.Slides.License();
licensePpt.SetLicense(byteLicenceStream);
BlValidateLicence = true;
break;
case Gep.Cumulus.CSM.Entities.FileExtenstion.PDF:
if (LicenceBytes == null)
{
BlValidateLicence = false;
break;
}
byteLicenceStream = new MemoryStream(LicenceBytes);
Aspose.Pdf.License licensePDF = new Aspose.Pdf.License();
licensePDF.SetLicense(byteLicenceStream);
BlValidateLicence = true;
break;
case Gep.Cumulus.CSM.Entities.FileExtenstion.Excel:
if (LicenceBytes == null)
{
BlValidateLicence = false;
break;
}
byteLicenceStream = new MemoryStream(LicenceBytes);
Aspose.Cells.License licenseExcel = new Aspose.Cells.License();
licenseExcel.SetLicense(byteLicenceStream);
BlValidateLicence = true;
break;
default:
BlValidateLicence = false;
break;
}
}
catch (Exception)
{
}
}
public byte[] GetHTMLtoPDF_V2(MemoryStream msHTMLStream, string allowwatermark = “”, bool isLandscape = false)
{
if (msHTMLStream == null)
throw new ArgumentNullException(“File Stream”);
byte[] htmlBytes = null;
Aspose.Pdf.HtmlLoadOptions htmlLoadOptions = new Aspose.Pdf.HtmlLoadOptions();
htmlLoadOptions.PageInfo.Margin.Left = 15;
htmlLoadOptions.PageInfo.Margin.Right = 15;
htmlLoadOptions.PageInfo.Margin.Top = 15;
htmlLoadOptions.PageInfo.Margin.Bottom = 15;
htmlLoadOptions.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
htmlLoadOptions.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;
htmlLoadOptions.InputEncoding = "UTF-8";
if (isLandscape)
{
htmlLoadOptions.PageInfo.IsLandscape = isLandscape;
htmlLoadOptions.PageInfo.Width = Aspose.Pdf.PageSize.A4.Height;
htmlLoadOptions.PageInfo.Height = Aspose.Pdf.PageSize.A4.Width;
}
using (MemoryStream msPDFStream = new MemoryStream())
{
msHTMLStream.Position = 0;
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(msHTMLStream, htmlLoadOptions);
int pagecount = pdfDocument.Pages.Count;
if (pagecount > 1)
{
//create page number stamp
PageNumberStamp pageNumberStamp = new PageNumberStamp();
//whether the stamp is background
pageNumberStamp.Background = false;
pageNumberStamp.Format = "Page # of " + pdfDocument.Pages.Count;
pageNumberStamp.BottomMargin = 6;
pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Center;
pageNumberStamp.StartingNumber = 1;
//set text properties
pageNumberStamp.TextState.Font = FontRepository.FindFont("Arial");
pageNumberStamp.TextState.FontSize = 9.0F;
pageNumberStamp.TextState.FontStyle = FontStyles.Bold;
pageNumberStamp.TextState.FontStyle = FontStyles.Italic;
//add stamp to particular page
//pdfDocument.Pages[1].AddStamp(pageNumberStamp);
foreach (Page page in pdfDocument.Pages)
{
page.AddStamp(pageNumberStamp);
}
}
if (allowwatermark != "" || allowwatermark != null || allowwatermark.Length > 0)
{
Aspose.Pdf.Facades.Stamp aStamp = new Aspose.Pdf.Facades.Stamp();
aStamp.Rotation = 45;
aStamp.IsBackground = false;
TextStamp textStamp = new TextStamp(allowwatermark);
textStamp.Opacity = 0.2;
textStamp.TextState.FontSize = 60.0F;
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.VerticalAlignment = VerticalAlignment.Center;
textStamp.RotateAngle = aStamp.Rotation;
textStamp.TextState.Font = FontRepository.FindFont("Arial");
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Gray;
// Adds Watermark in Page 1
//pdfDocument.Pages[1].AddStamp(textStamp);
//Adds Watermark in all Pages
foreach (Page page in pdfDocument.Pages)
{
page.AddStamp(textStamp);
}
}
pdfDocument.Save(msPDFStream);
htmlBytes = new byte[msPDFStream.Length];
htmlBytes = msPDFStream.ToArray();
}
return htmlBytes;
}