z / OS上的JZOS和iText

时间:2015-01-01 06:47:28

标签: itext

我正在尝试使用JZOS和iText在z / OS上创建PDF。

我为字体和DefaultPlatformEncoding尝试了很多组合,但我似乎无法在PDF中显示阿拉伯字符。它们显示为拉丁字符。当我关闭PDF压缩并显示十六进制字符时,我看到了EBCDIC十六进制代码。

z / OS上的输入文件是IBM-420,输出PDF应该有Cp1256或Windows-1256以便在Windows上显示。

以下是代码片段:

// Open the input dataset
ZFile zFilein = new ZFile("//DD:INDS", "rb,type=record,noseek");
// Open the output PDF file
PdfWriter writer = PdfWriter.getInstance(document,
    FileFactory.newBufferedOutputStream("//DD:OUTPDF"));
document.open();
//  Font cf = new Font(Font.FontFamily.COURIER, Font.DEFAULTSIZE, Font.NORMAL);
//  Font cf = FontFactory.getFont("Courier","Cp1256", true);
Font cf = FontFactory.getFont("Arial", BaseFont.IDENTITY_H, true, Font.DEFAULTSIZE, Font.NORMAL);
Paragraph paragraph = new Paragraph();
paragraph.setFont(cf);
String encoding = ZUtil.getDefaultPlatformEncoding();
// String encoding = "Cp1256";
String line = new String(recBuf,1,nRead-1,encoding);
paragraph.add(line);

我尝试了以下选项,但仍无法正确显示PDF PDF字体信息不会将字体显示为EMBEDDED。我错过了什么?

注意:arial.ttf是从WINDOWS上传的

选项1

FontFactory.register(" ARIAL.TTF&#34);
字体cf = FontFactory.getFont(" Arial",8);

段落=新段落(line,cf);

PDF中的FONT信息显示以下内容:

ArialMT             类型:TrueType             编码:安西             实际字体:ArialMT             实际字体类型:TrueType

Option 2

BaseFont bf = BaseFont.createFont(font1, BaseFont.IDENTITY_H, true);     
Font cf = new Font(bf, 10);           
paragraph = new Paragraph(line, cf);   

Viewing the PDF display the following error:
Cannot extract the embedded font 'ZQRNLC+ArialMT'. Some characters may not display or 
print correctly.

Viewing the source of the PDF in an editor I can see the following:
R/FontName/ZQRNLC+ArialMT/         

The FONT in the PDF displays the following information:

ArialMT
            Type: TrueType(CID)
            Encoding: Identity-H
            Actual Font: Unknown

1 个答案:

答案 0 :(得分:0)

您的问题与其他几个问题重复。

这行代码可能有问题:

Font cf = FontFactory.getFont("Arial", BaseFont.IDENTITY_H, true, Font.DEFAULTSIZE, Font.NORMAL);

除非您按照我对问题的回答中的说明注册了Arial字体程序,否则不会提供字体Arial “Why doesn't FontFactory.GetFont("Known Font Name", floatSize) work?

我不知道z / OS(从未听说过),但是如果它使用EBCDIC,它就会出错。你的字符串需要在UNICODE中。正如我对问题“getBytes() doesn't work for Cyrillic letters”的回答中所解释的那样,您使用的String值采用正确的编码非常重要。在您的情况下,您正在从文件中读取内容,但不能保证您用于读取文件的编码与用于存储文件的编码相匹配。当你说这些字形显示在EBCDIC中时,我认为你错了,你遇到了与“getBytes() doesn't work for Cyrillic letters”中解释的相同的问题。你真的需要Unicode。

你说你想用阿拉伯语创建文本,但我没有看到你在任何地方使用RTL设置。我在回答这个问题时解释了这一点:“how to create persian content in pdf using eclipse”。

请下载免费的电子书"The Best iText Questions on StackOverflow",您会发现所有这些问题都已被提及并且之前得到了解答。我想将您的问题作为how to create persian content in pdf using eclipse的副本关闭,但不幸的是,该答案未被接受且未收到upvote,因此不能将其用作标记其他问题的原始问题作为副本。