Open source Wkhtmltopdf usage experience (iv)

Source: Internet
Author: User
Tags wkhtmltopdf

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.