Hi
I'm using Migradoc version 1.31 and I want to be able to place an image over a table. I'm trying to achieve it by:
- Adding a TextFrame with wrapstyle through
- Adding a small spacer image
- Adding my Table to the TextFrame
- Adding a second TextFrame which will start at the same places as the last textframe
- Adding an icon Image to the second TextFrame, which will appear on top of the table
The issue with this method is that the first TextFrame does not grow to encompass of content inside it. Because of that, I can't set the height of the second TextFrame to match the first, and subsequent elements are added at about half way through the table.
Code is below, mostly irrelevant but rather too much than too little.
Code:
private void testOverlap(object sender, EventArgs e)
{
Document document = new Document();
DefineStyles(ref document);
document.DefaultPageSetup.TopMargin = "10mm";
document.DefaultPageSetup.LeftMargin = "10mm";
document.DefaultPageSetup.RightMargin = "10mm";
document.DefaultPageSetup.BottomMargin = "10mm";
document.DefaultPageSetup.PageHeight = "297mm";
document.DefaultPageSetup.PageWidth = "210mm";
Section s1 = document.AddSection();
s1.AddParagraph("Opening paragraph...");
s1.AddParagraph("");
TextFrame FirstTextFrame = s1.AddTextFrame();
FirstTextFrame.WrapFormat.Style = WrapStyle.Through;
FirstTextFrame.LineFormat.Width = "0.1mm";
Image trans = FirstTextFrame.AddImage("Z:\\Migradoc Testing\\Images\\transpix.png");
trans.Height = "1mm";
CreateFlightTable(ref FirstTextFrame);
FirstTextFrame.AddParagraph("");
TextFrame OverlappingTextFrame = s1.AddTextFrame();
OverlappingTextFrame.Height = FirstTextFrame.Height;
OverlappingTextFrame.LineFormat.Width = "0.1mm";
OverlappingTextFrame.LineFormat.Color = Colors.Red;
OverlappingTextFrame.MarginLeft = "2mm";
OverlappingTextFrame.AddImage("Z:\\Migradoc Testing\\Images\\test_flight_logo.png");
s1.AddParagraph("End paragraph.");
//Render
MigraDoc.Rendering.PdfDocumentRenderer pdfRenderer = new MigraDoc.Rendering.PdfDocumentRenderer(false, PdfSharp.Pdf.PdfFontEmbedding.Always);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
PdfSharp.Pdf.PdfDocument pdfdoc = pdfRenderer.PdfDocument;
pdfdoc.ViewerPreferences.FitWindow = false;
pdfdoc.PageLayout = PdfSharp.Pdf.PdfPageLayout.SinglePage;
pdfdoc.PageMode = PdfSharp.Pdf.PdfPageMode.UseNone;
string filename = "Z:\\scratch\\test.pdf";
pdfdoc.Save(filename);
System.Diagnostics.Process.Start(filename);
}
private void DefineStyles(ref Document doc)
{
Style style = doc.Styles["Normal"];
style.Font.Name = "Arial";
style.Font.Size = 8;
style = doc.Styles["Heading1"];
style.Font.Name = "Arial";
style.Font.Bold = true;
style.Font.Size = 10;
style.Font.Color = Colors.Black;
style = doc.Styles["Heading2"];
style.Font.Name = "Arial";
style.Font.Bold = true;
style.Font.Size = 9;
style.Font.Color = Colors.Black;
style = doc.Styles["Heading3"];
style.Font.Name = "Arial";
style.Font.Bold = true;
style.Font.Size = 10;
style.Font.Color = Colors.White;
style = doc.Styles["Heading4"];
style.Font.Name = "Arial";
style.Font.Bold = true;
style.Font.Size = 9;
style.Font.Color = Colors.White;
}
private void CreateFlightTable(ref TextFrame Obj)
{
MigraDoc.DocumentObjectModel.Tables.Table ftable = Obj.AddTable();
ftable.LeftPadding = "0mm";
ftable.RightPadding = "0mm";
ftable.TopPadding = "0mm";
ftable.BottomPadding = "0mm";
//columns 6
MigraDoc.DocumentObjectModel.Tables.Column c = ftable.AddColumn("50mm"); //from airport
c.Format.Alignment = ParagraphAlignment.Left;
c.Format.LeftIndent = "1mm";
c.Format.RightIndent = "1mm";
c = ftable.AddColumn("50mm"); //to airport
c.Format.Alignment = ParagraphAlignment.Left;
c.Format.LeftIndent = "1mm";
c.Format.RightIndent = "1mm";
c = ftable.AddColumn("20mm"); // dep date
c.Format.Alignment = ParagraphAlignment.Left;
c.Format.LeftIndent = "1mm";
c.Format.RightIndent = "1mm";
c = ftable.AddColumn("20mm"); //dep time
c.Format.Alignment = ParagraphAlignment.Left;
c.Format.LeftIndent = "1mm";
c.Format.RightIndent = "1mm";
c = ftable.AddColumn("20mm"); //arr time
c.Format.Alignment = ParagraphAlignment.Left;
c.Format.LeftIndent = "1mm";
c.Format.RightIndent = "1mm";
c = ftable.AddColumn("30mm"); //flight number
c.Format.Alignment = ParagraphAlignment.Left;
c.Format.LeftIndent = "1mm";
c.Format.RightIndent = "1mm";
//First row is a header row, black background
MigraDoc.DocumentObjectModel.Tables.Row r = ftable.AddRow();
r.HeadingFormat = false;
r.Format.Alignment = ParagraphAlignment.Left;
//r.Format.Font.Bold = true;
r.VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;
//r.Height = "6mm";
r.Style = "Heading3";
r.BottomPadding = "0.2mm";
r.TopPadding = "0.2mm";
Color org = new Color(0, 60, 100, 0);
r.Shading.Color = Color.FromCmyk(0, 60, 100, 0);
Paragraph p = r.Cells[0].AddParagraph();
p.AddTab();
p.AddText("Flight Details");
r.Cells[0].MergeRight = 5;
//next row is the column headers
r = ftable.AddRow();
r.HeadingFormat = false;
r.Format.Alignment = ParagraphAlignment.Left;
r.Format.Font.Bold = true;
r.TopPadding = "0.2mm";
r.BottomPadding = "0.2mm";
r.Cells[0].AddParagraph("Departure Airport");
r.Cells[1].AddParagraph("Arrival Airport");
r.Cells[2].AddParagraph("Date");
r.Cells[3].AddParagraph("Depart");
r.Cells[4].AddParagraph("Arrive");
r.Cells[5].AddParagraph("Flight Number");
r = ftable.AddRow();
r.TopPadding = "0.2mm";
r.BottomPadding = "0.2mm";
r.Cells[0].AddParagraph("London Gatwick");
r.Cells[1].AddParagraph("Sharm el Sheikh, Egypt");
r.Cells[2].AddParagraph("24/05/2012");
r.Cells[3].AddParagraph("11:30");
r.Cells[4].AddParagraph("17:10");
r.Cells[5].AddParagraph("EZY5366");
r = ftable.AddRow();
r.TopPadding = "0.2mm";
r.BottomPadding = "0.2mm";
r.Cells[0].AddParagraph("Sharm el Sheikh, Egypt");
r.Cells[1].AddParagraph("London Gatwick");
r.Cells[2].AddParagraph("02/06/2012");
r.Cells[3].AddParagraph("16:30");
r.Cells[4].AddParagraph("22:10");
r.Cells[5].AddParagraph("EZY5367");
//add spacer to before hte flight blurb
r = ftable.AddRow();
r.TopPadding = "0.2mm";
r.BottomPadding = "0.2mm";
//add the flight blurb
r = ftable.AddRow();
r.TopPadding = "0.2mm";
r.BottomPadding = "0.2mm";
r.Format.Alignment = ParagraphAlignment.Justify;
r.Cells[0].MergeRight = 5;
r.Cells[0].AddParagraph("All the flight times are based on local time, flight timings and airling details are subject to change. " +
"We recommend you check-in for your flight two hours before your scheduled departure time. The desks close promptly, so make " +
"sure you've completed check-in at least an hour before take-off.");
//add spacer to before hte flight options header
r = ftable.AddRow();
r.TopPadding = "0.2mm";
r.BottomPadding = "0.2mm";
//add flight options header
r = ftable.AddRow();
r.TopPadding = "0.2mm";
r.BottomPadding = "0.2mm";
r.HeadingFormat = true;
r.Format.Alignment = ParagraphAlignment.Left;
//r.Format.Font.Bold = true;
r.VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center;
//r.Height = "6mm";
r.Style = "Heading4";
r.Shading.Color = Color.FromCmyk(0, 60, 100, 0);
p = r.Cells[0].AddParagraph();
p.AddTab();
p.AddText("Pre-booked Flight Options:");
r.Cells[0].MergeRight = 5;
//add small spacer
r = ftable.AddRow();
r.TopPadding = "0.2mm";
r.BottomPadding = "0.2mm";
r.Height = "2mm";
//add flight options
r = ftable.AddRow();
r.TopPadding = "0.2mm";
r.BottomPadding = "0.2mm";
r.Cells[0].MergeRight = 5;
r.Cells[0].AddParagraph("In-flight meals: None");
r.Cells[0].AddParagraph("Extra leg-room: None");
r.Cells[0].AddParagraph("Speedy boarding: None");
//add small spacer
r = ftable.AddRow();
r.TopPadding = "0.2mm";
r.BottomPadding = "0.2mm";
ftable.SetEdge(0, 1, ftable.Columns.Count, ftable.Rows.Count - 1, MigraDoc.DocumentObjectModel.Tables.Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, "0.1mm", Color.FromCmyk(0, 60, 100, 0));
}
It ends up looking like this - I bordered the text frames so you can see them.
I am open to alternative methods, like just drawing the image absolutely just above the table, if I could a) determine the position of the table and b) draw the image there, but I can't seem to figure that out in Migradoc.
Can you help please?
Thank you.
Lee