Printing a logo in every page of a document

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Magdalen
In need of some credit
In need of some credit
Posts: 2
Joined: Fri Oct 02, 2015 12:04 pm

Printing a logo in every page of a document

Post by Magdalen » Fri Oct 02, 2015 12:48 pm

Hello to everyone,
I should insert my company's logos in every page of a document printed by wxRichTextPrinting (wxWidgets 3.0.2).
The document contains only text. At the moment, I have printed the image at the beginning, but I need it in every page, at the beginning for example. Or, alternatively, I'd like to add it in the header, so that it would be in every page, but it seems not to be possible.
Would anyone know how to help me please?
Thanks in advance.
Best regards
Magdalen

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Re: Printing a logo in every page of a document

Post by tierra » Fri Oct 02, 2015 1:16 pm

I don't think that's possible with wxRichTextPrinting. It's really designed to make printing ridiculously easy since it's extremely complicated to handle printing yourself using wxPrintout, but in this case, if you really want to power to make customizations like rendering images in headers or footers, then you really should switch to manual printouts using your own rendering and layout code.

Optionally, it might be worth contributing a patch to wxRichTextPrinting that offers a way to interrupt each page, that reserves some margin space for additional rendering in custom paint methods. I probably would have been in favor of that API instead of the current wxRichTextHeaderFooterData class back when this was first written, but it's certainly far too late for that now.

User avatar
doublemax
Moderator
Moderator
Posts: 14801
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Printing a logo in every page of a document

Post by doublemax » Fri Oct 02, 2015 2:00 pm

There is no easy way to do this.

I'm not 100% sure, but looking through the source code, this might work:

Derive your own class from wxRichTextPrintout and override the method OnPrintPage(). The original code looks like this:

Code: Select all

bool wxRichTextPrintout::OnPrintPage(int page)
{
    wxDC *dc = GetDC();
    if (dc)
    {
        if (HasPage(page))
            RenderPage(dc, page);
        return true;
    }
    else return false;
}
Before or after RenderPage() render your own custom content onto the page.

Derive your own class from wxRichTextPrinting(), override the method CreatePrintout() and return an instance of your wxRichTextPrintout.

However this doesn't solve the problem that the "normal" content of the page must not overlap your custom content. I see no easy fix for that, that would require even deeper changes to the related classes.
Use the source, Luke!

Magdalen
In need of some credit
In need of some credit
Posts: 2
Joined: Fri Oct 02, 2015 12:04 pm

Re: Printing a logo in every page of a document

Post by Magdalen » Mon Oct 05, 2015 2:36 pm

Thank you very much. I'll try yet by wxRichTextPrintout even if it seems a bit hard :-?

User avatar
evstevemd
Part Of The Furniture
Part Of The Furniture
Posts: 2292
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania
Contact:

Re: Printing a logo in every page of a document

Post by evstevemd » Fri Oct 09, 2015 5:09 pm

Or Save XML, Parse it to add image and print with wxHtmlEasyPrinting
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?
[Ubuntu 19.04/Windows 10 Pro/MacOS 10.13 - GCC/MinGW/Clang, CodeLite IDE]

Post Reply