PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Top and Botton space in Table.Cell
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4345
Page 1 of 1

Author:  mmagni [ Wed Jun 01, 2022 8:31 am ]
Post subject:  Top and Botton space in Table.Cell

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
Look what happens when zoomming in
Image
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/b9japcvjw
https://files.fm/f/rj6btgdkc
</Edited>

Any help will be greatly appreciated.
Regards,
Mauricio

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/