Hi
I'm trying to implement PDF View functionality of Foxit PDF SDK DLL within WPF application
Here some parts of code
#region Code starts here
bool IsInit = false;
private void InitBitmap(string file)
{
if (!IsInit)
{
FPDFView.FPDF_InitLibrary(System.Diagnostics.Proce ss.GetCurrentProcess().Handle);
FPDFView.FPDF_UnlockDLL("SDKRDTEMP", "7E92543CBE6996B4F284AE93F4F9FF964280E536");
IsInit = true;
}
var pdfDoc = FPDFView.FPDF_LoadDocument(file, String.Empty);
if (pdfDoc == null)
return;
var pdfPage = FPDFView.FPDF_LoadPage(pdfDoc, 0);
if (pdfPage == null)
return;
Double pdfWidth = FPDFView.FPDF_GetPageWidth(pdfPage);
Double pdfHeight = FPDFView.FPDF_GetPageHeight(pdfPage);
int sizeX = (int)pdfWidth;
int sizeY = (int)pdfHeight;
Bitmap bitmap = null;
WindowInteropHelper wih = new WindowInteropHelper(this);
using (var gr = Graphics.FromHwnd(wih.Handle))
{
var hdc = gr.GetHdc();
sizeX = (int)pdfWidth / 72 * MyWinApi.GetDeviceCaps(hdc, MyWinApi.DeviceCap.LOGPIXELSX);
sizeY = (int)pdfHeight / 72 * MyWinApi.GetDeviceCaps(hdc, MyWinApi.DeviceCap.LOGPIXELSY);
gr.ReleaseHdc(hdc);
}
bitmap = new Bitmap(sizeX, sizeY);
using (var gr = Graphics.FromImage(bitmap))
{
var hdc = gr.GetHdc();
FPDFView.FPDF_RenderPage(hdc, pdfPage, 0, 0, sizeX, sizeY, 0, 0 | 1 | 2);
gr.ReleaseHdc(hdc);
}
var bmpSource = System.Windows.Interop.Imaging.CreateBitmapSourceF romHBitmap(
bitmap.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight(sizeX, sizeY)
//BitmapSizeOptions.FromEmptyOptions()
);
img.BeginInit();
img.Source = bmpSource;
img.EndInit();
}
#endregion Code ends here
And what I have as output is distorted bitmap. So my question is WHY?
Foxit Reader (original).jpgFoxit SDK DLL (result).jpg
I'm trying to implement PDF View functionality of Foxit PDF SDK DLL within WPF application
Here some parts of code
#region Code starts here
bool IsInit = false;
private void InitBitmap(string file)
{
if (!IsInit)
{
FPDFView.FPDF_InitLibrary(System.Diagnostics.Proce ss.GetCurrentProcess().Handle);
FPDFView.FPDF_UnlockDLL("SDKRDTEMP", "7E92543CBE6996B4F284AE93F4F9FF964280E536");
IsInit = true;
}
var pdfDoc = FPDFView.FPDF_LoadDocument(file, String.Empty);
if (pdfDoc == null)
return;
var pdfPage = FPDFView.FPDF_LoadPage(pdfDoc, 0);
if (pdfPage == null)
return;
Double pdfWidth = FPDFView.FPDF_GetPageWidth(pdfPage);
Double pdfHeight = FPDFView.FPDF_GetPageHeight(pdfPage);
int sizeX = (int)pdfWidth;
int sizeY = (int)pdfHeight;
Bitmap bitmap = null;
WindowInteropHelper wih = new WindowInteropHelper(this);
using (var gr = Graphics.FromHwnd(wih.Handle))
{
var hdc = gr.GetHdc();
sizeX = (int)pdfWidth / 72 * MyWinApi.GetDeviceCaps(hdc, MyWinApi.DeviceCap.LOGPIXELSX);
sizeY = (int)pdfHeight / 72 * MyWinApi.GetDeviceCaps(hdc, MyWinApi.DeviceCap.LOGPIXELSY);
gr.ReleaseHdc(hdc);
}
bitmap = new Bitmap(sizeX, sizeY);
using (var gr = Graphics.FromImage(bitmap))
{
var hdc = gr.GetHdc();
FPDFView.FPDF_RenderPage(hdc, pdfPage, 0, 0, sizeX, sizeY, 0, 0 | 1 | 2);
gr.ReleaseHdc(hdc);
}
var bmpSource = System.Windows.Interop.Imaging.CreateBitmapSourceF romHBitmap(
bitmap.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight(sizeX, sizeY)
//BitmapSizeOptions.FromEmptyOptions()
);
img.BeginInit();
img.Source = bmpSource;
img.EndInit();
}
#endregion Code ends here
And what I have as output is distorted bitmap. So my question is WHY?
Foxit Reader (original).jpgFoxit SDK DLL (result).jpg
Comment