2015-01-01 25 views
1

我正嘗試使用JZOS和iText在z/OS上創建PDF。z/OS上的JZOS和iText

我已經嘗試瞭如此多的字體以及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字體信息不顯示的字體嵌入。還有什麼我錯過了?

注:ARIAL.TTF從WINDOWS

選項1個

FontFactory.register( 「ARIAL.TTF」)上傳;
Font cf = FontFactory.getFont(「Arial」,8);

paragraph = new Paragraph(line,cf);

在PDF的字體信息顯示如下:

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 
+0

[如何使用eclipse在pdf中創建波斯語內容](http://stackoverflow.com/questions/26818555/how-to-create-persian-content-in-pdf-using-eclipse) –

+0

PDF中字體的「未知」是由於輸出PDF中的錯誤,這與iText無關。 – user1579878

回答

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的一個副本來結束,但不幸的是,該答案未被接受,並且沒有收到優惠,所以它不能被用作將另一個問題標記爲重複的原始問題。