wxPDFDoc without building a library Topic is solved

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: 2408
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

wxPDFDoc without building a library

Post by evstevemd »

I want to use wxPDFDoc with my app. I don't want to build it separately and I wonder if I can just include the files with my project and build them together.
Also I want to use System fonts so I don't want to include with my app extra fonts. Are those two things possible?
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: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPDFDoc without building a library

Post by utelle »

evstevemd wrote:I want to use wxPDFDoc with my app. I don't want to build it separately and I wonder if I can just include the files with my project and build them together.
Sure, you can do that of course. There are currently no external dependencies except wxWidgets.
evstevemd wrote:Also I want to use System fonts so I don't want to include with my app extra fonts. Are those two things possible?
Well, that depends on the requirements of your application. If you can restrict your application to just use the 14 PDF / PostScript core fonts Helvetica (Regular, Bold, Oblique, BoldOblique), Times Roman ((Regular, Bold, Oblique, BoldOblique), Courier (Regular, Bold, Oblique, BoldOblique), Symbol, and ZapfDingbats, then no fonts have to be embedded into the resulting PDF document. You refer to those fonts by the names "Courier", "Helvetica", "Times", "Symbol", and "ZapfDingbats" in the wxPdfDocument API. It is not required to "register" those fonts; they are always "known" by wxPdfDocument.

However, you have to face the fact that the core fonts support only a limited character set, corresponding more or less to Windows-1252 (Latin-1) or ISO-8859-1 codepages. You can find the list of available characters in Appendix D of the Adobe PDF reference.

Regards,

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

Re: wxPDFDoc without building a library

Post by evstevemd »

utelle wrote:
evstevemd wrote:I want to use wxPDFDoc with my app. I don't want to build it separately and I wonder if I can just include the files with my project and build them together.
Sure, you can do that of course. There are currently no external dependencies except wxWidgets.
Thank you so much for your confirmation. I appreciate it!
utelle wrote:
evstevemd wrote:Also I want to use System fonts so I don't want to include with my app extra fonts. Are those two things possible?
Well, that depends on the requirements of your application. If you can restrict your application to just use the 14 PDF / PostScript core fonts Helvetica (Regular, Bold, Oblique, BoldOblique), Times Roman ((Regular, Bold, Oblique, BoldOblique), Courier (Regular, Bold, Oblique, BoldOblique), Symbol, and ZapfDingbats, then no fonts have to be embedded into the resulting PDF document. You refer to those fonts by the names "Courier", "Helvetica", "Times", "Symbol", and "ZapfDingbats" in the wxPdfDocument API. It is not required to "register" those fonts; they are always "known" by wxPdfDocument.

However, you have to face the fact that the core fonts support only a limited character set, corresponding more or less to Windows-1252 (Latin-1) or ISO-8859-1 codepages. You can find the list of available characters in Appendix D of the Adobe PDF reference.

Regards,

Ulrich
I'm lost here, please excuse my ignorance.
Let say for example I use Liberation Sans (which comes with ubuntu and is availble for free), is there anything extra I need to do?
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: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPDFDoc without building a library

Post by utelle »

evstevemd wrote:
utelle wrote:
evstevemd wrote:Also I want to use System fonts so I don't want to include with my app extra fonts. Are those two things possible?
Well, that depends on the requirements of your application. If you can restrict your application to just use the 14 PDF / PostScript core fonts Helvetica (Regular, Bold, Oblique, BoldOblique), Times Roman ((Regular, Bold, Oblique, BoldOblique), Courier (Regular, Bold, Oblique, BoldOblique), Symbol, and ZapfDingbats, then no fonts have to be embedded into the resulting PDF document. You refer to those fonts by the names "Courier", "Helvetica", "Times", "Symbol", and "ZapfDingbats" in the wxPdfDocument API. It is not required to "register" those fonts; they are always "known" by wxPdfDocument.

However, you have to face the fact that the core fonts support only a limited character set, corresponding more or less to Windows-1252 (Latin-1) or ISO-8859-1 codepages. You can find the list of available characters in Appendix D of the Adobe PDF reference.
I'm lost here, please excuse my ignorance.
Let say for example I use Liberation Sans (which comes with ubuntu and is availble for free), is there anything extra I need to do?
Maybe I misinterpreted your question.

Usually, it is necessary to embed the font data of all used fonts in a PDF document, to make it displayable / readable anywhere. However, this is not the case for the 14 core fonts, which can be used without any special measures, since every PDF reader "knows" how to display those fonts. For example, on Windows platforms the font Arial is the equivalent of the core font Helvetica.

If you are going to use a font that is not one of the core fonts, wxPdfDocument needs access to the font data file. That is, you need to "register" the font in question with a method of the wxPdfDocument font manager (class wxPdfFontManager). This can be done in several ways:
  • Call RegisterFont with the full path of the font data file
  • Call RegisterFont with a wxFont instance of the font, if you used the very same font for on-screen display
  • Call RegisterSystemFonts to register all fonts that are installed in the default font location of your system
  • Call RegisterFontDirectory to register all font files located in a given directory
So, if you want to use font Liberation Sans to create a PDF document with wxPdfDocument, you'll have to register it with wxPdfFontManager.

However, as far as I know, the Liberation fonts are open font replacements for the Microsoft fonts Times New Roman, Arial, and Courier New (which are in turn equivalent to the core fonts Times Roman, Helvetica, and Courier). That is, your application should be fine in just using the core fonts.

Regards,

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

Re: wxPDFDoc without building a library

Post by evstevemd »

That was comprehensive answer. I thank you. You have answered all I asked and more.
Thank you!
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: 2408
Joined: Wed Jan 28, 2009 11:57 am
Location: United Republic of Tanzania

Re: wxPDFDoc without building a library

Post by evstevemd »

Hi Urlich,
I have one more question. Can I force the PDF to use only Single Font in rendering? For example I want everything to be rendered with Exo 2 font only without disturbing Sizes?

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: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPDFDoc without building a library

Post by utelle »

evstevemd wrote:Can I force the PDF to use only Single Font in rendering? For example I want everything to be rendered with Exo 2 font only without disturbing Sizes?
It's not fully clear what you intend to accomplish. wxPdfDocument requires the user / developer to select a font, before writing text to the PDF document. If you want to use only a single certain font, then restrict your application to select just that font.

If you try to output something via wxPdfDC and your drawing method selects various wxFonts to generate the output, then the underlying wxPdfDocument instance will also use various fonts.

In short, it is the developer's responsibility to select the font(s).

If this does not answer your question, please be more specific about what problem you experience that you want to solve.

Regards,

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

Re: wxPDFDoc without building a library

Post by evstevemd »

utelle wrote:
evstevemd wrote:Can I force the PDF to use only Single Font in rendering? For example I want everything to be rendered with Exo 2 font only without disturbing Sizes?
It's not fully clear what you intend to accomplish. wxPdfDocument requires the user / developer to select a font, before writing text to the PDF document. If you want to use only a single certain font, then restrict your application to select just that font.

If you try to output something via wxPdfDC and your drawing method selects various wxFonts to generate the output, then the underlying wxPdfDocument instance will also use various fonts.

In short, it is the developer's responsibility to select the font(s).

If this does not answer your question, please be more specific about what problem you experience that you want to solve.

Regards,

Ulrich
I use wxPdfDC and I want to restrict fonts to single font. Here is my code

Code: Select all

void App::OnExportPDF(wxCommandEvent& event)
{ 
    wxPageSetupDialogData dialogData = wxPageSetupDialogData();
    //.. 
    
    wxPdfPageSetupDialog* dialog = new wxPdfPageSetupDialog(wxTheApp->GetTopWindow(), &dialogData);
    if(dialog->ShowModal() == wxID_OK)
    {
        dialogData = dialog->GetPageSetupData();
        wxPdfPrintData printData = wxPdfPrintData(&dialogData); 

        wxPdfPrintDialog *printDialog =  new wxPdfPrintDialog(wxTheApp->GetTopWindow(), &printData);
        if(printDialog->ShowModal() == wxID_OK)
        { 
            printData = printDialog->GetPdfPrintData(); 
            //wxRichTextPrinting* m_printer;
            m_printer->SetRichTextBufferPrinting(new wxRichTextBuffer());

            wxRichTextPrintout *printPrintout = new wxRichTextPrintout(wxT("Export to PDF"));
            // 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
            );

            wxRichTextBuffer *printBuffer = GetNotepadBuffer();
            printPrintout->SetRichTextBuffer(printBuffer);

            wxPdfPrinter *printer = new wxPdfPrinter(&printData); 
            printer->Print(this, printPrintout, false);
            
            //...

        } 
    } 
}
Now with this code is it possible to limit everything to single Font?

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: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: wxPDFDoc without building a library

Post by utelle »

evstevemd wrote:I use wxPdfDC and I want to restrict fonts to single font. Here is my code

Code: Select all

void App::OnExportPDF(wxCommandEvent& event)
{ 
    wxPageSetupDialogData dialogData = wxPageSetupDialogData();
    //.. 
    
    wxPdfPageSetupDialog* dialog = new wxPdfPageSetupDialog(wxTheApp->GetTopWindow(), &dialogData);
    if(dialog->ShowModal() == wxID_OK)
    {
        dialogData = dialog->GetPageSetupData();
        wxPdfPrintData printData = wxPdfPrintData(&dialogData); 

        wxPdfPrintDialog *printDialog =  new wxPdfPrintDialog(wxTheApp->GetTopWindow(), &printData);
        if(printDialog->ShowModal() == wxID_OK)
        { 
            printData = printDialog->GetPdfPrintData(); 
            //wxRichTextPrinting* m_printer;
            m_printer->SetRichTextBufferPrinting(new wxRichTextBuffer());

            wxRichTextPrintout *printPrintout = new wxRichTextPrintout(wxT("Export to PDF"));
            // 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
            );

            wxRichTextBuffer *printBuffer = GetNotepadBuffer();
            printPrintout->SetRichTextBuffer(printBuffer);

            wxPdfPrinter *printer = new wxPdfPrinter(&printData); 
            printer->Print(this, printPrintout, false);
            
            //...

        } 
    } 
}
Now with this code is it possible to limit everything to single Font?
It really depends on the content of the wxRichTextBuffer. If you used different fonts on creating the content using methods wxRichTextCtrl::SetDefaultStyle, wxRichTextCtrl::SetFont, wxRichTextCtrl::BeginFont, wxRichTextCtrl::SetStyle and the like, then the answer is unfortunately NO. wxPdfDC and hence wxPdfDocument will use the fonts that are associated with the content of the wxRichTextBuffer. In fact, this is not related to wxPdfDC at all - that's how wxRichTextPrintout handles writing to a DC.

If you don't want different fonts in PDF output, you will have to regenerate the wxRichTextBuffer using just a single font.

Regards,

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

Re: wxPDFDoc without building a library

Post by evstevemd »

Ok great.
Thanks for clearing that out. I will find a solution on wxRTC before printing
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