PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Fri May 16, 2025 6:16 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Jan 27, 2025 1:53 pm 
Offline

Joined: Mon Jan 27, 2025 1:16 pm
Posts: 1
Hi Team,

I am using Table structure to build my invoice report. I am adding Image to one of the cell at the top of the invoice and it is taking some space the left. How can I fix this ? I have tried padding/indent but nothing is working.

code given below :

static void Main(string[] args)
{
Document document = new();
Section section = document.AddSection();

string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string imageLogoPath = Path.Combine(baseDirectory, "assets\\images\\sample_logo.png");

Console.WriteLine($"Image Path: {imageLogoPath}");

if (File.Exists(imageLogoPath))
{
Table logoTable = section.AddTable();
List<ColumnAttributes> columnAttributes =
[
new()
{
Width = 16
}
];

ConfigureTable(logoTable, columnAttributes, false);

Row row1 = logoTable.AddRow();
Cell cellA1 = row1.Cells[0];
var logoImage = cellA1.AddImage(imageLogoPath);
ConfigureImage(logoImage);
}
else
{
section.AddParagraph("Logo image not found.");
Console.WriteLine("Logo image not found at the specified path.");
}
}

private static void ConfigureImage(MigraDoc.DocumentObjectModel.Shapes.Image logoImage)
{
logoImage.Left = ShapePosition.Center;
logoImage.Resolution = 128;
}

private static void ConfigureTable(Table table, List<ColumnAttributes> columnAttributes, bool withBorders = false)
{
foreach (var col in columnAttributes)
{
Column column = table.AddColumn(Unit.FromCentimeter(col.Width));
column.Format.Font.Bold = col.IsBold ?? column.Format.Font.Bold;
column.Format.Font.Size = col.FontSize ?? column.Format.Font.Size;
column.Format.Alignment = col.Alignment ?? column.Format.Alignment;
}

table.Borders.Width = withBorders ? 1 : 0;
}

Actual Image is coming which has few cms gap from left side of the table boundary, any suggestions will be appreciated.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 30, 2025 8:59 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1044
Location: CCAA
sagar_sagar_sagar wrote:
Actual Image is coming which has few cms gap from left side of the table boundary, any suggestions will be appreciated.
What is "cms"? What do you get? What do you want?

See also:
https://docs.pdfsharp.net/General/Issue-Reporting.html

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 52 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