Modify Wkhtmltox source code to enable conversion of Chinese paths and Chinese names to PDF, image
1.vs2010 Configuring the QT5.5.0 development environment or VS2010 configuration QT5.5.0 development environment
2. Locate pdf_c_binding.cc to add the following statement
A. Modifications
CAPI (int) wkhtmltopdf_set_global_setting (wkhtmltopdf_global_settings * settings, const char * name, const char * value) {
Return reinterpret_cast<settings::P dfglobal *> (Settings)->set (name, Qstring::fromutf8 (value));
}
Switch
CAPI (int) wkhtmltopdf_set_global_setting (wkhtmltopdf_global_settings * settings, const char * name, const char * value) {
Return reinterpret_cast<settings::P dfglobal *> (Settings)->set (name, qstring::fromlocal8bit (value));
}
Modified to recompile build wkhtmltox.lib and Wkhtmltox.dll, support to local Chinese path and Chinese name
B. Modifications
CAPI (int) wkhtmltopdf_set_object_setting (wkhtmltopdf_object_settings * settings, const char * name, const char * value) {
Return reinterpret_cast<settings::P dfobject *> (Settings)->set (name, Qstring::fromutf8 (value));
}
For
CAPI (int) wkhtmltopdf_set_object_setting (wkhtmltopdf_object_settings * settings, const char * name, const char * value) {
Return reinterpret_cast<settings::P dfobject *> (Settings)->set (name, qstring::fromlocal8bit (value));
}
Modify and recompile build Wkhtmltox.lib and Wkhtmltox.dll, support local HTML for Chinese name and save HTML to local
3. Locate image_c_binding.cc to add the following statement
A. Modifications
CAPI (int) wkhtmltoimage_set_global_setting (wkhtmltoimage_global_settings * settings, const char * name, const char * valu E) {
Return Reinterpret_cast<settings::imageglobal *> (settings)->set (name, Qstring::fromutf8 (value));
}
For
CAPI (int) wkhtmltoimage_set_global_setting (wkhtmltoimage_global_settings * settings, const char * name, const char * valu E) {
Return Reinterpret_cast<settings::imageglobal *> (settings)->set (name, qstring::fromlocal8bit (value));
}
Modified to recompile build wkhtmltox.lib and Wkhtmltox.dll, support to local Chinese path and Chinese name
4. The content of the Web page to image output is garbled problem
Locate image_c_binding.cc and image_c_binding_p.hh to add the following statement to the header file
#include <QHash>
Add in the Myimageconverter class
Qhash<qstring, qbytearray> Utf8stringcache;
A. Modifications
CAPI (const char *) wkhtmltoimage_phase_description (Wkhtmltoimage_converter * converter, int phase) {
Return Reinterpret_cast<myimageconverter *> (Converter)->converter.phasedescription (phase). ToUtf8 (). Constdata ();
}
For
CAPI (const char *) wkhtmltoimage_phase_description (Wkhtmltoimage_converter * converter, int phase) {
myimageconverter* conv = Reinterpret_cast<myimageconverter *> (converter);
QString PD = conv->converter.phasedescription (phase);
if (!conv->utf8stringcache.contains (PD))
{
Return Conv->utf8stringcache.insert (PD, Pd.toutf8 ()). Value (). Constdata ();
}
Else
return Conv->utf8stringcache[pd].constdata ();
}
B. Modifications
CAPI (const char *) wkhtmltoimage_progress_string (Wkhtmltoimage_converter * Converter) {
Return Reinterpret_cast<myimageconverter *> (Converter)->converter.progressstring (). ToUtf8 (). Constdata () ;
}
For
CAPI (const char *) wkhtmltoimage_progress_string (Wkhtmltoimage_converter * Converter) {
myimageconverter* conv = Reinterpret_cast<myimageconverter *> (converter);
QString PD = conv->converter.phasedescription (phase);
if (!conv->utf8stringcache.contains (PD))
{
Return Conv->utf8stringcache.insert (PD, Pd.toutf8 ()). Value (). Constdata ();
}
Else
return Conv->utf8stringcache[pd].constdata ();
}
The problem can be resolved by recompiling the build wkhtmltox.lib and Wkhtmltox.dll after modification
Open source Wkhtmltopdf Experience (iv)