You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Roberto Nibali <rn...@gmail.com> on 2015/07/24 10:27:40 UTC

PDFBox 2.0 SVN Head: PDStream discontinued

Hi

Until last week, the following code worked just fine:

public static String calculateFontSize(PDTextField field) throws IOException {
    PDFStreamParser parser = new PDFStreamParser(new
RandomAccessBuffer(field.getDefaultAppearance().getBytes()));
    parser.parse();
    final List<Object> tokens = parser.getTokens();
    int setFontOperatorIndex = tokens.indexOf(Operator.getOperator("Tf"));
    Integer fontSize = ((COSNumber) tokens.get(setFontOperatorIndex -
1)).intValue();
    /* This specifies that the text appearing on the button by default
should be Courier
       8pts in size or the original size, and the color of the text is
black (0 g = 0 setgray)
     */
    return "/Cour " + (fontSize == 0 ? 8 : fontSize) + " Tf 0 g";
}

Could someone maybe help me out with how the new code should be structured?
The following line:

    PDFStreamParser parser = new PDFStreamParser(new
RandomAccessBuffer(field.getDefaultAppearance().getBytes()));

does not compile anymore. The simple solution is a cast:

    PDFStreamParser parser = new PDFStreamParser((PDContentStream) new
RandomAccessBuffer(field.getDefaultAppearance().getBytes()));

Is this the correct approach? It looks overly twisted.

Thanks and best regards

Roberto

Re: PDFBox 2.0 SVN Head: PDStream discontinued

Posted by Roberto Nibali <rn...@gmail.com>.
Hi

On Fri, Jul 24, 2015 at 4:44 PM, Tilman Hausherr <TH...@t-online.de>
wrote:

Am 24.07.2015 um 10:27 schrieb Roberto Nibali:
>
>> Hi
>>
>> Until last week, the following code worked just fine:
>>
>> public static String calculateFontSize(PDTextField field) throws
>> IOException {
>>      PDFStreamParser parser = new PDFStreamParser(new
>> RandomAccessBuffer(field.getDefaultAppearance().getBytes()));
>>      parser.parse();
>>      final List<Object> tokens = parser.getTokens();
>>      int setFontOperatorIndex =
>> tokens.indexOf(Operator.getOperator("Tf"));
>>      Integer fontSize = ((COSNumber) tokens.get(setFontOperatorIndex -
>> 1)).intValue();
>>      /* This specifies that the text appearing on the button by default
>> should be Courier
>>         8pts in size or the original size, and the color of the text is
>> black (0 g = 0 setgray)
>>       */
>>      return "/Cour " + (fontSize == 0 ? 8 : fontSize) + " Tf 0 g";
>> }
>>
>> Could someone maybe help me out with how the new code should be
>> structured?
>> The following line:
>>
>>      PDFStreamParser parser = new PDFStreamParser(new
>> RandomAccessBuffer(field.getDefaultAppearance().getBytes()));
>>
>> does not compile anymore. The simple solution is a cast:
>>
>>      PDFStreamParser parser = new PDFStreamParser((PDContentStream) new
>> RandomAccessBuffer(field.getDefaultAppearance().getBytes()));
>>
>> Is this the correct approach? It looks overly twisted.
>>
>
> Because it could be simpler:
>
> PDFStreamParser parser = new
> PDFStreamParser(field.getDefaultAppearance().getBytes()));
>
>
D'oh, thanks! I'll try to engage my brain a wee bit more next time.

Best regards
Roberto

Re: PDFBox 2.0 SVN Head: PDStream discontinued

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 24.07.2015 um 10:27 schrieb Roberto Nibali:
> Hi
>
> Until last week, the following code worked just fine:
>
> public static String calculateFontSize(PDTextField field) throws IOException {
>      PDFStreamParser parser = new PDFStreamParser(new
> RandomAccessBuffer(field.getDefaultAppearance().getBytes()));
>      parser.parse();
>      final List<Object> tokens = parser.getTokens();
>      int setFontOperatorIndex = tokens.indexOf(Operator.getOperator("Tf"));
>      Integer fontSize = ((COSNumber) tokens.get(setFontOperatorIndex -
> 1)).intValue();
>      /* This specifies that the text appearing on the button by default
> should be Courier
>         8pts in size or the original size, and the color of the text is
> black (0 g = 0 setgray)
>       */
>      return "/Cour " + (fontSize == 0 ? 8 : fontSize) + " Tf 0 g";
> }
>
> Could someone maybe help me out with how the new code should be structured?
> The following line:
>
>      PDFStreamParser parser = new PDFStreamParser(new
> RandomAccessBuffer(field.getDefaultAppearance().getBytes()));
>
> does not compile anymore. The simple solution is a cast:
>
>      PDFStreamParser parser = new PDFStreamParser((PDContentStream) new
> RandomAccessBuffer(field.getDefaultAppearance().getBytes()));
>
> Is this the correct approach? It looks overly twisted.

Because it could be simpler:

PDFStreamParser parser = new 
PDFStreamParser(field.getDefaultAppearance().getBytes()));


Tilman
>
> Thanks and best regards
>
> Roberto
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org