I want to export the database to pdf in the table for each user including their images. the problem is that it shows specific images with height and width. for example, a pic with 359x214 is shown perfectly, But one with 264x364 can't be shown. I even resized the second one to be exactly the same size as the first one but still doesn't work! They both are JPEG-type pictures. I even increased the height of the row in which the picture is to be shown but still failed. I use DinkToPdf to convert HTML to pdf
public IActionResult CreatePdf()
{
var globalSettings = new GlobalSettings
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Margins = new MarginSettings { Top = 10 },
DocumentTitle = "Users_Report"
};
var objectSettings = new ObjectSettings
{
PagesCount = true,
HtmlContent = GetHTMLString(),
WebSettings = { DefaultEncoding = "utf-8",UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "Style.css"), LoadImages = true },
HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "User" }
};
var pdf = new HtmlToPdfDocument()
{
GlobalSettings = globalSettings,
Objects = { objectSettings }
};
var file = _converter.Convert(pdf);
return File(file, "application/pdf", "Users.pdf");
}
public string GetHTMLString()
{
var users = _dbContext.Users.ToList();
var wwwRootPath = _hostEnvironment.WebRootPath;
var sb = new StringBuilder();
foreach (var user in users)
{
var picAddress = Path.Combine(wwwRootPath + "/image/", user.ImageName);
sb.Append(@"
<html dir='rtl' lang='fa-IR'>
<head>
</head>
<body dir='rtl'>");
sb.AppendFormat(@"<table align ='center'>
<tbody>
<tr>
<td></td>
<td><img src={0} asp-append-version='true' width='110px' height='130px' /></td>
</tr>
<tr>
<td>{1}</td>
<td>{2}</td>
</tr>
<tr>
<td>{3}</td>
<td>{4}</td>
</tr>
<tr>
<td>{5}</td>
<td>{6}</td>
</tr>
<tr>
<td>{7}</td>
<td>{8}</td>
</tr>", picAddress, user.FullName, user.FatherName, user.IdCardNumber,
user.DateOfBirth, user.MaritalStatus, user.MilitaryServiceStatus, user.CallNumber, user.Address);
sb.Append(@"
</table>
</body>
</html>");
}
return sb.ToString();
}
public IActionResult Complete()
{
return View();
}
Here is the Style.css file
table {
width: 100%;
margin:5px;
}
table, th, td {
border: 1px solid gray;
padding: 15px;
font-size: 15px;
text-align: center;
}
th, td {
width:50%;
}