PDF and Music – 2

Not all music is in PDF format. More music is in image formats such as JPG, PNG, or TIFF. For example, the following resource Pinterest provides music sheets for marches, waltzes, rags, theater music, cornet solos, trombone features, and much more in the PNG format mostly. And if you want to convert music sheets in the image format, you can use PDF Mosaic SDK .NET for your purposes. PDF Mosaic .NET Library is able to convert images in various formats (BMP, jpeg, png, tiff, gif) to PDF documents. You can create an image from a file in GIF/TIFF/PNG/BMP/JPEG formats, or a buffer of image bytes, or a System.Drawing.Image object. To create PDF files from images, use PDFImage object and the following methods of canvas: public void DrawImage(PDFMosaic.PDFImage image,System.Single left,System.Single top), public void DrawImage(PDFMosaic.PDFImage image, System.Single left, System.Single top, System.Singlewidth, System.Single height).

Below is the code for creating PDF from images:

using PDFMosaic;
using System.Drawing;
 
namespace DrawImage
{
    class DrawImage
    {
        static void Main()
        {
            PDFDocument document = new PDFDocument();
            document.Pages.Add(new PDFPage(PDFPaperFormat.A4));
            PDFCanvas canvas = document.Pages[0].Canvas;
            PDFImage image = new PDFImage("musicsheet.jpg");            
            canvas.DrawImage(image, 0, 0, image.Width, image.Height);
            document.Save("music.pdf", true);
        }
    }
}

Please see the sample PDF music compilations here: music.pdf

The PDF file was created by PDF Mosaic .NET Library. Original image here.
As you can see, the creation of PDF is an easy process with help of PDF SDK for .NET. Try it!

Read the first part of the article.