Error

# Convert image files (jpeg, png) etc to pdf document.

#1 Posted : Monday, August 14, 2017 12:49:48 PM(UTC)

Groups: Registered
Posts: 3

Hello,

I have a requirement of converting the image files like jpg, jpeg, png bmp etc.. to a single pdf file. Will i be able to use Lead tools for same? If yes can you please guide me to some examples?

Thanks!

#2 Posted : Tuesday, August 15, 2017 3:02:01 PM(UTC)

Posts: 70

Was thanked: 4 time(s) in 4 post(s)

Hello,

Yes, using LEADTOOLS you can convert from the formats that you mentioned to PDF. A full list of the file formats that LEADTOOLS supports can be found here: https://www.leadtools.com/sdk/formats

The evaluation will unlock all functionality of the SDK for sixty days. Included in the download are sample projects that you can use as a reference.
Specifically, I would recommend that you look at the Main Demo, which can be found in the following installation directory:

Converting from one file format to another can be done with as little as three lines of code. For example, this code snippet will allow you to convert an input file to PDF in C#
Code:

var codecs = new RasterCodecs();
codecs.Save(image, @"C:\path\to\outPutFile.pdf", RasterImageFormat.RasPdf, 0);


Thanks,
Duncan Quirk
Developer Support Engineer

#3 Posted : Tuesday, August 15, 2017 3:28:39 PM(UTC)

Groups: Registered
Posts: 3

Hello,

I am using this code and i get Error as "CMP Codec is needed to use this feature"

RasterCodecs codecs = new RasterCodecs();
var stopWatch = new Stopwatch();
stopWatch.Start();
stopWatch.Stop();
MessageBox.Show("Successfully Merged,TimeTaken :" + stopWatch.Elapsed.Milliseconds.ToString() + " seconds");

I have referenced these 3 dlls is there any other dll that i might need to reference?

Also Will i be able to load multiple images at one time, lets say an array of images and then convert same to pdf?

#4 Posted : Tuesday, August 15, 2017 3:43:25 PM(UTC)

Posts: 70

Was thanked: 4 time(s) in 4 post(s)

Hello,

The error you are getting indicates that you are missing one or more codecs filter. Information about what codecs filters are needed for what file format can be referenced in our documentation here: https://www.leadtools.co...n.html#fileformatsupport

For instance, if you are writing to RasPdf, you will need the following DLLs referenced:

You can also set the build path for your project to the LEADTOOLS bin directory you are referencing the DLLs from. This will allow the codecs to automatically pull in what codecs filters are needed without having to reference each one. I would suggest that you try this and see if you are able to convert the file.
Duncan Quirk
Developer Support Engineer

#5 Posted : Tuesday, August 15, 2017 4:00:02 PM(UTC)

Groups: Registered
Posts: 3

Hello,

Thanks for your prompt reply. I added the references you mentioned and still i get the same issue. ""CMP Codec is needed to use this feature"

I am using all this references:

Error seems on the line RasterImage image = codecs.Load(@"C:\Viral\.NET Projects\Code\MergePDFDocument\MergePDFDocument\MergePDFDocument\bin\Debug\PDF_Documents\T05_JB70722.jpg");

Thanks!

#6 Posted : Wednesday, August 16, 2017 12:44:16 PM(UTC)

Posts: 70

Was thanked: 4 time(s) in 4 post(s)

Hello,

Have you tried setting the build path for your project to the LEADTOOLS bin directory that you are referencing the dlls from? Setting this path will allow the codecs to automatically pull in the filters it needs. If after do this you project is able to run without issue, then that would indicate that there is an additional DLL that needs to be referenced.

Also, make sure that you are setting your license in your application. This can be done in C# as follows:

Thanks,
Duncan Quirk
Developer Support Engineer

#7 Posted : Monday, February 18, 2019 7:28:32 AM(UTC)

Groups: Registered
Posts: 4

var codecs = new RasterCodecs();
codecs.Save(image, @"C:\path\to\outPutFile.pdf", RasterImageFormat.RasPdf, 0);

After using the above code if i convert the 250kb image file the converted pdf file is of 25mb. Is there any way i can compress or reduce the size.

#8 Posted : Monday, February 18, 2019 8:59:41 AM(UTC)

Posts: 201

Was thanked: 9 time(s) in 9 post(s)

When you choose RasterImageFormat.RasPdf, that is uncompressed raster PDF. Depending on the input file, I would suggest using RasJpeg411 (for color images) or RasPdfG4 (for 1 BPP):

Developer Support Manager

#9 Posted : Friday, February 22, 2019 5:11:40 PM(UTC)

Posts: 26

Was thanked: 1 time(s) in 1 post(s)

If you want to take advantage of more advanced features of LEADTOOLS, such as OCR and image processing, while converting from multiple formats to PDF, check out this blog post:

Convert and Merge Files into a PDF

The post includes example code that uses the LEADTOOLS Document Converter to merge multiple files into one text-searchable PDF file. It links to other posts that perform some more advanced image processing to clean up photos of documents.
Gabriel Smith