Hi! This function is called correctly but pdf isn't saved..
void OnExport(wxCommandEvent& WXUNUSED(event))
{
wxFileDialog dlg(this, wxT("ESPORTA PDF"), wxEmptyString, wxEmptyString, wxT("Documento PDF (*.pdf)|(*.pdf)"), wxSAVE | wxOVERWRITE_PROMPT);
if (dlg.ShowModal() != wxOK) return;
wxPdfDocument pdf;
pdf.AddPage();
pdf.SetFont(wxT("Helvetica"), wxT(""), 12);
pdf.SetMargins(20, 20, 20);
for (int i(0); i < 2; ++i)
{
wxString HEAD = wxT("<b>MyHTML</b>");
pdf.WriteXml(HEAD);
}
wxString working_dir = wxGetWorkingDirectory();
wxSetWorkingDirectory(dlg.GetPath());
pdf.SaveAsFile(dlg.GetFilename() + wxT(".pdf"));
wxFileType* fileType = wxTheMimeTypesManager -> GetFileTypeFromExtension(wxT("pdf"));
if (fileType)
{
wxString cmd = fileType -> GetOpenCommand(dlg.GetFilename() + wxT(".pdf"));
if (!cmd.IsEmpty()) wxExecute(cmd);
delete fileType;
}
wxSetWorkingDirectory(working_dir);
fileType = NULL;
}
wxPdfDocument - Save Pdf Topic is solved
-
- Experienced Solver
- Posts: 96
- Joined: Thu Apr 17, 2014 10:10 am
wxPdfDocument - Save Pdf
I'm Italian but we can speak C++
Re: wxPdfDocument - Save Pdf
You should replace wxSAVE and wxOVERWRITE_PROMPT by wxFD_SAVE and wxFD_OVERWRITE_PROMPT respectively, since the constants you used are outdated and will only work if wxWidgets was compiled with version 2.6 compatibility.wxProgrammer wrote:Hi! This function is called correctly but pdf isn't saved..
void OnExport(wxCommandEvent& WXUNUSED(event))
{
wxFileDialog dlg(this, wxT("ESPORTA PDF"), wxEmptyString, wxEmptyString, wxT("Documento PDF (*.pdf)|(*.pdf)"), wxSAVE | wxOVERWRITE_PROMPT);
dlg.Path returns the full path (directory and filename) of the selected file. The argument for wxSetWorkingDirectory should be a directory only. I'm not sure whether the working directory is set as expected if you pass a filename to this function.wxProgrammer wrote: if (dlg.ShowModal() != wxOK) return;
wxPdfDocument pdf;
pdf.AddPage();
pdf.SetFont(wxT("Helvetica"), wxT(""), 12);
pdf.SetMargins(20, 20, 20);
for (int i(0); i < 2; ++i)
{
wxString HEAD = wxT("<b>MyHTML</b>");
pdf.WriteXml(HEAD);
}
wxString working_dir = wxGetWorkingDirectory();
wxSetWorkingDirectory(dlg.GetPath());
According to the documentation dlg.GetFilename returns the default filename (which you set as an empty string). You should use dlg.GetPath to get the filename selected in the file selection dialog.wxProgrammer wrote: pdf.SaveAsFile(dlg.GetFilename() + wxT(".pdf"));
In principle the code should work, provided that the filename is valid. What behaviour do you get? Do you get warnings or error messages? Is the PDF viewer (Adobe Reader or similar) started? If yes, what is displayed?wxProgrammer wrote: wxFileType* fileType = wxTheMimeTypesManager -> GetFileTypeFromExtension(wxT("pdf"));
if (fileType)
{
wxString cmd = fileType -> GetOpenCommand(dlg.GetFilename() + wxT(".pdf"));
if (!cmd.IsEmpty()) wxExecute(cmd);
delete fileType;
}
wxSetWorkingDirectory(working_dir);
fileType = NULL;
}
You could / should use wxMessageBox to display the filename used in method SaveAsFile and the command passed to wxExecute. Maybe this gives you clou where to look for the generated PDF file.
Regards,
Ulrich
-
- Experienced Solver
- Posts: 96
- Joined: Thu Apr 17, 2014 10:10 am
Re: wxPdfDocument - Save Pdf
wxFileDialog dlg(this, wxT("ESPORTA PDF"), wxEmptyString, wxEmptyString, wxT("Documento PDF (*.pdf)|*.pdf"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (dlg.ShowModal() == wxID_CANCEL) return;
Now work
EDIT: I have read now your post, now I change with GetPath() thank you
if (dlg.ShowModal() == wxID_CANCEL) return;
Now work
EDIT: I have read now your post, now I change with GetPath() thank you
I'm Italian but we can speak C++
-
- Experienced Solver
- Posts: 96
- Joined: Thu Apr 17, 2014 10:10 am
Re: wxPdfDocument - Save Pdf
Work, and the PDF Reader is shown, thank you
I'm Italian but we can speak C++