We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert Multiple PNG Files Into Single Tiff File

I am wondering if Aspose can convert multiple PNG files into a single TIFF file. If it can, please provide me with some samples.


Thanks

Hi DJ,


Thanks for your inquiry. I think you can achieve what you need after using the following code snippet:

///
/// Converts a List of Image objects to Multi-Page TIFF format
///
/// System.Drawing.Image List of PNG images
public static void
ConvertMultipleImagesToTiff(List<Image> images)
{
Document
doc =
new Document();
DocumentBuilder
builder =
new DocumentBuilder(doc);

// Loop through
all the images
for (int i = 0; i < images.Count; i++)
{
// Insert one
PNG per page, positioned at top left corner of document
builder.InsertImage(images[i],
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
images[i].Width,
images[i].Height,
WrapType.None);

// To prevent
extra page break at the end of document
if (i
< images.Count - 1)
builder.InsertBreak(BreakType.PageBreak);
}

// Save
Aspose.Words document to TIFF format
doc.Save(@“C:\test\PNGs\test.tiff”);

}


I hope, this will help.

Best Regards,

Hi DJ,


Thanks for your inquiry.

I’ll just improve a bit on Awais’s sample code. You may find that different sized images will have white bands around them or are cut off at the edges of the pages. You can avoid this happening by making the following changes below.

///
/// Converts a List of Image objects to Multi-Page TIFF format
///
/// System.Drawing.Image List of PNG images
public static void ConvertMultipleImagesToTiff(List<Image> images)
{
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Loop through all the images
for (int i = 0; i < images.Count; i++)
{

PageSetup
ps = builder.PageSetup;<o:p></o:p>

ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);

ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);


// Insert one PNG per page, positioned at top left corner of document
builder.InsertImage(images[i],
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);

// To prevent extra page break at the end of document
if (i < images.Count - 1)
builder.InsertBreak(BreakType.SectionBreakNewPage);
}

// Save Aspose.Words document to TIFF format
doc.Save(@"C:\test\PNGs\test.tiff");
}

If we can help with anything else, please feel free to ask.

Thanks.

Hello Agustine,


Thanks for your interest in our products.

I think Aspose.Imaging can fulfil your requirement of converting PNG images into TIFF format. For more information, please visit


However if the above links does not satisfy your requirements, you may consider using Aspose.Pdf for .NET to accomplish this requirement. For that reason, first you need to read the source PNG files and save them into to PDF format and then you can convert the resultant PDF into TIFF format. For more information, please visit the following links. In case it does not satisfy your requirements or you have any further query, please feel free to contact.