Strange behavior with web PDFs

I finally gave up trying to get a Xojo web app to recognize the fonts on the VPS we have been using. The problem was my web app ran fine until the user selected the button to generate and display a PDF. Then nothing. No crash - nothing. The command was simply ignored.

If it won’t run on Linux, I could at least run it on a dedicated Windows computer in our office and expose it to the internet. So I compiled the app for Windows and used remote desktop to copy it to my office computer then ran it. I experienced the same problem as before. Click, then nothing. Next step was to copy the source to the office computer. The app ran as expected in the debugger so I compiled it and ran it. Works perfectly. Xojo seems to have a problem recognizing where fonts are stored for PDFs. I don’t know if others have experienced anything like this. If so, perhaps Xojo should take a look at DynaPDFMBS and add a function so the user can speciy where the fonts are. The MBS function only works with Linux though. Xojo needs it to work with Windows (and maybe Mac).

Uhhh… Greg already suggested this…

Here’s the documentation link for it https://documentation.xojo.com/api/pdf/pdfdocument.html#pdfdocument-addfonts

I made a test using Ubuntu. Not even with Times New Roman installed. Desktop, and it worked. Times is somehow internalized by Xojo as a Type1 font, Postcript, not True Type, but works. All you need is to refer its enum instead of name, weird choice, but works. Later I’ve installed the TTF, but the results were the same, it used the preloaded internal Type1 instead of the TTF.
Didn’t make a test using Web.

It’s not internalized but Xojo. There are 13 base fonts (the ones in that enum) which are available in every PDF reader.

And now I learned that they have few subtle differences. PDF accepts as standard “Times Roman”.

The whole point of this (in the PDF spec) is to have one serif (Times New Roman), one sans-serif (Helvetica or Arial), one monospace (Courier) and one Symbol font (Zapf Dingbats) available at all times so that the PDF reader can still render something even if the PDF doesn’t include the font and the reader doesn’t have a font available. It won’t be pretty, but it’ll be readable. This was the same logic that was used with Adobe Postscript printers at the time (early 1990’s IIRC).

As I reported above, the PDF standard is “Times” not “Times New Roman”. And “Times Roman” is one of the 4 typefaces available: roman, italic, bold, and bold italic.

If somebody really wants “Times New Roman” instead, they will need to load a basic set of it in the Xojo PDF object with PDFDocument.AddFonts (folderPathContainingTheFonts As FolderItem) like /myFonts/TimesNew/ and there you put all the “Times New Roman” TTFs files with the chosen typefaces. I said basic, because Xojo only handles few chars of the file, not the entire universe of unicode blocks there.

The manual needs a bit more details.

Yes, you are correct. There was no such thing as Times New Roman back then. Just Times.

1 Like

For anyone reading this thread and is thinking there’s a disconnect between the four fonts I listed and my statement of 13 base fonts, Times, Helvetica and Courier each have four variants:

  • Regular
  • Bold
  • Italic
  • Bold Italic

So it’s 3 x 4 + 1 = 13

2 Likes

I am having a terrible time with this. To start with, at one point I limited the fonts in the PDF to Times. According to the docs, that should have been embedded in the PDF automatically, but it did not work. Recently, I added a new folder next to the app source named PDF Fonts and copied the Times New Roman and Arial ttf files from the Windows.Fonts folder to it. I added the AddFonts method before any WriteText commands. It runs fine in the debugger, but after compiling and uploading to our VPS it does not work. The PDF Fonts folder was not included in the resources folder so I uploaded the folder to both the resources folder and in a folder next to the app.

The debugger generated a pdf that appeared fine on the screen. But when I downloaded it and opened it with Acrobat, I get an error message that says “The font ‘Arial-Bold’ contains a bad /BBox.” Searching the internet for that error message revealed that the program that created the pdf corrupted the font.

Hi @Dean_Davidge

As far as I understand this is a Web App running on Windows using the last Xojo release, isn’t?

Would you mind to send over the generated PDF file (privately if you prefer)?

Thank you!

My subscription ran out last month and I am waiting for a substantial change before renewing it so I am using 2021r1.1. I replaced Arial with LiberationSans and my last problem went away. It still has weird problems like returning 0 for width of Liberation fonts. Times seems to be the only one I can get a width for and that is what I use for the right alignment of the title and the right column of text on the meter.

The last PDF I made is at https://ezmeter.us/PDFs/A3131-E.pdf

It’s using standard Helvetica, not LiberationSans.

All fonts have to be embedded in your PDF file even if it’s only available for an online version. We insist that the quality of the digital images should have an original high-resolution, at least 300 dpi for figures that will be published in a paper version and at least 150 dpi if it’s only an online version.


PDF Checker 2.1.0  Copyright 2018-2021 Datalogics, Inc. All Rights Reserved

PDF Version: 1.4

Author: Dean Davidge
Creation Date: 2021-Aug-22 15:11:11
Creator: Custom Xojo App
Keywords: EZ Meter, Electric, submeter, PDF, Report
Modification Date: 2021-Aug-22 15:18:09
Producer: Xojo PDFLib 1.0 Windows
Subject: Find a model number
Title: EZ Meter Product Picker
Trapped: 

File Size: 47.6 KB

<<=CHECKER_SUMMARY_START=>>
general:born-digital
userdata:contains-metadata
fonts:uses-base14fonts-not-embedded
sizeInBytes:48709
canBeOptimized
<<=CHECKER_SUMMARY_END=>>

Optimization Assessment
    Document can be optimized

General Results
    Errors:
        None
    Information:
        Document was born digital.  It was produced from PDF authoring software and so it may contain text, images, tables, forms, and other objects.  These types of PDFs typically do not require OCR.
    Checks Completed.
 
Userdata Results
    Errors:
        None
    Information:
        Contains metadata:
            SubType: XML, Update region size: 2048 (1 instance)
            Total: (1 instance)
    Checks Completed.
    How To Optimize:
        Metadata can be removed to save space. (1 instance)
        XMP Metadata padding can be removed  to save space. (1 instance)

Fonts Results
    Errors:
        Uses Base 14 fonts not embedded in document:
            Helvetica (1 instance)
            Helvetica-Bold (1 instance)
            Times-Roman (1 instance)
    Information:
        None
    Checks Completed.

Objects Results
    Errors:
        None
    Information:
        None
    Checks Completed.

Cleanup Results
    Errors:
        None
    Information:
        None
    Checks Completed.

Image Results
    Errors:
        None
    Information:
        None
    Checks Completed.

    Color Images
    Errors:
        None
    Information:
        None
    Checks Completed.

    Grayscale Images
    Errors:
        None
    Information:
        None
    Checks Completed.

    Monochrome Images
    Errors:
        None
    Information:
        None
    Checks Completed.

I think not having the fonts embedded in the document is the problem. The documentation for PDFDocument.AddFonts leads me to believe that its use is not required if I am only using the Standard14 fonts which I am. I tried using non-standard fonts putting them in a folder next to the app and also in the Resources folder. I started the app in the VPS using terminal and as soon as I clicked the PDF button in the browser, I got an error message “Fontconfig error: Cannot load default config file”. Is there a special name for the folder and where should it be located for Centos?

Go to terminal. What does this print?

echo $FONTCONFIG_PATH

echo $FONTCONFIG_PATH returned nothing. I think there is something going on besides the fonts on the server. I developed the app using Windows. I compiled the app for Windows and copied the files to another computer. It did the same thing. I moved my Xojo license to that other computer along with the source code and compiled it there. App works fine now.
My license expired last month so I have been using 2021r1.1 and found that recently web messageboxes do not close when the OK button is clicked. They work properly with 2021r2 so I am wondering if some recent change in Windows is affecting the compiler too.
2021r1.1 messageboxes work fine in MacOS.

I think you’ll find that it’s related to which browser you are using instead of which platform you are on.

1 Like

Trying to understand your linux browser error

Do a

ls -al /etc/fonts/fonts.conf

show a file?

That’s the expected place for the default fonts configuration, and if you change it, you must set and export a new one in $FONTCONFIG_PATH

There is a fonts.conf file that I opened in nano and it appears to be a standard file that should not be edited.