on 11-09-2006 4:18 PM
Hi all,
I want to display a pdf file in interactive form. The property pdfSource is bind to a context element of the same name. When I am trying to run my app I get a message that file was corrupted. I think that the problem is with the conversion string to byte[]. I am not very familiar with java so can you help me? Here is my code:
File file = new File("report.pdf");
FileReader fileReader = new FileReader(file);
BufferedReader bufferReader = new BufferedReader(fileReader);
String string = "", line = "";
while ((line = (String) bufferReader.readLine()) != null) string += line;
byte[] bytes = string.getBytes();
wdContext.currentContextElement().setPdfSource(bytes);
Thank you
Ivo
PDF isn't a normal TEXT file.
It is a binary file!
Your error is
BufferedReader bufferReader = new BufferedReader(fileReader);
String string = "", line = "";
while ((line = (String) bufferReader.readLine()) != null) string += line;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
// Returns the contents of the file in a byte array.
public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
// File is too large
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
// Close the input stream and return bytes
is.close();
return bytes;
}
Hi Ivo,
is your application running on NW04 or NW04s? In both cases you can use the InteractiveForm UI element to display a <i>non-interactive</i> PDF resource in it by setting the mode property to USE_PDF. I described a solution, based on using a Modifiable Binary Type" (NW04) in this thread:
Regards, Bertram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Let me know what your expecting to do ?
U are mapping only context node as pdfsource binary type.
can you brief me your requirement again.
Thanks
Lohi.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.