我想从pdf文件,使用Itextsharp和Bitmiracle创建tif图像。试图从PDF创建Tif。越来越差的图像
首先,我想使用iTextsharp获取pdf文件每个页面的字节细节。
string bpp = pd.Get(PdfName.BITSPERCOMPONENT).ToString();
PixelFormat pixelFormat;
switch (bpp)
{
case "1":
pixelFormat = PixelFormat.Format1bppIndexed;
break;
case "8":
pixelFormat = PixelFormat.Format24bppRgb;
break;
default:
throw new Exception(String.Format("Unknown pixel format {0}.", bpp));
}
之后,使用bitmiracle我保存该图像在TIFF格式。但图像不可见。
string filter = PDFStremObj.Get(PdfName.FILTER).ToString();
switch (filter)
{
case "/FlateDecode":
byte[] arr = PdfReader.GetStreamBytes((PRStream)PDFStremObj);
Bitmap bmp = new Bitmap(Int32.Parse(width), Int32.Parse(height), PixelFormat.Format24bppRgb);
BitmapData bmd = bmp.LockBits(new System.Drawing.Rectangle(0, 0, Int32.Parse(width), Int32.Parse(height)), ImageLockMode.WriteOnly,
PixelFormat.Format24bppRgb);
Marshal.Copy(arr, 0, bmd.Scan0, arr.Length);
bmp.UnlockBits(bmd);
bmp.Save(strFileNewName, System.Drawing.Imaging.ImageFormat.Tiff);
bmp.Dispose();
page++;
break;
}
请帮我解决代码中的问题,或者建议我更改。
在此先感谢您的帮助。
为什么人们似乎认为PDF是一种图像格式?这显然不是。 – Nyerguds 2018-01-08 15:29:20