MVC view to pdf a second blank page is added. This page is good but why is there a second page added. I searched aspose there other posts say it is margins. I changed the margins down to 1 for all 4 sides and still get second page. Also some posts say it is the page width and length and I am using A4 width and length. I want 8 1/2 x 11 so that is why I picked A4.
@{
Layout = null;
}
// ASPOSE
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Pdf.lic");
string html = ViewRenderer.RenderView("/myProject/Views/Home/GeneratePDFaspose2.cshtml", Session["viewModel"]);
// convert string to stream
byte[] byteArray = Encoding.UTF8.GetBytes(html);
//byte[] byteArray = Encoding.ASCII.GetBytes(contents);
MemoryStream stream = new MemoryStream(byteArray);
// import an HTML document
Aspose.Pdf.HtmlLoadOptions options = new Aspose.Pdf.HtmlLoadOptions();
options.PageInfo.IsLandscape = false;
options.PageInfo.Margin.Top = 25;
options.PageInfo.Margin.Left = 25;
options.PageInfo.Margin.Right = 25;
options.PageInfo.Margin.Bottom = 25;
options.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;
options.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(stream, options);
pdfDocument.Pages.Add();
ArrayList watermark = new ArrayList();
watermark.Add("UNOFFICIAL");
//watermark.Add(" ");
//watermark.Add(" ");
//watermark.Add("UNOFFICIAL");
//watermark.Add(" ");
//watermark.Add(" ");
//watermark.Add("UNOFFICIAL");
// arrange multiline text stamp text
FormattedText ft = new FormattedText(watermark[0].ToString(), System.Drawing.Color.LightGray, "Helvetica", EncodingType.Winansi, false, 80);
for (int i = 1; i < watermark.Count; i++)
ft.AddNewLineText(watermark[i].ToString());
TextStamp stamp = new TextStamp(ft);
stamp.Background = true;
stamp.Opacity = 0.5;
stamp.RotateAngle = -45;
//stamp.TextAlignment = HorizontalAlignment.Left;
stamp.TextAlignment = HorizontalAlignment.Center;
//stamp.HorizontalAlignment = HorizontalAlignment.Left;
stamp.HorizontalAlignment = HorizontalAlignment.Center;
//stamp.VerticalAlignment = VerticalAlignment.Center;
// add stamp to page collection
pdfDocument.Pages[1].AddStamp(stamp);
MemoryStream stream2 = new MemoryStream();
pdfDocument.Save(stream2, Aspose.Pdf.SaveFormat.Pdf);
return File(stream2.ToArray(), "application/pdf", "myFile.pdf");