Search code examples
fontspdfbox

Embedding standard PDType1Font


I have an application that adds some text to every page of any existing PDF document based on bookmarks. I deliberately use one of the standard fonts and a bright blue color so the text sticks out. It works on the majority of the pages, but on some the font and the color is substituted with whatever exists on the page. Is there a way to force (or embed) the use of the standard font?

Here is the just of the code:

    private void processPage(
            PDDocument doc, PDPage page, String footer
    ) throws IOException {
       try (PDPageContentStream cs = new PDPageContentStream(
              doc, page, PDPageContentStream.AppendMode.APPEND, true, true)) {
        cs.setFont(PDType1Font.HELVETICA_BOLD_OBLIQUE, 12);
        cs.setStrokingColor(Color.BLUE);
        cs.setNonStrokingColor(Color.BLUE);
        cs.beginText();
        cs.newLineAtOffset(70, 15);
        cs.showText(footer);
        cs.endText();
      }
   }

Solution

  • I feel sheepish, the pages where this was happening were disconnected from the bookmark, so this is not an issue (yet).