Here are some more examples of working with iTextPdf API. It is simple to use, can be installed easily and conversion is performed very quickly. ITextPdf API lets you convert BMP, JPEG, PNG, GIF, and many more image file formats to PDF file format. The image is automatically scaled to fit the width of the PDF page while maintaining its aspect ratio. In summary, this code reads an image file, creates a PDF document, adds the image to the document, and saves the result as “ImageToPdf.pdf”. This ensures that all the changes made to the PDF are properly saved and the file is ready for use. Closing the PDF Document: After adding all the necessary content to the PDF document, it is closed.This step inserts the image into the PDF document. Adding Image to the Document: The Image object is added to the Document.The SetAutoScaleHeight(true) method is called to automatically scale the height of the image to maintain its aspect ratio based on the width set in the previous step. This will make the image fit the width of the page while maintaining its aspect ratio. The SetWidth method is used to set the width of the image to match the width of the PDF document’s default page size, with a 50-point margin on each side. This Image object represents the image that will be added to the PDF document. Image Creation and Configuration: An Image object is created using the previously created ImageData object.It’s constructed using the PdfDocument object created in the previous step. Document Creation: A Document object is created, representing the content of the PDF document.In this case, the file is named “ImageToPdf.pdf”. It takes a PdfWriter object as an argument, which specifies the file where the PDF will be saved. PDF Document Creation: Here, a new PDF document is created using the PdfDocument class constructor.This method is used to read the image data and create an ImageData object from it, which is later used to create an Image object. The ORIG variable presumably contains the path to the image file. ImageData Creation: The ImageData object is created by calling the Create method of the ImageDataFactory class.Let’s have a detailed look at how iTextPdf API converts an image to PDF using C#. PdfDocument.Close() Explanation of Code for Converting Image to PDF in C# Image.SetWidth(pdfDocument.GetDefaultPageSize().GetWidth() - 50) PdfDocument pdfDocument = new PdfDocument(new PdfWriter("ImageToPdf.pdf")) ĭocument document = new Document(pdfDocument) ImageData imageData = ImageDataFactory.Create(ORIG) If you haven’t installed iTextPdf yet, you can check our guide, Open-Source API for PDF Documents, to know more about how to install the API for working with it. How to Convert Images to PDF in C#?īefore we jump into writing the code for converting images to PDF in C#, make sure that you have installed iTextPdf on your system. Among its wide range of features, iTextPdf enables us to convert images to PDF with just a few lines of code as we will show in this article. It has a wide range of features including creating, manipulating, and extracting content from PDF documents. NET is a free open-source API that provides the capability of working with PDF files from within your. It assumes that you have a basic knowledge of working with. In this article, we’ll show how to convert images to PDF using iTextPDF for. NET application developer, you would like to add the functionality of converting different types of images such as PNG, JPG, BMP, and GIF to PDF file format using C# in your application. PDF files are one of the widely used document file formats for sharing information and content. The format is sometimes known as Device-Independent Bitmap (DIB), since, when loaded into memory using Windows software, the image is held as a DIB structure.Images are an effective way to visualize data and make documents look more informative. It is a simple raster graphics image file format designed to store bitmap digital images independently of a display device, originally and primarily on Microsoft Windows and OS/2 operating systems. This attenuation increases with the compression coefficient.ĭeveloped by: Joint Photographic Experts Group, IBM, Mitsubishi Electric, AT&T, Canon Inc.Īsociated Programs: MS Paint, Adobe Photoshop, Apple Preview, Corel Paint Shop Pro, …īMP is also known as Bitmap image file. Image quality is degraded after decompression. However, the image after decompression will be different from the original image. JPG/JPEG is one of the effective image compression methods, with a compression ratio of several tens of times. JPG (or JPEG) is a popular digital image format which contains compressed image data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |