@@ -41,13 +41,8 @@ public byte[] ReadByteImage(string source, ProviderImageInfo info)
41
41
{
42
42
using ( PdfPage pdfPage = pdfDocument . Pages [ info . Index ] )
43
43
{
44
- int dpiX = 300 ;
45
- int dpiY = 300 ;
46
-
47
- int pageWidth = ( int ) ( dpiX * pdfPage . Size . Width / 72 ) ;
48
- int pageHeight = ( int ) ( dpiY * pdfPage . Size . Height / 72 ) ;
49
-
50
- using ( Bitmap bitmap = new Bitmap ( pageWidth , pageHeight , PixelFormat . Format24bppRgb ) )
44
+ Size size = CalculateSize ( pdfPage . Width , pdfPage . Height ) ;
45
+ using ( Bitmap bitmap = new Bitmap ( size . Width , size . Height , PixelFormat . Format24bppRgb ) )
51
46
{
52
47
pdfPage . Render ( bitmap ) ;
53
48
return bitmap . ImageToBytes ( ImageFormat . Jpeg ) ;
@@ -61,6 +56,25 @@ public byte[] ReadByteImage(string source, ProviderImageInfo info)
61
56
}
62
57
}
63
58
59
+ private Size CalculateSize ( double width , double height )
60
+ {
61
+ //The width & height are returned in point (1/72 inch)
62
+ //but PDFs created by CR will have the wrong page size. Which would mean that opening this PDF would mean the resolution would balloon up.
63
+ //To prevent from the above mentioned ballooning, this will be the MAX resolution
64
+ int maxWidth = 1920 ; //8.5in at 225dpi
65
+ int maxHeight = 2540 ; //11in at 225dpi
66
+
67
+ //Calculate the width based on the max height
68
+ int targeWidth = ( int ) ( ( width * maxHeight ) / height ) ;
69
+ //Calculate the height based on the max width
70
+ int targeHeight = ( int ) ( ( height * maxWidth ) / width ) ;
71
+
72
+ //if the page is a landscape page (width > height), use the max height, if not we use the max width
73
+ Size outSize = width > height ? new Size ( targeWidth , maxHeight ) : new Size ( maxWidth , targeHeight ) ;
74
+
75
+ return outSize ;
76
+ }
77
+
64
78
public ComicInfo ReadInfo ( string source )
65
79
{
66
80
return null ;
0 commit comments