wxProgrammer wrote:Code: Select all
wxPdfDocument pdf;
pdf.AddPage();
pdf.SetFont(wxT("Helvetica"), wxT(""), 12);
pdf.SetMargins(0, 20, 20);
pdf.SetTitle((*analysis)[ANALYSIS_FIELDS_NAME]);
pdf.SetAuthor(wxT("La Clinica del PC"));
pdf.Open();
If you make an explicit call to method Open, then it must be the first thing you do. Please refer to the wxPdfDocument API documentation of method
Open:
This method begins the generation of the PDF document.
It is not necessary to call it explicitly because AddPage() does it automatically. Note: no page is created by this method
Method
AddPage already called method
Open implicitly, therefore calling method
Open again messes up the internal state of wxPdfDocument. Just remove the call to method Open, and the generated document should no longer be empty.
Besides that keep in mind that method
SetTitle sets the meta data field of the generated PDF document, that is, no visible output is produced by this method.
wxProgrammer wrote:Code: Select all
pdf.SetY(297/2);
pdf.Ln();
for (int i(0); i < 2; ++i)
{
pdf.SetY(i * (pdf.GetHeight()/2) + 20);
wxString HEAD = wxT("<table><tr><td><img src='images/pdf_logo.png' /></td><td>Copia ");
HEAD += (!i) ? wxT("Analisi") : wxT("Cliente");
HEAD += wxT("</td></tr></table>");
pdf.WriteXml(HEAD);
pdf.WriteXml(wxT("ciao"));
}
pdf.SaveAsFile(dlg.GetPath());
Why the document is empty? It's saved but the page is white, empty.
Your first call to method
AddPage creates a new page. However, not output is written to this page, before the (at this point invalid) call to method
Open. Therefore the page is blank. Since method
Open resets the internal state and no call to method
AddPage follows, the following output methods do not create visible content.
I would advise to inspect the numerous samples coming with wxPdfDocument to get a feeling how wxPdfDocument works.
Regards,
Ulrich