SoFunction
Updated on 2025-03-07

C# method to convert jpg to pdf

This article describes the method of converting jpg to pdf in C#. Share it for your reference. The specific implementation method is as follows:

C# generates a PDF file with a file, which is an open source library file used to generate PDF documents in C#. Let us introduce to you the use of itextsharp to generate library files.

introduce

The required class library for PDF generation is an open source library file used to generate PDF documents in C#. Many C# enthusiasts use it to create PDF document generators.

The specific code is as follows:

Copy the codeThe code is as follows:
void ConvertJPG2PDF(string jpgfile, string pdf)
{
 var document = new Document(.A4, 25, 25, 25, 25);
 using (var stream = new FileStream(pdf, , , ))
 {
  (document, stream);
  ();
  using (var imageStream = new FileStream(jpgfile, , , ))
  {
   var image = (imageStream);
   if ( > . - 25)
   {
    (. - 25, . - 25);
   }
   else if ( > . - 25)
   {
    (. - 25, . - 25);
   }
   = .ALIGN_MIDDLE;
   (image);
  }
 
  ();
 }
}

iTextSharp is indeed awesome, it can be done with a few simple lines of code.

I hope this article will be helpful to everyone's C# programming.