wxPDFDocument : Best way to render wxRichTextCtrl to PDF?

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
User avatar
evstevemd
Part Of The Furniture
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?

Post by evstevemd »

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!
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?
utelle
Moderator
Moderator
Posts: 1126
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF

Post by utelle »

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?
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.

Regards,

Ulrich
User avatar
evstevemd
Part Of The Furniture
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

Post by evstevemd »

utelle wrote:
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?
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.

Regards,

Ulrich
Thanks 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?
utelle
Moderator
Moderator
Posts: 1126
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF

Post by utelle »

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?
In fact your questions is not really related to wxPdfPodument or wxPdfDC, but to the wxWidgets printing framework.

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
User avatar
evstevemd
Part Of The Furniture
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

Post by evstevemd »

utelle wrote:
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?
In fact your questions is not really related to wxPdfPodument or wxPdfDC, but to the wxWidgets printing framework.

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
Mh! It seems complicated than thought. May be there is a way with wxPDFDocument to somehow merge the PDFs into a given order?
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?
utelle
Moderator
Moderator
Posts: 1126
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF

Post by utelle »

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?
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.

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.
evstevemd wrote:I think of changing XML produced by wxRTC but also it is complex and I take it as last resort!
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.

Regards,

Ulrich
User avatar
evstevemd
Part Of The Furniture
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

Post by evstevemd »

utelle wrote:
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?
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.

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.
evstevemd wrote:I think of changing XML produced by wxRTC but also it is complex and I take it as last resort!
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.

Regards,

Ulrich
Thanks for your complement. I will ask on wx-list
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?
User avatar
evstevemd
Part Of The Furniture
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

Post by evstevemd »

utelle wrote:
For the future I plan to provide a wxPdfDocument based PDF handler for wxRTC (like wxRichTextHTMLHandler)
Regards,
Ulrich
Is this scheduled yet?
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?
utelle
Moderator
Moderator
Posts: 1126
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPDFDocument : Best way to render wxRichTextCtrl to PDF

Post by utelle »

evstevemd wrote:
utelle wrote:
For the future I plan to provide a wxPdfDocument based PDF handler for wxRTC (like wxRichTextHTMLHandler)
Is this scheduled yet?
Short answer: No.

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
User avatar
evstevemd
Part Of The Furniture
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

Post by evstevemd »

utelle wrote:
evstevemd wrote:
utelle wrote:
For the future I plan to provide a wxPdfDocument based PDF handler for wxRTC (like wxRichTextHTMLHandler)
Is this scheduled yet?
Short answer: No.

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
Thanks for info
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?
Post Reply