Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Trouble with Library and DirectX |
Post Reply |
Author | |
mulfycrowh
Beginner Joined: 03 May 10 Status: Offline Points: 18 |
Post Options
Thanks(0)
Posted: 05 Jun 10 at 8:30AM |
Good morning !
Here you will find a sample under DirectX :
MY PDF DLL :
---------------- // T4UDLL_PDF.cpp : Defines the exported functions for the DLL application.
// #include "stdafx.h"
#include "T4UDLL_PDF.h" #include "QuickPDFDLL0719.h" #define LENGTH_FILENAME 100
const char cQuickPDFFileName[LENGTH_FILENAME] = "C:\\Program Files\\Quick PDF Library\\DLL\\QuickPDFDLL0719.dll";
const string strLicenseKey = "j59g79ru43q9dp4b35ri7nt5y"; const string password = ""; // Declare and load Quick PDF Library DLL
static QuickPDFDLL0719& My_QuickPDF = QuickPDFDLL0719::getInstance(cQuickPDFFileName); /********************
* Class Constructor * ********************/ CT4UDLL_PDF::CT4UDLL_PDF(void) { // Unlock the library int iResult = My_QuickPDF.UnlockKey(strLicenseKey); PDFLibraryUnlocked = (iResult == 1); }; /*******************
* Class Destructor * *******************/ CT4UDLL_PDF::~CT4UDLL_PDF(void) { } /******************************************
* EXPORTED FUNCTION * * getInstance * * Gets the singleton of the class * ******************************************/ extern "C" __declspec(dllexport)CT4UDLL_PDF& CT4UDLL_PDF::getInstance() { static CT4UDLL_PDF pInstance; return pInstance; } /************************************************
* OpenPDFFile * * Opens the PDF file and loads * * the following fields : * * * * PageNumber * * Width * * Height * * Returns success * ************************************************/ bool CT4UDLL_PDF::OpenPDFFile(const char* PDFFileName) { FileHandle = My_QuickPDF.DAOpenFile(PDFFileName,password); PageCount = My_QuickPDF.GetPageCount(FileHandle); // Reference on the first page of the document // To compute height and width PageReference = My_QuickPDF.DAFindPage(FileHandle,1); PageHeight = My_QuickPDF.GetPageHeight(FileHandle,PageReference); PageWidth = My_QuickPDF.GetPageWidth(FileHandle,PageReference); return (FileHandle != 0); }; /************************************************************ * RenderPDFFilePageToDC * * Renders the specified page from the specified document * * Directly onto a Device Context * ************************************************************/ bool CT4UDLL_PDF::RenderPDFFilePageToDC(int DeviceContext, int DPI, int PageNumber) { int PageReference = My_QuickPDF.DAFindPage(FileHandle,PageNumber); int PageRendered = My_QuickPDF.DARenderPageToDC(FileHandle,PageReference,DPI,DeviceContext); return (PageRendered == 1); }; /************************************************************ * RenderPDFFilePageToFile * * Renders the specified page from the specified document * * Directly onto a Device Context * ************************************************************/ bool CT4UDLL_PDF::RenderPDFFilePageToFile(const char* FileName, int DPI, int PageNumber, int Options) { int PageReference = My_QuickPDF.DAFindPage(FileHandle,PageNumber); int PageRendered = My_QuickPDF.DARenderPageToFile(FileHandle,PageReference,Options,DPI,FileName); return (PageRendered == 1); }; /************************************************
* ClosePDFFile * * Closes the PDF file * ************************************************/ void CT4UDLL_PDF::ClosePDFFile(int FileHandle) { My_QuickPDF.DACloseFile(FileHandle); }; /**************************************
* Get_KeyDetected * * Accessor to PDFLibraryUnlocked * **************************************/ bool CT4UDLL_PDF::Get_PDFLibraryUnlocked(void) { return PDFLibraryUnlocked; } /**************************************
* Get_FileHandle * * Accessor to FileHandle * **************************************/ int CT4UDLL_PDF::Get_FileHandle(void) { return FileHandle; } /************************************************
* Get_PageCount * * Accessor to PageCount * ************************************************/ int CT4UDLL_PDF::Get_PageCount(void) { return PageCount; } /**************************************
* Get_PageHeight * * Accessor to PageHeight * **************************************/ double CT4UDLL_PDF::Get_PageHeight(void) { return PageHeight; } /**************************************
* Get_PageWidth * * Accessor to PageWidth * **************************************/ double CT4UDLL_PDF::Get_PageWidth(void) { return PageWidth; } /**************************************
* Get_LastErrorCode * * Accessor to LastErrorCode * **************************************/ int CT4UDLL_PDF::Get_LastErrorCode(void) { return LastErrorCode; } /**********************************************
* Get_Canvas * * Gets a device context handle from a canvas * **********************************************/ HDC CT4UDLL_PDF::Get_Canvas(int Width, int Height) { return (HDC)My_QuickPDF.GetCanvasDC(Width,Height); } HERE IS MY METHOD FOR RENDERING A BITMAP UNDER DIRECTX
IT RUNS WELL : -------------------------------------------------------------------------------- /******************************************************************** * Render_IconBitmap * * Renders the icon bitmap from the top left coordinates _X,_Y * ********************************************************************/ HRESULT dxManager::Render_IconBitmap(int _X,int _Y,int iGraspHelpMsg,int iIconBitmapReference) { RECT src; RECT dest; D3DXIMAGE_INFO imageInfo; HRESULT hResult; IDirect3DSurface9* pBufferBitmap = NULL; IDirect3DSurface9* srcSurface = NULL; D3DSURFACE_DESC desc_backbuffermem; string sIconBitmapFileName = cDirectoryIcons + My_Turn_For_You.Get_PBitmap(iIconBitmapReference)->Get_BitmapFilename(); // Computes the new coordinates for the given resolution _X = ConvertCoordinate_X(_X); _Y = ConvertCoordinate_Y(_Y); if (FAILED(D3DXGetImageInfoFromFile(format_Bitmap(sIconBitmapFileName).c_str(), &imageInfo)))
return E_FAIL; src.bottom = imageInfo.Height-1; src.left = 0; src.right = imageInfo.Width-1; src.top = 0; dest.bottom = _Y+imageInfo.Height-1; dest.left = _X; dest.right = _X+imageInfo.Width-1; dest.top = _Y; // Creates the object within the backup class if (iGraspHelpMsg != ID_MSG_DUMMY) { pBackup.push_back(new CBackup(TYPE_BITMAP_GRASP,iIconBitmapReference,iGraspHelpMsg, My_Turn_For_You.Get_PageTurnForYou(),_X,_Y,dest)); ++Nb_GraspObjects; } else pBackup.push_back(new CBackup(TYPE_BITMAP,iIconBitmapReference,ID_MSG_DUMMY, My_Turn_For_You.Get_PageTurnForYou(),_X,_Y,dest)); ++ Nb_DisplayedObjects; // Gets backbuffer_mem descriptor
backbuffer_mem->GetDesc(&desc_backbuffermem); // Creates a surface whose size equals to size of bitmap with same descriptor as backbuffer_mem // Descriptors mut be the same ones for UpdateSurface method to succeed // D3DPOOL_DEFAULT for UpdateSurface method to suceed if (FAILED(pd3dDevice->CreateOffscreenPlainSurface(imageInfo.Width, imageInfo.Height,desc_backbuffermem.Format, D3DPOOL_DEFAULT, &pBufferBitmap, NULL))) return E_FAIL; pBackup[Nb_DisplayedObjects-1]->Set_SurfaceObject(pBufferBitmap); // Copies the region of backbuffer_mem to pBufferBitmap if (FAILED(D3DXLoadSurfaceFromSurface(pBufferBitmap,NULL,&src,backbuffer_mem,NULL,&dest,D3DX_FILTER_NONE,0))) return E_FAIL; // Gets the bitmap surface PTA: if (FAILED(srcSurface = getSurfaceFromBitmap(format_Bitmap(sIconBitmapFileName)))) return E_FAIL; PTB: // Copies srcSurface to backbuffer
if (FAILED(blitToSurface(srcSurface, &src, &dest))) return E_FAIL; // Copies the bitmap surface to backbuffer_mem hResult = D3DXLoadSurfaceFromSurface(backbuffer_mem,NULL,&dest,srcSurface,NULL,&src,D3DX_FILTER_NONE,0); return hResult; } QUESTION IS : ------------------ When I add the lines :
HDC hdc; srcSurface->GetDC(&hdc); bool Res = CT4UDLL_PDF::getInstance().RenderPDFFilePageToDC((int)hdc,92,1); Between the lines PTA: and PTB:
Although Res returns true, it's no more possible to blit srcSurface onto the backbuffer ! WHY ???? |
|
Jan
Beginner Joined: 24 May 10 Location: Czech Republic Status: Offline Points: 14 |
Post Options
Thanks(0)
|
May be, that was other problem (I'm know nothing about GDI+, I use C# where is GDI+ encapsulated... ):
public void redraw()
{
int vysledek;
if (pdf == null) { return; }
Graphics g = this.CreateGraphics();
//Do Double Buffering
Graphics offScreenDC;
offScreenDC = Graphics.FromImage(offScreenBmp);offScreenDC.TextRenderingHint = System.Drawing.Text. TextRenderingHint.AntiAlias;offScreenDC.SmoothingMode = System.Drawing.Drawing2D. SmoothingMode.AntiAlias;offScreenDC.Clear( this.BackColor);vysledek = pdf.DARenderPageToDC(fileHandle, pdf.DAFindPage(fileHandle, strana), zoom, offScreenDC.GetHdc().ToInt32()); // HERE: without use ReleaseHdc() was screen empty...
offScreenDC.ReleaseHdc();
// I draw the buffer on the graphic of my control
//g.DrawImageUnscaled(offScreenBmp, 0, 0);
g.DrawImageUnscaled(offScreenBmp, - dx, - dy); offScreenDC.Dispose(); g.Dispose(); } |
|
Shah
Beginner Joined: 09 Jun 10 Status: Offline Points: 1 |
Post Options
Thanks(0)
|
Hi,
I use the Quick PDF Library year back and it works great. About your question Between the lines PTA: and PTB:
Although Res returns true, it's no more possible to blit
srcSurface onto the backbuffeYou need to work little close with your code. First make sure "RenderPDFFilePageToDC" is working fine. If it is working fine means there is no issue with library. Second step check function "D3DXLoadSurfaceFromSurface" you have enough memory available to render page on buffer. also try co call "AddDirtRec" explicitly. Thanks, Shah |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store