I think I'm close but still I'm having troubles, couldn't figure it out already two days.
I'm taking a multitiff "A", and want to add a border in the top and watermark it with text, only on the first page, the rest should stay as is.
I did some tests and it works with single paged tiffs, or a multitiff is saved as single paged.
Please could someone help me out pointing where I am doing the mistake?, this is like the 20th iteration code:
The function takes the path to the tiff (with extension .TF, that's why I change the extension to .TIF later), and a string with the text to embed on the first page.
Code: Select all
public void EmbedIdentificationToTiffHeader(string pathToTiff, string code)
{
using (GdPictureImaging image = new GdPictureImaging())
{
int imgIdSrc = image.CreateGdPictureImageFromFile(pathToTiff);
int imgIdTgt = image.TiffCreateMultiPageFromGdPictureImage(imgIdSrc);
int pages = image.TiffGetPageCount(imgIdSrc);
for (int pageId = 1; pageId <= pages; pageId++)
{
image.TiffSelectPage(imgIdSrc, pageId);
if (image.GetStat() == GdPictureStatus.OK)
{
//if it is the first page
if (pageId == 1)
{
image.TiffAddToMultiPageFile(imgIdTgt, imgIdSrc);
image.AddBorderTop(imgIdTgt, 50, Color.White);
image.DrawText(imgIdTgt, code, 20, 1, 16, FontStyle.FontStyleRegular, Color.Black, "Arial", false);
image.TiffSaveAsMultiPageFile(imgIdTgt, Path.ChangeExtension(pathToTiff, "TIF"), TiffCompression.TiffCompressionCCITT4);
}
else
{
image.TiffAddToMultiPageFile(imgIdTgt, imgIdSrc);
}
}
else
{
Logger.Write("Error: " + image.GetStat());
break;
}
}
image.ReleaseGdPictureImage(imgIdSrc);
image.ReleaseGdPictureImage(imgIdTgt);
image.Dispose();
}
}