标签:using collect graphics graph memory oat float ice gen
很多扫描版的电子书,留有很大的页边距,大屏的设备看起来没有啥影响,
可是在kindle上看起来就麻烦了,放大操作简直就没法用,最好能把留白去掉。
int pageCount = pdfDocument.Pages.Count; Resolution resolution = new Resolution(300); if (pageCount == 0) { return; } float dpiX = 72; float dpiY = 72; using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero)) { dpiX = graphics.DpiX; dpiY = graphics.DpiY; } int pageWidth = rect.Width; float secPageWidth = (float)(pageWidth * 72 / dpiX); float secPageHeight = (float)(pdfDocument.PageInfo.Height * 72 / dpiY); System.Drawing.Rectangle clipRect = new System.Drawing.Rectangle(rect.X, 0, rect.Width, (int)pdfDocument.PageInfo.Height); JpegDevice jpegDevice = new JpegDevice((int)pdfDocument.PageInfo.Width, (int)pdfDocument.PageInfo.Height, resolution, 100); for (int i = 1; i <= pageCount; i++) { Aspose.Pdf.Generator.Section imageSection = newPdfFileDocument.Sections.Add(); imageSection.PageInfo.PageWidth = secPageWidth; imageSection.PageInfo.PageHeight = secPageHeight; Aspose.Pdf.Generator.MarginInfo marginInfo = new Aspose.Pdf.Generator.MarginInfo(); marginInfo.Bottom = 0; marginInfo.Left = 0; marginInfo.Right = 0; marginInfo.Top = 0; imageSection.PageInfo.Margin = marginInfo; Aspose.Pdf.Generator.Image imagePdfContent = new Aspose.Pdf.Generator.Image(imageSection); imageSection.Paragraphs.Add(imagePdfContent); imagePdfContent.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Jpeg; MemoryStream msSrcImg = new MemoryStream(); jpegDevice.Process(pdfDocument.Pages[i], msSrcImg); System.Drawing.Image image = System.Drawing.Image.FromStream(msSrcImg); System.Drawing.Bitmap bmpImage = new System.Drawing.Bitmap(image); System.Drawing.Bitmap bmpCrop = bmpImage.Clone(clipRect, bmpImage.PixelFormat); MemoryStream msCropImg = new MemoryStream(); bmpCrop.Save(msCropImg, ImageFormat.Jpeg); imagePdfContent.ImageInfo.ImageStream = msCropImg; GC.Collect(); }
利用Aspose.Pdf将扫描的电子书修改为适合在kindle上查看
标签:using collect graphics graph memory oat float ice gen
原文地址:http://www.cnblogs.com/firesword/p/6093066.html