Asked by:
How to use RenderPageToSurface in PDF API in easy way but best performance?

Question
-
Hi , I'm c# programmer. I know c++ little bit.
My Application Structure that C#/XAML have to call C++ Pdf Renderer for fast render pdf page.
I'm developing an c++ pdf renderer. I will use RenderPageToSurface method it only have in C++. I would like to know "How to deveop it".
I try to developed, but i found problem. When my app call RenderPageToSurface it work, but call again (use in render when user zoom pdf page) it occur AccessViolationException. I can't catch this Exception in C# !!
Please help and sugest me how should i do.
Thanks.
Here is my c++ code
// Initialize hardware-dependent resources. void PDFDocumentRenderer::CreateDeviceResources() { UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; const D3D_FEATURE_LEVEL featureLevels [] = { D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1, }; ComPtr<ID3D11Device> d3dDevice; ComPtr<ID3D11DeviceContext> d3dContext; DX::ThrowIfFailed( D3D11CreateDevice( nullptr, D3D_DRIVER_TYPE_HARDWARE, 0, creationFlags, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, &m_d3dDevice, &featureLevel, &d3dContext ) ); m_d3dDevice.As(&dxgiDevice); d2dFactory->CreateDevice(dxgiDevice.Get(), &d2dDevice); d2dDevice->CreateDeviceContext( D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &d2dDeviceContext ); d2dDeviceContext->SetUnitMode(D2D1_UNIT_MODE_PIXELS); d2dDeviceContext->SetTextAntialiasMode(D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE); HRESULT pdfCreateHR = PdfCreateRenderer(dxgiDevice.Get(), &m_PdfRenderer); }
//Render Method void PDFDocumentRenderer::RenderPage(PdfPage^ page, SurfaceImageSource^ surface, int width, int height) { reinterpret_cast<IInspectable*>(surface)->QueryInterface(IID_PPV_ARGS(&m_sisNative)); ComPtr<IDXGIDevice> local_dxgiDevice; dxgiDevice.Get()->QueryInterface(IID_PPV_ARGS(&local_dxgiDevice)); m_sisNative->SetDevice(local_dxgiDevice.Get()); POINT offset = { 0, 0 }; RECT rectangle = { 0, 0, static_cast<long>(width), static_cast<long>(height) }; ComPtr<IDXGISurface> dxgiSurface; HRESULT beginDrawHR = m_sisNative->BeginDraw(rectangle, &dxgiSurface, &offset); PDF_RENDER_PARAMS params; params.DestinationHeight = height; params.DestinationWidth = width; params.BackgroundColor = DX::ConvertToColorF(Windows::UI::Colors::White); params.SourceRect.left = 0; params.SourceRect.top = 0; params.SourceRect.bottom =0; params.SourceRect.right = 0; HRESULT pdfRenderHR = m_PdfRenderer->RenderPageToSurface(reinterpret_cast<IUnknown*>(page), dxgiSurface.Get(), offset, ¶ms); HRESULT endDrawHR = m_sisNative->EndDraw(); }
UPATE I'm debugging , I found this line is occur AccessViolationException
HRESULT pdfRenderHR = m_PdfRenderer->RenderPageToSurface(reinterpret_cast<IUnknown*>(page), dxgiSurface.Get(), offset, ¶ms);
And I track begindrawHR , I got value is 0x80070057
HRESULT beginDrawHR = m_sisNative->BeginDraw(rectangle, &dxgiSurface, &offset); // got 0x80070057
P.S. I try to adapt as http://code.msdn.microsoft.com/windowsapps/PDF-viewer-showcase-sample-39ced1e8 , but hard to understand for me.
- Edited by Korawit Tuesday, April 22, 2014 10:05 AM ๊Update Information
- Moved by Matt SmallMicrosoft employee, Moderator Tuesday, April 22, 2014 12:59 PM C++ question
Tuesday, April 22, 2014 6:39 AM
All replies
-
I'm thinking that it might be a better idea to debug this in WinDBG so you can try to capture the exception easier.
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.Tuesday, April 22, 2014 7:36 PMModerator -
Ok , I will try WinDBG later.
I would like to know why HRESULT is not SUCCESSED.
Wednesday, April 23, 2014 2:11 AM