![]() ![]() 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. Other applications that can open BMP files include Adobe Photoshop, Microsoft Photos, Apple Preview, Apple Photos, and ColorStrokes.Images are an effective way to visualize data and make documents look more informative. Should you need to convert the BMP into a vector-based image, then consider using CorelDRAW. In addition to opening BMP files, many applications can be used to create them, such as Adobe Illustrator. Despite the association with Microsoft, a device-independent BMP, or DIB, can open on almost any device, operating system, or application. BMP opens readily in the Microsoft Paint application and is often associated with Microsoft operating systems. How to open a BMP file?īMP can be device-dependent or independent. However, due to the lack of compression, BMP files are usually large. BMP is mostly used for digital publishing of photographs. BMP utilizes a dot matrix data structure called raster graphics, which establishes the color depth of the image. Bitmap (BMP) is a pixel-based file format that stores two-dimensional images, generally without any compression. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |