GdPicture.NET是一款综合的图片文档处理控件,不仅可以对图片进行各种操作处理、清洁、打印和浏览,还可以结合多种添加模块进行更广泛的应用,如OCR、OMR、PDF、TIFF、条码生成与识别、以及扫描等,该产品包含了
GdPicture.NET Document Imaging SDK、
GdPicture.NET Image SDK、
GdPicture.NET TWAIN SDK、
GdPicture.NET Document Viewer SDK几个基础模块,基于这些基础模块开发人员还可以根据功能需求进行额外的模块添加,这篇文章主要介绍怎么利用Managed PDF添加模块来实现PDF文件转换为多页TIFF文件的功能,具体可以参考下面的.NET代码:
GdPictureImaging oGdPictureImaging = new GdPictureImaging();
GdPicturePDF oGdPicturePDF = new GdPicturePDF();
int multiTiffID;
//Load pdf file
GdPictureStatus status = oGdPicturePDF.LoadFromFile("input.pdf", false);
//if pdf loading was successful
if (status == GdPictureStatus.OK)
{
//loop through pages
for (int i = 1; i <= oGdPicturePDF.GetPageCount(); i++)
{
//select page
oGdPicturePDF.SelectPage(i);
//render selected page to GdPictureImage identifier
int rasterizedPageID = oGdPicturePDF.RenderPageToGdPictureImageEx(200.0f, true);
//if it is the first page
if (i == 1)
{
multiTiffID = rasterizedPageID;
//make the image a new multipage tiff image
status = oGdPictureImaging.TiffSaveAsMultiPageFile(multiTiffID, "output.tif", TiffCompression.TiffCompressionAUTO);
//release old image identifier
oGdPictureImaging.ReleaseGdPictureImage(rasterizedPageID);
//check for saving errors
if (status != GdPictureStatus.OK)
{
MessageBox.Show("Error: " + status.ToString());
break;
}
}
else
{
//add new image to multipage tif image
status = oGdPictureImaging.TiffAddToMultiPageFile(multiTiffID, rasterizedPageID);
//release last image identifier
oGdPictureImaging.ReleaseGdPictureImage(rasterizedPageID);
//check for page adding errors
if (status != GdPictureStatus.OK)
{
MessageBox.Show("Error: " + status.ToString());
break;
}
}
}
//clost multipage tif file
oGdPictureImaging.TiffCloseMultiPageFile(multiTiffID);
//release multipage tif image
oGdPictureImaging.ReleaseGdPictureImage(multiTiffID);
//display success or failure
if (status == GdPictureStatus.OK)
{
MessageBox.Show("Success !");
}
else
{
MessageBox.Show("Error: " + status.ToString());
}
//close and release pdf document
oGdPicturePDF.CloseDocument();
}
else
{
MessageBox.Show("Can\'t open file" + status.ToString());
}