[ 
https://issues.apache.org/jira/browse/PDFBOX-2838?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18073710#comment-18073710
 ] 

Stefan Ziegler commented on PDFBOX-2838:
----------------------------------------

{{PDPageContentStream.appendRawCommands()}} is {{@Deprecated}} but no viable 
replacement exists for raw byte-level text output (Type 3 fonts, raw-GID 
{{{}Tj{}}}, custom-encoded fonts)

We are building a PostScript-to-PDF converter on top of PDFBox 3.x. In three 
distinct situations we are forced to call 
{{contentStream.appendRawCommands(String)}} because no supported public API in 
{{PDAbstractContentStream}} / {{PDPageContentStream}} can do what is needed. 
The method is marked {{@Deprecated}} with the only Javadoc justification being 
_"Usage of this method is discouraged"_ — with no suggested alternative.

 

*Use Case 1 — Raw GID {{Tj}} for CIDFont / Type 0 fonts*
{code:java}
contentStream.appendRawCommands(String.format("<%04X> Tj\n", gid));{code}
 

When a PostScript font is mapped to a PDType0Font backed by a CIDFont, the 
character selector in the PDF content stream must be a 2-byte hex string 
referring to the glyph ID directly (e.g. <0041> Tj). The showText(String) path 
in PDAbstractContentStream.showTextInternal() calls font.encode(text), which 
goes through Unicode-based encoding lookup. We already know the GID; there is 
no public API to write a pre-encoded byte sequence as a Tj operand without 
going through the Unicode→encoding round-trip.

 

*Use Case 2 — Type 3 font rendering*
{code:java}
// renderType3String() and op_show() for Type3 fonts:{code}
{code:java}
contentStream.appendRawCommands(hex.toString()); // e.g. "<41> Tj\n"{code}

> Please make PDPageContentStream non-final
> -----------------------------------------
>
>                 Key: PDFBOX-2838
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2838
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: PDModel
>    Affects Versions: 2.0.0
>            Reporter: Philip Helger
>            Assignee: John Hewson
>            Priority: Major
>             Fix For: 2.0.0
>
>         Attachments: PDPageContentStreamWithCache.java
>
>
> Please make PDPageContentStream non-final as in certain cases it might be 
> helpful to cache the last set data on an PDPageContentStream (such as the 
> last used Font) to avoid bloating the created PDF. Therefore the methods must 
> be overridable.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to