From a563801e1a6be5e70645472d82f4ba8534b454d1 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Mon, 12 Dec 2022 23:40:24 +0100 Subject: PDFDoc::sign: Find Arial to sign if Helvetica isn't found At least on my Windows install Helvetica isn't found and signing thus fails --- poppler/PDFDoc.cc | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc index c46ed0c4..e5b6ed55 100644 --- a/poppler/PDFDoc.cc +++ b/poppler/PDFDoc.cc @@ -63,6 +63,7 @@ #include #include +#include #include #include #include @@ -2152,6 +2153,24 @@ bool PDFDoc::hasJavascript() return jsInfo.containsJS(); } +static std::string findPdfFontNameToUseForSigning(Form *form) +{ + static constexpr std::array fontsToUseToSign = { "Helvetica", "Arial" }; + for (const char *fontToUseToSign : fontsToUseToSign) { + std::string pdfFontName = form->findFontInDefaultResources(fontToUseToSign, ""); + if (!pdfFontName.empty()) { + return pdfFontName; + } + + pdfFontName = form->addFontToDefaultResources(fontToUseToSign, "").fontName; + if (!pdfFontName.empty()) { + return pdfFontName; + } + } + + return {}; +} + bool PDFDoc::sign(const char *saveFilename, const char *certNickname, const char *password, GooString *partialFieldName, int page, const PDFRectangle &rect, const GooString &signatureText, const GooString &signatureTextLeft, double fontSize, double leftFontSize, std::unique_ptr &&fontColor, double borderWidth, std::unique_ptr &&borderColor, std::unique_ptr &&backgroundColor, const GooString *reason, const GooString *location, const std::string &imagePath, const std::optional &ownerPassword, const std::optional &userPassword) @@ -2169,11 +2188,7 @@ bool PDFDoc::sign(const char *saveFilename, const char *certNickname, const char } Form *form = catalog->getCreateForm(); - std::string pdfFontName = form->findFontInDefaultResources("Helvetica", ""); - if (pdfFontName.empty()) { - pdfFontName = form->addFontToDefaultResources("Helvetica", "").fontName; - } - + const std::string pdfFontName = findPdfFontNameToUseForSigning(form); if (pdfFontName.empty()) { return false; } -- cgit v1.2.3