Searching an easy method for converting JPG to PDF in C#

Question:I would like to convert from JPG to PDF, I've checked out ImageMagickNET, but it is far too complex for what I am after doing, it needs to be simple. Is there any easy solution on VeryPDF? I do not want to spend too much time to learn a new application.

Answer:According to your needs, VeryPDF provides two quite simply methods for convert image JPG to PDF from C#. Method 1, you can convert JPG to PDF from C# by cloud based application named VeryPDF Image to PDF Converter Cloud API. By this cloud based API, simply run the conversion from C# by copy a URL to C# code. Method 2, you can have a free trial of Image to PDF Converter SDK version. I will state code template here for your reference. When you run the conversion, simply change the input and output file path. Please check more information of those two applications on home page, in the following part, I will show you how to call them from C#.

Method 1, Convert JPG to PDF from C#  by cloud based Image to PDF Converter Cloud API

  • Here is the code template for your reference:
  • using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.Serialization;
    using System.Net;
    using System.IO;
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void button1_Click(object sender, EventArgs e)
            {
                string url = "http://online.verypdf.com/api/apikey=XXXXXXXXXXXXX&app=imageproc&infile=
    http://online.verypdf.com/examples/cloud-api/verypdf.jpg&outfile=out.pdf";
                WebRequest request = HttpWebRequest.Create(url);
                WebResponse response = request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string urlText = reader.ReadToEnd();
                MessageBox.Show(urlText);
            }
        }

  • Please pay more attention to the URL part. You need to change the API code the real code in your email box or else there will be watermark on output. Change the URL of JPG to the real image file and then run it in C#.

Method 2. Convert JPG to PDF by Image to PDF Converter.

  • Please download Image to PDF SDK/COM for Developers. When downloading finishes, there will be a zip file. Please extract it to some folder then you can run the conversion easily.
  • When you need to convert JPG to PDF from C#, please refer to the following code templates:
  • void main()
    {
       char szPDFFile[256];
       char szImageFile[256];
       long id;
       memset(szPDFFile,0,256);
       memset(szImageFile,0,256);

        if(!LoadVeryWDll())
        return ;

        GetModulePath(szPDFFile,"append.pdf");
        id=pVeryOpen(szPDFFile);
        if(id>0)
        {

            pVeryAddInfo(id,"Title","Subject","Author",
            "Keywords""Creator");
            pVerySetFunction(id,Very_Set_ViewerPreferences,4+4096,2,0,0);

            //add image file types
            AddTIFFImage(id);
            AddJPGImage(id);

           AddTextExample2(id);
           CharTable(id);
           pVeryClose(id);
           }
           FreeVeryWDll();
           ShellExecute(NULL,"open",szPDFFile,NULL,NULL,SW_SHOWNORMAL);
      }

Please check more information on homepage. During the using, if you have any question, please contact us as soon as possible.

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!