Hello
I am learning to use MigraDoc (using MigraDocCore).
I want to insert an image in a table and make it to fill the cell completely, but I keep failing on this.
I have read this thread:
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3012, and others, but the solution keeps being elusive...
This is the code I am using.
Code:
open System
open MigraDocCore.DocumentObjectModel
open MigraDocCore.Rendering
module Helper =
open MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes
let initialize () =
if (ImageSource.ImageSourceImpl = null) then
let imageSource = PdfSharpCore.Utils.ImageSharpImageSource<SixLabors.ImageSharp.PixelFormats.Rgba32>();
ImageSource.ImageSourceImpl <- imageSource
let getImageSource (filename: string) =
let b = System.IO.File.Exists(filename)
ImageSource.FromFile(filename)
let build () =
Helper.initialize ()
let doc = Document ()
let section = doc.AddSection ()
let table = section.AddTable()
table.Borders.Color <- Colors.Navy
table.LeftPadding <- 0
table.RightPadding <- 0
table.BottomPadding <- 0
table.TopPadding <- 0
let width = Unit.FromMillimeter 50
table.AddColumn(width) |> ignore
table.AddColumn(width) |> ignore
table.AddColumn(width) |> ignore
let row = table.AddRow ()
row.Cells[0].Shading.Color <- Colors.LightBlue
row.Cells[1].Shading.Color <- Colors.Aqua
row.Cells[2].Shading.Color <- Colors.LightBlue
let para = row.Cells[1].AddParagraph()
para.Style <- "DataCell"
para.Format.Shading.Color <- Colors.Yellow
para.Format.Borders.Distance <- Unit.Zero
para.Format.Borders.Top.Width <- Unit.Zero
para.Format.Borders.Bottom.Width <- Unit.Zero
let imageSource = "logo.png" |> Helper.getImageSource
let image = para.AddImage(imageSource)
image.LockAspectRatio <- true
let filename =
let now = DateTime.Now
let year = now.Year
let month = now.Month
let ticks = now.Ticks
$"{year}-%02i{month}-Invoice_%08i{ticks}.pdf"
let renderer = new PdfDocumentRenderer()
renderer.Document <- doc
renderer.RenderDocument()
renderer.PdfDocument.Save(filename)
()
This is the result:
![Image](https://files.fm/f/b9japcvjw)
Look what happens when zoomming in
![Image](https://files.fm/f/rj6btgdkc)
Please, notice the yellow borders on top and bottom... those are the ones I do not know how to remove.
<Edited>
I cannot see the images in the post, here are the links:
https://files.fm/f/b9japcvjwhttps://files.fm/f/rj6btgdkc</Edited>
Any help will be greatly appreciated.
Regards,
Mauricio