PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Gray background on page https://forum.pdfsharp.net/viewtopic.php?f=2&t=4418 |
Page 1 of 1 |
Author: | marty.nord [ Mon Feb 20, 2023 1:31 am ] |
Post subject: | Gray background on page |
When I render my document which contains a header and a table, it is rendering it with a gray background behind it. Please advise how to remove the gray background. Thank you. public static Document CreateReceipt(long userID) { // Create a new MigraDoc document Document document = new Document(); document.Info.Title = "Your Receipt"; document.Info.Subject = "Your Receipt"; document.Info.Author = "https://www.greenthumbhub.com"; MigraDoc.DocumentObjectModel.Style style = document.Styles["Normal"]; style.Font.Name = "Verdana"; style.Font.Size = 10; // Each MigraDoc document needs at least one section. Section section = document.AddSection(); // Put a logo in the header MigraDoc.DocumentObjectModel.Shapes.Image image = section.Headers.Primary.AddImage("/Images/header.jpg"); image.Height = "2.528in"; image.Width = "8in"; image.LockAspectRatio = true; //image.RelativeVertical = RelativeVertical.Line; //image.RelativeHorizontal = RelativeHorizontal.Margin; image.Top = ShapePosition.Top; image.Left = ShapePosition.Left; //image.WrapFormat.Style = WrapStyle.TopBottom; // Create footer Paragraph paragraph = section.Footers.Primary.AddParagraph(); paragraph.AddText("www.greenthumbhub.com - Receipt.pdf - " + DateTime.Today.ToShortDateString()); paragraph.Format.Font.Size = 10; paragraph.Format.Alignment = ParagraphAlignment.Center; // Create the item table MigraDoc.DocumentObjectModel.Tables.Table table = section.AddTable(); table.Style = "Table"; table.Borders.Color = Color.FromRgb(0, 0, 0); //table.Borders.Width = 0.25; //table.Borders.Left.Width = 0.5; //table.Borders.Right.Width = 0.5; table.Rows.LeftIndent = 0; // Before you can add a row, you must define the columns Column column = table.AddColumn("3in"); column.Format.Alignment = ParagraphAlignment.Center; column = table.AddColumn("3in"); column.Format.Alignment = ParagraphAlignment.Right; // Create the header of the table Row row = table.AddRow(); row.HeadingFormat = true; row.Format.Alignment = ParagraphAlignment.Center; row.Format.Font.Bold = true; row.Cells[0].AddParagraph("Product"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Center; row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[1].AddParagraph("Price"); row.Cells[1].Format.Font.Bold = true; row.Cells[1].Format.Alignment = ParagraphAlignment.Right; row.Cells[1].VerticalAlignment = VerticalAlignment.Bottom; List<CartInfo> cartItems = CartDAL.GetCart(userID); if (cartItems.Count > 0) { foreach (CartInfo item in cartItems) { row = table.AddRow(); row.Format.Alignment = ParagraphAlignment.Center; if (item.ProductID == GreenThumbConstants.PRODUCT_MONTHLY_AD && item.TermID == GreenThumbConstants.TERM_MONTH) { row.Cells[0].AddParagraph(item.Product + " - " + item.Quantity + " months"); } else if (item.ProductID == GreenThumbConstants.PRODUCT_YEARLY_AD && item.TermID == GreenThumbConstants.TERM_YEAR) { row.Cells[0].AddParagraph(item.Product + " - 1 Year"); } else if (item.ProductID == GreenThumbConstants.PRODUCT_DOWNLOADABLE_DIRECTORY && item.TermID == GreenThumbConstants.TERM_YEAR) { row.Cells[0].AddParagraph(item.Product + " - 1 Year"); } row.Cells[0].Format.Alignment = ParagraphAlignment.Center; row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[1].AddParagraph(item.SubTotal.ToString("C2")); row.Cells[1].Format.Alignment = ParagraphAlignment.Right; row.Cells[1].VerticalAlignment = VerticalAlignment.Bottom; } // calculate total price decimal total = 0; foreach (CartInfo item in cartItems) { if (item.SubTotal != 0) { total += item.SubTotal; } } // calculate card fee decimal card_fee = 0; if (total != 0) { card_fee = Math.Round(((total + Convert.ToDecimal(0.30)) / Convert.ToDecimal(0.971)) - total, 2, MidpointRounding.AwayFromZero); } total += card_fee; row = table.AddRow(); row.Format.Alignment = ParagraphAlignment.Center; row.Cells[0].AddParagraph("Card Fee"); row.Cells[0].Format.Alignment = ParagraphAlignment.Center; row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[1].AddParagraph(card_fee.ToString("C2")); row.Cells[1].Format.Alignment = ParagraphAlignment.Right; row.Cells[1].VerticalAlignment = VerticalAlignment.Bottom; row = table.AddRow(); row.Format.Alignment = ParagraphAlignment.Center; row.Cells[0].AddParagraph("Total"); row.Cells[0].Format.Alignment = ParagraphAlignment.Center; row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[1].AddParagraph(total.ToString("C2")); row.Cells[1].Format.Alignment = ParagraphAlignment.Right; row.Cells[1].VerticalAlignment = VerticalAlignment.Bottom; } row = table.AddRow(); row.Format.Alignment = ParagraphAlignment.Center; row.Cells[0].AddParagraph("Thank you for your business!"); row.Cells[0].Format.Alignment = ParagraphAlignment.Center; row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[0].MergeRight = 1; return document; } |
Author: | marty.nord [ Mon Feb 20, 2023 2:23 am ] |
Post subject: | Re: Gray background on page |
Weird thing is that the gray background went away but the header image will not display. I have tried several paths and none seem to work. ../Images/header.jpg /Images/header.jpg ~/Images/headerjpg None of these work and the image is not displaying. Any advice? Thank you. |
Author: | TH-Soft [ Mon Feb 20, 2023 10:07 am ] |
Post subject: | Re: Gray background on page |
marty.nord wrote: Any advice? You must know where the image is stored.Path like "images\header.jpg" or "..\images\header.jpg" are relative. You can set the WorkingDirectory for the PdfDocumentRenderer. Relative paths will be resolved from this working directory. You can convert the image to a BASE64 string to avoid using a file: http://pdfsharp.net/wiki/MigraDoc_FilelessImages.ashx |
Author: | marty.nord [ Mon Feb 20, 2023 1:59 pm ] |
Post subject: | Re: Gray background on page |
Thank you for your hep. The image is displaying now. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |