Skip to content

Commit a5b6e75

Browse files
committed
42254 Resolved the feedback.
1 parent b5a6a47 commit a5b6e75

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

Images/DifferentFormatsImageintoPDF/.NET/DifferentFormatsImageintoPDF/Controllers/HomeController.cs

+20-27
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using Syncfusion.Pdf;
55
using Syncfusion.Pdf.Graphics;
66
using Syncfusion.Drawing;
7+
using SkiaSharp;
8+
using Microsoft.AspNetCore.Mvc.RazorPages;
79

810
namespace DifferentFormatsImageintoPDF.Controllers
911
{
@@ -32,38 +34,29 @@ public IActionResult DifferentFormatsImagetoPDF()
3234
foreach (var file in files)
3335
{
3436
string extension = Path.GetExtension(file);
35-
37+
//Load the image from the disk
38+
FileStream imageStream = new FileStream(file, FileMode.Open, FileAccess.Read);
39+
PdfImage image;
3640
if (extension == ".jpg" || extension == ".png" || extension == ".jpeg")
3741
{
38-
//Add a page to the document
39-
PdfPage page = doc.Pages.Add();
40-
41-
//Create PDF graphics for the page
42-
PdfGraphics graphics = page.Graphics;
43-
44-
//Load the image from the disk
45-
FileStream imageStream = new FileStream(file, FileMode.Open, FileAccess.Read);
46-
PdfBitmap image = new PdfBitmap(imageStream);
47-
48-
//Draw the image
49-
graphics.DrawImage(image, new PointF(0, 0), new SizeF(400, 600));
42+
image = new PdfBitmap(imageStream);
5043
}
51-
52-
else if (extension == ".tiff" || extension == ".tif" || extension == ".bmp" || extension == ".gif")
44+
else
5345
{
54-
//Add a page to the document
55-
PdfPage page = doc.Pages.Add();
56-
57-
//Create PDF graphics for the page
58-
PdfGraphics graphics = page.Graphics;
59-
60-
//Load the TIFF image
61-
FileStream imageStream = new FileStream(file, FileMode.Open, FileAccess.Read);
62-
PdfTiffImage image = new PdfTiffImage(imageStream);
63-
64-
//Draw the image
65-
graphics.DrawImage(image, new PointF(0, 0), new SizeF(400, 600));
46+
image = new PdfTiffImage(imageStream);
6647
}
48+
49+
//Add section
50+
PdfSection section = doc.Sections.Add();
51+
//Set margin
52+
section.PageSettings.Margins.All = 0;
53+
//Set page size as image size.
54+
section.PageSettings.Size = new SizeF(image.Width, image.Height);
55+
//Add page to the section and initialize graphics for the page
56+
PdfPage page = section.Pages.Add();
57+
//Create PDF graphics for the page
58+
PdfGraphics graphics = page.Graphics;
59+
graphics.DrawImage(image, new PointF(0, 0), new SizeF(image.Width, image.Height));
6760
}
6861

6962
//Saving the PDF to the MemoryStream

Images/DifferentFormatsImageintoPDF/.NET/DifferentFormatsImageintoPDF/DifferentFormatsImageintoPDF.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<RootNamespace>Different_Formats_Image_into_PDF</RootNamespace>
88
</PropertyGroup>
99

10+
<ItemGroup>
11+
<PackageReference Include="Syncfusion.Pdf.Imaging.Net.Core" Version="*" />
12+
</ItemGroup>
13+
1014
<ItemGroup>
1115
<Content Update="wwwroot\Data\256.tif">
1216
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

0 commit comments

Comments
 (0)