Convert JPG to PDF in C#
The GdPictureDocumentConverter
class is a quick and easy one-step operation for converting
JPG and JPEG images into PDF or PDF/A. You can also choose the PDF conformance level you require.
Here’s the code for converting files to PDF:
// We assume GdPicture has been correctly installed and unlocked. using (GdPictureDocumentConverter oConverter = new GdPictureDocumentConverter()) { // Select your source image and its image format (TIFF, JPG, PNG, SVG, and 50+ more). GdPictureStatus status = oConverter.LoadFromFile("input.jpg", GdPicture14.DocumentFormat.DocumentFormatJPEG); if (status == GdPictureStatus.OK) { MessageBox.Show("The file has been loaded successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information); // Select the conformance of the resulting PDF document. status = oConverter.SaveAsPDF("output.pdf", PdfConformance.PDF); if (status == GdPictureStatus.OK) { MessageBox.Show("The file has been saved successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
'We assume GdPicture has been correctly installed and unlocked. Using oConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter() 'Select your source image and its image format (TIFF, JPG, PNG, SVG, and 50+ more). Dim status As GdPictureStatus = oConverter.LoadFromFile("input.jpg", GdPicture14.DocumentFormat.DocumentFormatJPEG) If status = GdPictureStatus.OK Then MessageBox.Show("The file has been loaded successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information) 'Select the conformance of the resulting PDF document. status = oConverter.SaveAsPDF("output.pdf", PdfConformance.PDF) If status = GdPictureStatus.OK Then MessageBox.Show("The file has been saved successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information) Else MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Else MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Using