-2

I am able to get a PDF file from an URL, encoding the stream into base 64 and send the string to a third party within a field of a XML file, but I have the next issue when I try to open the PDF file decode.

Cannot extract the embedded font 'ArialMT,Bold". Some characters may not display or print correctly.

Here is the code from Java Mapping in SAP PI 7.1:

    urlStr = "Insert here your url";
    StringBuffer data = new StringBuffer();
    URL url = new URL(urlStr);
    URLConnection conn = url.openConnection ();

    // Get the response
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    StringBuffer sb = new StringBuffer();
    String line;
    String carriagereturn = System.getProperty("line.separator");

    while ((line = rd.readLine()) != null)
    {
        trace.addWarning(line);
        sb.append(line);
        sb.append(carriagereturn);
    }

    rd.close();
    result = sb.toString();
} catch (Exception e){
    trace.addWarning(e.toString());
}

return org.apache.commons.codec.binary.Base64.encodeBase64String(result.getBytes());

I have read that it is not possible to retrieve the font when you execute an InputStreamReader because of the copyrights of the letter. Is it true?

Is there other any possibility to embed the font afterwards using iText library or similar?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • have you tried comparing the bytes of the original pdf to the bytes of the pdf after it goes through the various steps to confirm that the pdf has not accidentally been corrupted at some point? – jtahlborn Jun 21 '23 at 18:28

2 Answers2

0

The OP commented that as far as they knew the font is embedded

The PDF is generated by SAP and stored in a content server. You can access to the file via url and checking the document properties, the font is embedded. The issue appears when I recover the pdf's stream, the font is not included.

The reason a font will no longer be seen as embeded at a PDF receiver, is that it can be highly likely that during transportation the files binary content was modified.

On its own, cleanly converting binary into base64 and clean out again should never alter the files content. However several problem can arise since that method involves extra points of failure, compared with simply offering <a href="download.pdf"> which is usually 95+% reliable but can also be multiple points of failure.

The most common failing in base64 is using any other encoding at either end (outside of the string streaming). Thus commonly using string functions before or after will almost certainly destroy fonts and or images as they are binary single byte streams within the binary.PDF

K J
  • 8,045
  • 3
  • 14
  • 36
-1

This may happens if the font was not embeded in the PDF during creation, and you do not have the same exact font on the system where you open the pdf.

Is the pdf generated using itext ? in this case, this answer could help you. otherwise, try putting the font in your system font directory.

Edit : as for the second question, there is a small demo program to embed a font in an existing pdf file where the font is not embeded here

Community
  • 1
  • 1
PATRY Guillaume
  • 4,287
  • 1
  • 32
  • 41
  • The PDF is generated by SAP and stored in a content server. You can access to the file via url and checking the document properties, the font is embedded. The issue appears when I recover the pdf's stream, the font is not included. – user2553834 Jul 08 '13 at 07:51
  • 1
    how do you generate the PDF ? smartform-to-pdf module function ? – PATRY Guillaume Jul 10 '13 at 08:20