PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Dec 09, 2024 11:12 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 
Offline

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


Top
 Profile  
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: No registered users and 36 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