I am preparing a program in RPGLE that will use Java function returning fancy PDF file. I want to take that PDF in RPGLE and create a PDF file on IFS.

For now the Java program returns the PDF in byte[] format. Than I take the byte [] as char in RPG and I try to create stream file out of it. But the PDF is damaged and I can't open it via Adobe Reader...

Below is the prototype of Java procedure and code creating stream file:

D GetPDF PR A ExtProc(*Java:'PDF':'get') Len(16773100) CCSID(*HEX) Dcl-S wkPDFTxt Char(16773100) CCSID(*HEX); wkPDFTxt = GetPDF(); fd = open(filePath :O_CREAT + O_EXCL + O_WRONLY + O_CCSID + O_INHERITMODE :S_IRUSR :65535); write(fd: %addr(wkPDFTxt): %Len(%Trim(wkPDFTxt)); close(fd) 

Anyone is familiar with PDF creation and could help me how can I achieve this? I thought that taking byte [] as char() and writing it to stream file in UTF8 would work but it doesn't.

2

3 Answers

I found the open/write/close functions. They are UNIX-type integrated file system APIs.

The CCSID when the file already exists is the file CCSID. The CCSID specified in the parameters is simply the CCSID that the file is created with. It should be either 1208 (UTF-8) or 819 (ASCII), even though PDF is a binary format. Maybe you should use 819 because that appears to be what you are getting from the Java method.

NO CONVERSION IS PERFORMED. according to the documentation

If O_TEXTDATA is not specified, the data is processed as binary. The data is read from the file and written to the file without any conversion. The application is responsible for handling the data.

You must make sure the data is in the required format. The docs are a bit confusing because that fourth parameter is called conversion ID and the docs say

The specified or derived CCSID is assumed to be the CCSID of the data in the file, when a new file is created. This CCSID is associated with the file during file creation.

The punctuation could be wrong. To line up with the rest of the document, it should be

The specified or derived CCSID is assumed to be the CCSID of the data in the file. When a new file is created, this CCSID is associated with the file during file creation.

In any case, you do not have O_TEXTDATA (and you shouldn't) so since the source CCSID looks like it is 819 (this is normal for a windows file in the US) you should make the CCSID 819 and just write the data the way you got it.

1

Probably an encoding problem... wkPDFTxt is char() so EBCDIC. If you are >= V7R2 you can force UTF8 for this variable , by adding to the declaration:

Dcl-S wkPDFTxt Char(16773100) CCSID(*UTF8);

Would it be possible to write the stream on the java side , and compare in hexadecimal with the RPG file ?

3

If you're dealing with binary objects like PDF, CCSID(65535) aka CCSID(*HEX) would seem to be more appropriate.

I'd add that to the PR and to the declaration of wkPDFTxt though wkPDFbuffer would be a more appropriate name.

Also, when you open the stream file, you'll want to use 65535 instead of 1208.

Lastly, your PR for the Java method looks a little suspect, it'd might be helpful to see the signature of the Java method you're calling to ensure it's been done correctly.

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.