I am stuck with an issue where I need to take out the Base64 content of multi page tiff image file. This image file is uploaded on a third part system from where I am able to access it. The image here is having 2 pages and I am accessing it page by page and storing the byte data in two separate indexes of byte[] array. Now when I am converting the two pages individually to respective base 64 content then I am getting it right. But I am not getting how to merge these two base 64 content of two pages in order to get single base 64 content of both the pages.
I need to get base 64 string for both the pages. Here is the code sample:
// Check if the document type is multi page tiff document
if (workPacket.Folder[documentIndex].DocumentType.Equals(Resources.DocumentTypeMultiPg))
{
// Convert the document object to Multipage diff object
MultiPageTiffDocument tiffDoc = (MultiPageTiffDocument)workPacket.Folder[documentIndex].Document;
int pageCount = tiffDoc.PageCount;
Helper.LogMessage(string.Format(Helper.UkCulture, Resources.PageCountMsg + pageCount), Helper.BpiMessageLevel4, tasknode);
bool allOk = false;
List<byte[]> test = new List<byte[]>();
for (int page = 1; page <= pageCount; page++)
{
if (tiffDoc.CopyImageToFile(page, tempCopyFileName, true))
{
allOk = true;
test.Add(File.ReadAllBytes(tempCopyFileName));
Helper.LogMessage(string.Format("Data copied for page {0} is {1}", page, File.ReadAllBytes(tempCopyFileName)), Helper.BpiMessageLevel4, tasknode);
}
}
// Copy the document data to temporary file
if (allOk)
{
// Read the data from File created.
int lngth = 0;
for (int j = 0; j < test.Count; j++)
{
lngth = lngth + test[j].Length;
Helper.LogMessage(string.Format("Length of {0} element is {1}",j, test[j].Length), Helper.BpiMessageLevel4, tasknode);
}
byteData = new byte[lngth];
int Consolidatelength = 0;
for (int j = 0; j < test.Count; j++)
{
if (j == 0)
{
test[j].CopyTo(byteData, 0);
}
else
{
Consolidatelength = Consolidatelength + test[j - 1].Length;
test[j].CopyTo(byteData, Consolidatelength);
}
}
}
else
{
Helper.LogMessage(string.Format(Helper.UkCulture, Resources.CopyFailedMsg, tempCopyFileName), Helper.BpiMessageLevel4, tasknode);
}
}
// Add the combined base 64 in separate collection
binaryCollection.Add(Convert.ToBase64String(byteData));