comment creer un fichier pdf ?
Added by Ericken Sty over 7 years ago
I use Qt with Wt, in the pro file I have this:
LIBS + = -LZ: / PROGRAM_FILE / Wt_402_msvs2015_x64 / lib
@CONFIG (release, debug | release): LIBS + = -lwt -lwthttp -lwtdbo -lwtdbomysql -llibhpdf
else: CONFIG (debug, debug | release): LIBS + = -lwtd -lwthttpd -lwtdbod -lwtdbomysqld -llibhpdfd
else: unix: LIBS + = -lwt -lwthttp -lwtdbo -lwtdbomysql -llibhpdf
INCLUDEPEPH + = Z: / PROGRAM_FILE / Wt_402_msvs2015_x64 / include@
I would like to create a pdf to be downloaded I have this code:
@#include <Wt / WResource.h>
#include <Wt / Http / Request.h>
#include <Wt / Http / Response.h>
#include <Wt / Render / WPdfRenderer.h>
#include <Wt / Render / WTextRenderer.h>
#include <hpdf.h>
class ReportResource: public Wt :: WResource
{
public:
ReportResource (Wt :: WContainerWidget * target): WResource (), m_target (nullptr)
{
suggestFileName ( "document.pdf");
m_target = target;
}
virtual ~ ReportResource () {beingDeleted (); }
virtual void handleRequest (const Wt :: Http :: Request & request, Wt :: Http :: Response & response)
{
response.setMimeType ( "text / html");
HPDF_Doc pdf = HPDF_New (error_handler, 0);
HPDF_UseUTFEncodings (pdf); // Note: UTF-8 encoding (for TrueType fonts) is only available since libharu 2.3.0!
renderReport (pdf);
HPDF_SaveToStream (pdf);
unsigned int size = HPDF_GetStreamSize (pdf);
HPDF_BYTE * buf = new HPDF_BYTE [size];
HPDF_ReadFromStream (pdf, buf, & size);
HPDF_Free (pdf);
response.out (). write ((char *) buf, size);
delete [] buf;
}
private:
Wt :: WContainerWidget * m_target;
void renderReport (HPDF_Doc pdf)
{
std :: stringstream ss;
m_target-> htmlText (ss);
std :: string out = ss.str ();
/ * std :: string out_id = m_target-> id ();
std :: string out_parent_id = m_target-> parent () -> id (); * /
HPDF_Page page = HPDF_AddPage (pdf);
HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);
renderPdf (Wt :: WString :: fromUTF8 (out), pdf);
}
void renderPdf (Wt const :: WString & html, HPDF_Doc pdf)
{
HPDF_Page page = HPDF_AddPage (pdf);
HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);
Wt :: Render :: WPdfRenderer renderer (pdf, page);
renderer.setMargin (2.54);
renderer.setDpi (96);
renderer.render (html);
}
};@
but I have a compilation error
fret.obj: -1: error: LNK2019: unresolved external symbol "__declspec (dllimport) public: __cdecl Wt :: Render :: WPdfRenderer :: WPdfRenderer (struct _HPDF_Doc_Rec *, struct _HPDF_Dict_Rec *)" (__imp _? 0WPdfRenderer
Render @ Wt @@ QEAA @ PEAU_HPDF_Doc_Rec @@ PEAU_HPDF_Dict_Rec @@@ Z) referenced in function "private: void __cdecl ReportResource :: renderPdf (class Wt :: WString const &, struct _HPDF_Doc_Rec *)" (? RenderPdf @ ReportResource @@ AEAAXAEBVWString @ Wt @@ @@@ PEAU_HPDF_Doc_Rec Z)
@
How to solve this problem?
Replies (2)
RE: comment creer un fichier pdf ? - Added by Wim Dumon over 7 years ago
Did you define HPDF_DLL in your project? That is required if you want to use PDF generation with Wt's prebuilt binaries. Hpdf is a bit weird in the sense that the type declarations are adjusted for DLL builds, which can cause unexpected linker errors like these.
wim.