wxPDFDocument : Best way to render wxRichTextCtrl to PDF?
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
wxPDFDocument : Best way to render wxRichTextCtrl to PDF?
Hi All,
I have an app that demands I export contents of wxRTC to PDF. What is the best/effective way of rendering PDF using the class above?
Should I do dirty work of dabbling with styles and formatting or there is easier way?
Thanks!
I have an app that demands I export contents of wxRTC to PDF. What is the best/effective way of rendering PDF using the class above?
Should I do dirty work of dabbling with styles and formatting or there is easier way?
Thanks!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF
No need to dirty your hands. Take a look at the wxPdfDC sample coming with wxPdfDocument 0.9.3. It demonstrates among other things how to print rich text to PDF.evstevemd wrote:I have an app that demands I export contents of wxRTC to PDF. What is the best/effective way of rendering PDF using the class above?
Should I do dirty work of dabbling with styles and formatting or there is easier way?
Regards,
Ulrich
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF
Thanks Ulrich,utelle wrote:No need to dirty your hands. Take a look at the wxPdfDC sample coming with wxPdfDocument 0.9.3. It demonstrates among other things how to print rich text to PDF.evstevemd wrote:I have an app that demands I export contents of wxRTC to PDF. What is the best/effective way of rendering PDF using the class above?
Should I do dirty work of dabbling with styles and formatting or there is easier way?
Regards,
Ulrich
I found this method (presumably is what you was referring). I have many pages in database that I would like to print (My App treats displays single page in wxRTC and gives dropdown aka wxChoice to select any page to edit/display). So my Question is, How can I add the pages before I do the final printing of the PDF?
something like
Code: Select all
for(int i=0; i<pageCount; i++)
{
//add pages somehow to the PDF wannabe
}
printer->Print(this, printPrintout, false);
Here is a function I talk about
Code: Select all
void MyFrame::OnPdfRichTextPrint(wxCommandEvent& WXUNUSED(event) )
{
wxPageSetupDialogData dialogData = wxPageSetupDialogData();
dialogData.SetMarginTopLeft(wxPoint(25,25));
dialogData.SetMarginBottomRight(wxPoint(25,25));
dialogData.EnableMargins(true);
dialogData.EnablePaper(true);
dialogData.EnableOrientation(true);
wxPdfPageSetupDialog* dialog = new wxPdfPageSetupDialog(this, &dialogData);
if( dialog->ShowModal() == wxID_OK )
{
dialogData = dialog->GetPageSetupData();
wxPdfPrintData printData = wxPdfPrintData( &dialogData );
wxPdfPrintDialog *printDialog = new wxPdfPrintDialog(this, &printData );
if( printDialog->ShowModal() == wxID_OK )
{
printData = printDialog->GetPdfPrintData();
// printData now has user info.
// We will use richtextprinting as a convenient storage container for
// the copy richtext buffers. If we did not do this, we would need to handle
// deletion of the buffers in our code.
m_richtextPrinting->SetRichTextBufferPrinting(
new wxRichTextBuffer(m_richtext->GetBuffer())
);
wxRichTextPrintout *printPrintout = new wxRichTextPrintout(wxT("Demo PDF Printing"));
// richtext printout accepts margins in tenths of mm
printPrintout->SetMargins(
10 * dialogData.GetMarginTopLeft().y,
10 * dialogData.GetMarginBottomRight().y,
10 * dialogData.GetMarginTopLeft().x,
10 * dialogData.GetMarginBottomRight().x
);
printPrintout->SetRichTextBuffer( m_richtextPrinting->GetRichTextBufferPrinting() );
wxPdfPrinter *printer = new wxPdfPrinter( &printData );
// don't show a print dialog again - we have already done so
printer->Print(this, printPrintout, false);
delete printer;
delete printPrintout;
}
delete printDialog;
}
delete dialog;
}
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF
In fact your questions is not really related to wxPdfPodument or wxPdfDC, but to the wxWidgets printing framework.evstevemd wrote:I found this method (presumably is what you was referring). I have many pages in database that I would like to print (My App treats displays single page in wxRTC and gives dropdown aka wxChoice to select any page to edit/display). So my Question is, How can I add the pages before I do the final printing of the PDF?
I have to admit that I don't have much experience with the wxWidgets printing framework. But for what I know you would have to derive your own wxPrintout resp wxRichTextPrintout class and to implement method OnPrintPage. When this method is called you get a page number to print. You can then select the rich text buffer to be printed based on the page number. This should work as long as your rich text fragments fit on a single page. It's probably less easy if a fragment is longer than one page.
Regards,
Ulrich
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF
Mh! It seems complicated than thought. May be there is a way with wxPDFDocument to somehow merge the PDFs into a given order?utelle wrote:In fact your questions is not really related to wxPdfPodument or wxPdfDC, but to the wxWidgets printing framework.evstevemd wrote:I found this method (presumably is what you was referring). I have many pages in database that I would like to print (My App treats displays single page in wxRTC and gives dropdown aka wxChoice to select any page to edit/display). So my Question is, How can I add the pages before I do the final printing of the PDF?
I have to admit that I don't have much experience with the wxWidgets printing framework. But for what I know you would have to derive your own wxPrintout resp wxRichTextPrintout class and to implement method OnPrintPage. When this method is called you get a page number to print. You can then select the rich text buffer to be printed based on the page number. This should work as long as your rich text fragments fit on a single page. It's probably less easy if a fragment is longer than one page.
Regards,
Ulrich
I think of changing XML produced by wxRTC but also it is complex and I take it as last resort!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF
This would be possible, but it is neither elegant nor efficient: you could produce a separate PDF file for each fragment. Thereafter you would import the pages from these separate files into a new PDF document. Take a look at the templates sample of wxPdfDocument.evstevemd wrote:Mh! It seems complicated than thought. May be there is a way with wxPDFDocument to somehow merge the PDFs into a given order?
But maybe someone with more knowledge of the wxWidgets printing framework could guide you how to generate multi-page richtext print output. You should probably ask on the wx-users list, too.
For the future I plan to provide a wxPdfDocument based PDF handler for wxRTC (like wxRichTextHTMLHandler), but I don't know whether this would solve your problem. Besides that I have no schedule when this will be available.evstevemd wrote:I think of changing XML produced by wxRTC but also it is complex and I take it as last resort!
Regards,
Ulrich
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF
Thanks for your complement. I will ask on wx-listutelle wrote:This would be possible, but it is neither elegant nor efficient: you could produce a separate PDF file for each fragment. Thereafter you would import the pages from these separate files into a new PDF document. Take a look at the templates sample of wxPdfDocument.evstevemd wrote:Mh! It seems complicated than thought. May be there is a way with wxPDFDocument to somehow merge the PDFs into a given order?
But maybe someone with more knowledge of the wxWidgets printing framework could guide you how to generate multi-page richtext print output. You should probably ask on the wx-users list, too.
For the future I plan to provide a wxPdfDocument based PDF handler for wxRTC (like wxRichTextHTMLHandler), but I don't know whether this would solve your problem. Besides that I have no schedule when this will be available.evstevemd wrote:I think of changing XML produced by wxRTC but also it is complex and I take it as last resort!
Regards,
Ulrich
PDF handler will be nice one.
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF
Is this scheduled yet?utelle wrote:
For the future I plan to provide a wxPdfDocument based PDF handler for wxRTC (like wxRichTextHTMLHandler)
Regards,
Ulrich
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF
Short answer: No.evstevemd wrote:Is this scheduled yet?utelle wrote:
For the future I plan to provide a wxPdfDocument based PDF handler for wxRTC (like wxRichTextHTMLHandler)
Currently I'm still working on a first (partial) implementation of a wxPdfGraphicsContext. This is a major task ... more complex than expected ... this will take probably until end of 1st quarter of 2013, at least. Maybe thereafter I tackle the RTC handler.
Regards,
Ulrich
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF
Thanks for infoutelle wrote:Short answer: No.evstevemd wrote:Is this scheduled yet?utelle wrote:
For the future I plan to provide a wxPdfDocument based PDF handler for wxRTC (like wxRichTextHTMLHandler)
Currently I'm still working on a first (partial) implementation of a wxPdfGraphicsContext. This is a major task ... more complex than expected ... this will take probably until end of 1st quarter of 2013, at least. Maybe thereafter I tackle the RTC handler.
Regards,
Ulrich
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?