PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 11:57 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Gray background on page
PostPosted: Mon Feb 20, 2023 1:31 am 
Offline

Joined: Mon Feb 20, 2023 1:26 am
Posts: 5
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;
}


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 20, 2023 2:23 am 
Offline

Joined: Mon Feb 20, 2023 1:26 am
Posts: 5
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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 20, 2023 10:07 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
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

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 20, 2023 1:59 pm 
Offline

Joined: Mon Feb 20, 2023 1:26 am
Posts: 5
Thank you for your hep. The image is displaying now.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 154 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group