JZOS PDF encoding

General discussion on the JZOS batch launcher and toolkit
Post Reply
tsdjim
Posts: 64
Joined: Fri May 07, 2010 2:21 am

JZOS PDF encoding

Post by tsdjim »

I am writing a Java program to create a PDF with arabic and using the arial font. The input is in Cp420 The output should be in UTF-8, however I am not getting the correct output encoding, when I display the PDF in hex it does not shows UTF-8 characters for the data. I also have problems with the font. I am suspecting that the problems may relate to the encoding. Also what effect does -Dfile.encoding have on the input/output encoding?

The following are the two options I have tried.
Option 1

ZFile zFilein = new ZFile
("//DD:INDS", "rb,type=record,noseek");
String font1 = "/usr/lpp/java/J6.0.1/lib/fonts/arial.ttf";
BaseFont bf = BaseFont.createFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf, 12);
// Open the output PDF file
PdfWriter writer = PdfWriter.getInstance
(document,
FileFactory.newBufferedOutputStream("//DD:OUTPDF"));
Paragraph paragraph = new Paragraph();
paragraph.setFont(font);
while((nRead = zFilein.read(recBuf)) != -1) ؛
String line = new String(recBuf, 1, nRead-1,encoding);

Option 2

ZFile inZFile = new ZFile("//DD:INDS", "rb,type=record,noseek");
ZFile outZFile = new ZFile("//DD:OUTPDF", "wt");
String font1 = "/usr/lpp/java/J6.0.1/lib/fonts/arial.ttf";
BaseFont bf = BaseFont.createFont(font1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = FontFactory.getFont("arial", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
InputStream istream = inZFile.getInputStream();
InputStreamReader rdr = new InputStreamReader(istream,"Cp420");
brdr = new BufferedReader(rdr);
OutputStream ostream = outZFile.getOutputStream();
PdfWriter writer = PdfWriter.getInstance
(document, ostream);
while ((line = brdr.readLine()) != null) ؛

Displaying the resultant PDF gives an error 'cannot extract the embedded font 'XGFH+ArialMT some characters may no display correctly'. The font description shows.

Type truetype
Encoding IDENTITY-H
Actual Font: Unknown
Actual Font type: TrueType (CID)
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Re: JZOS PDF encoding

Post by dovetail »

PDFs are binary, therefore you should not use text mode output to a DD. Doing so will cause "newline" characters to be inserted.

I can't say whether the actual data is being written in the correct codepage - that is up to your Java PDF generator. But, as far as the JZOS ZFile class is concerned, the output is binary.

FileFactory.newBufferedOutputStream() will open as text

new ZFile("//DD:OUTPDF", "wt") will also open as text.

try:

new ZFile("//DD:OUTPDF", "wb")

(also, you will want the DD to probably be something like RECFM=U,BLKSIZE=27998 - it is a stream of binary bytes where record/block boundaries are not significant).
tsdjim
Posts: 64
Joined: Fri May 07, 2010 2:21 am

Re: JZOS PDF encoding

Post by tsdjim »

Thanks a lot. The 'wb' on the 'new ZFile' solved all the problems.
Post Reply