Merge PNG to PDF via C#
Sample code for concatenation PNG documents into single formats PDF on .NET Framework, .NET Core, and PHP, VBScript, Delphi, C++ via COM Interop.
Merge PNG to PDF Using C#
With Aspose.PDF for .NET library you can merge PNG to PDF programmatically. PDF software from Aspose is ideal for individuals, and small or large businesses. Since it is able to process a large amount of information, perform the concatenation quickly and efficiently and protect your data. A peculiar feature from Aspose.PDF is an API for merging PNG to PDF. The trait of this approach is that you only need to open the NuGet package manager, search for ‘Aspose.PDF for .NET’, and install it without any special complex settings. (Use the command from the Package Manager Console for installing). To verify the benefits of the library, try using the concatenation PNG to PDF code snippet.
Package Manager Console Command
PM> Install-Package Aspose.PDF
How to merge PNG to PDF via C#
.NET developers can easily load & merge PNG files to PDF in just a few lines of code.
- Initialize a new Document, and run a loop for merging files
- In loop: add a new page to PDF document
- In loop: add PNG file to new page
- After the loop save the result
System Requirements
Aspose.PDF for .NETis supported on all major operating systems. Just make sure that you have the following prerequisites.
- Microsoft® Windows™ or a compatible OS with .NET Framework, .NET Core, and PHP, VBScript, Delphi, C++ via COM Interop.
- Development environment like Microsoft Visual Studio.
- Aspose.PDF for .NET DLL referenced in your project.
This sample code shows PNG to PDF C# concatenation
// create empty pdf document
doc = new Aspose.Pdf.Document();
// make list of file streams with documents to merge
streams = new List<Stream>(){ File.Open("1.pmg", FileMode.Open), File.Open("2.pmg", FileMode.Open) };
// add new page to pdf
// add image to new pdf page
foreach (var fs in streams)
{
page = doc.Pages.Add();
page.AddImage(fs, new Aspose.Pdf.Rectangle(0, 0, 700, 1000));
}
// save result pdf to file
doc.Save("Merger_png_pdf.pdf", Aspose.Pdf.SaveFormat.Pdf);
Combine PNG to PDF in C#
Convert or combine multiple PNG into single PDF file in C# is not straightforward task without using 3rd party library. This page shows how to merge multiple PNG files into a single PDF document using Aspose.PDF for .NET. The example is written in C# but the API can be used in othe .NET programming languages as well such as VB.NET. PDF files are merged such that the first one is joined at the end of the other document.
Package Manager Console Command
PM > Install-Package Aspose.PDF