怎样去除PDF中的空白页 - GdPicture.NET使用教程
来源:互联网 发布:手机网络捕鱼修改器 编辑:程序博客网 时间:2024/04/24 13:45
在PDF文件进行扫描的时候,有时PDF中会有一些空白页存在,扫描出来也是空白的,所以在扫描前往往需要加载GdPicture.NET,先一页一页的进行检查,这样往往会很麻烦,实际上在使用GdPicture.NET的时候,只需要几段简单的代码,就可以除去PDF中的空白页,这里提供一段示例代码,适用于GdPicture.NET 8.5.3或者更高的版本。
》》》GdPicture.NET最新试用版下载地址
示例代码如下:
const int RASTER_DPI = 200; GdPictureImaging oGdPictureImaging = new GdPictureImaging(); GdPicturePDF oGdPicturePDF = new GdPicturePDF(); oGdPicturePDF.LoadFromFile(@"c:\input.pdf", false); oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitPoint); oGdPicturePDF.EnableCompression(true); for (int i = 1; i <= oGdPicturePDF.GetPageCount(); i++) { oGdPicturePDF.SelectPage(i); int rasterImageID = oGdPicturePDF.RenderPageToGdPictureImageEx(RASTER_DPI, false); int bitDepth = oGdPictureImaging.GetBitDepth(rasterImageID); if (oGdPictureImaging.IsBlank(rasterImageID)) { //page is blank, we remove it oGdPicturePDF.DeletePage(i--); } else { //if the page is based on a single color image, we convert it to 1bpp. Warning: not 100% safe if (bitDepth > 8 && !oGdPicturePDF.PageHasText() && !oGdPicturePDF.PageHasShape() && oGdPicturePDF.GetPageImageCount() == 1) { if (oGdPictureImaging.ConvertTo1BppAT(rasterImageID) == GdPictureStatus.OK) { //we remove the page then create a new one to remove unused resources on pack float pageWidth = oGdPicturePDF.GetPageWidth(); float pageHeight = oGdPicturePDF.GetPageHeight(); oGdPicturePDF.DeletePage(i); oGdPicturePDF.InsertPage(pageWidth, pageHeight, i); string pdfImageResName = oGdPicturePDF.AddImageFromGdPictureImage(rasterImageID, false, false); if (pdfImageResName != "") { oGdPicturePDF.DrawImage(pdfImageResName, 0, 0, pageWidth, pageHeight); } else { throw new Exception("Error embedding bitmap in PDF"); } } else { throw new Exception("Error during bitmap thresholding"); } } } oGdPictureImaging.ReleaseGdPictureImage(rasterImageID); } oGdPicturePDF.SaveToFile(@"c:\newpdf.pdf", true); //we have to pack the doc to remove unused enbedded bitmaps oGdPicturePDF.CloseDocument();
- 怎样去除PDF中的空白页 - GdPicture.NET使用教程连载
- 怎样去除PDF中的空白页 - GdPicture.NET使用教程
- GdPicture.NET使用教程:读取PDF文档中的1D和2D码
- GdPicture.NET使用教程:在PDF文件中添加水印
- 在PDF中添加文本 - GdPicture.NET使用教程连载
- GdPicture.NET使用教程汇总
- GdPicture.NET使用教程:直接获取Tiff中的OCR
- 如何为新的PDF页添加图片 - GdPicture.NET使用教程连载
- 为PDF和TIFF添加XMP注释 - GdPicture.NET使用教程连载
- 如何为新的PDF页添加图片 - GdPicture.NET使用教程
- 在已有PDF中添加新页并画图 - GdPicture.NET使用教程连载
- GdPicture.NET使用教程:从多页PDF Stream创建多页Tiff Stream
- GdPicture.NET使用教程:旋转页面并保存覆盖原始的PDF
- GdPicture.NET使用教程:将多页TIFF文件转换为JBIG2
- GdPicture.NET使用教程:如何合并多页TIFF文件
- GdPicture.NET使用教程:创建多页TIFF文件
- 将PDF转换成多页TIFF格式 - GdPicture.NET文件转换教程连载
- GdPicture.NET文件转换教程连载:将TIFF转换成PDF OCR
- 位图缩放的快速方法
- map 自定义类型作为键值
- Preference 的xml使用 小结
- SQL事务的用法
- webLogic后台运行(Unix/lunix)
- 怎样去除PDF中的空白页 - GdPicture.NET使用教程
- asp.net 负载均衡下session存储的解决方法
- 关于DW建模中维度建模问题一:自己循环
- Windbg和VirtualBox通过虚拟串口调试Win 8
- 获取当前模型的文件路径
- 简悦创始人云风谈程序员的职业素养
- STS set tomcat server deploy project path
- 大端格式、小端格式
- 科学的工作方法—PDCA循环工作法