Print Page | Close Window

File Path

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1330
Printed Date: 12 Aug 25 at 4:24PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: File Path
Posted By: mingoal
Subject: File Path
Date Posted: 31 Jan 10 at 10:35AM
Hello everybody!
 
I use QuickPDF to generate pdf, but I find that it does not work as I thought when I pass a string contains characters to functions which need a path as parameter, such as AddImageFromFile(), SavetoFile() etc.
 
For example:
  if(m_docQPDF.AddImageFromFile("C:\Documents and Settings\mingoal\桌面\map.bmp",0) != 0)
{
     AfxMessageBox("Quick PDF Load Image Failed! ");
}
 
 Can somebody help me to solve this promble ,or give me some hints ?
 
Thanks in advance !
 
Mingoal



Replies:
Posted By: Ingo
Date Posted: 31 Jan 10 at 1:37PM
Hi Mingoal!

The path isn't the problem ... the used characters between "mingoal" and "map" are the problem.
You take the path/file-name as a string but in strings you can't work with chinese characters.
The newest versions of QuickPDF are changed to work with unicode-characters, too.
In delphi something like AddImageFromFile(WideString(Edit1.Text),0) <> 0 could work ...

Cheers, Ingo



Posted By: mingoal
Date Posted: 01 Feb 10 at 12:46AM
Thank you for your reply, I really appreciate it. I will try it again under your help.
 
 Best regards!
  mingoal


Posted By: mingoal
Date Posted: 05 Feb 10 at 12:26PM
   I checked the API reference again, and I found that Quick PDF supports unicode file name, but I need to encode the file name using UTF8. Thus, I use a small function to convert a CString object to UTF8-encoding string. Here are my c++ sample code:

char* CString2UTF8(CString& strSrc)
{
   long  lBufferSize=0; 
   long  lResult =0; 
   long  lSrcLen=0;  
   lSrcLen=  strSrc.GetLength()  ;  
   lBufferSize  =  lSrcLen*  3  +  1  ; 
   //Don't forget to release the buffer
   char  *pCharUtf8  =  new  char[lBufferSize]  ;   
  //Translate  using  code  page  65001(UTF-8).   
  lResult =  WideCharToMultiByte(CP_UTF8,  0,strSrc.AllocSysString(),  lSrcLen,  pCharUtf8, lBufferSize,  NULL,  0)  ;   
   pCharUtf8[lResult ]  =  NULL  ; 
   return pCharUtf8;
}
 Sample:

//strFilePath is a CString object
char *pCharPath=CString2UTF8(strFilePath);
 if(m_docQPDF.SaveToFile(pCharPath) == 0)
 {
  delete [] pCharPath;
  pCharPath=NULL;
  return FALSE;
 }
 delete [] pCharPath;
 pCharPath=NULL;
 
 
 



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk