PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jul 12, 2024 2:53 pm

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Jun 01, 2022 8:31 am 

Joined: Wed Jun 01, 2022 8:13 am
Posts: 1
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.
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)

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
    let renderer = new PdfDocumentRenderer()
    renderer.Document <- doc

This is the result:
Look what happens when zoomming in
Please, notice the yellow borders on top and bottom... those are the ones I do not know how to remove.

I cannot see the images in the post, here are the links:

Any help will be greatly appreciated.

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: Google [Bot] and 44 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