Hi,
I am using Aspose Pdf for .net 3.5 framework. I am trying to add background color and border for Pdf page other than header and footer but I am not able to do it. Can you please help me on this?
Hi,
I am using Aspose Pdf for .net 3.5 framework. I am trying to add background color and border for Pdf page other than header and footer but I am not able to do it. Can you please help me on this?
Hi Ashokkumar,
Aspose.Pdf.Document
pdfDocument = new Aspose.Pdf.Document();<o:p></o:p>
var page = pdfDocument.Pages.Insert(1);
page.Background = Aspose.Pdf.Color.Red;
pdfDocument.Save(“c:/pdftest/PageWithBackGround_Color.pdf”);
Pdf pdf = new Pdf();<o:p></o:p>
Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();
sec1.PageInfo.PageBorder = new ASPDF.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All);
sec1.PageInfo.PageBorder.SetBorderStyle((int)Aspose.Pdf.Generator.BorderSide.All, ASPDF.Generator.BorderStyle.Double);
sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text("Hello WOrld.."));
pdf.Save(“c:/pdftest/PDFwithBorder.pdf”);
Hi,
Thanks for the reply, I added header, body and footer in sec1(pdf page). I want to set background color and border for only body section but not header and footer part.
Can you look into the request.
Hi Ashokkumar,
Pdf pdf = new Pdf();<o:p></o:p>
Aspose.Pdf.Generator.Section sec1 = pdf.Sections.Add();
sec1.PageInfo.PageBorder = new Aspose.Pdf.Generator.BorderInfo((int)Aspose.Pdf.Generator.BorderSide.All);
sec1.PageInfo.PageBorder.SetBorderStyle((int)Aspose.Pdf.Generator.BorderSide.All, Aspose.Pdf.Generator.BorderStyle.Double);
// instantiate Document object with Pdf instance
Document document = new Document(pdf);
// create headerfooter object
Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
header.Margin.Top = 5;
header.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Header Text..."));
document.Pages[1].Header = header;
int pageHeight = (int)document.Pages[1].CropBox.Height;
int pageWidth = (int)document.Pages[1].CropBox.Width;
// set floating box width equal to page width minus left marin
// -6 is the width of double border being used
Aspose.Pdf.FloatingBox fbox = new Aspose.Pdf.FloatingBox((pageWidth - (int)document.Pages[1].PageInfo.Margin.Left -6), (pageHeight - (int)document.Pages[1].PageInfo.Margin.Top -6));
// specify the left origin of FloatingBox
fbox.Left = -42;
fbox.Top = -33;
// background color for FloatingBox
fbox.BackgroundColor = Aspose.Pdf.Color.Yellow;
// background color for whole PDF file
document.Background= Aspose.Pdf.Color.LightBlue;
fbox.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Hello WOrld..in FloatingBox"));
document.Pages[1].Paragraphs.Add(fbox);
document.Save("c:/pdftest/PDFwithBorder.pdf");