× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




Hello, 

I have a working Java class converting tiff to PDF. working on different systems including some IBM i lpars. 
On one LPAR the program crashes with a 'no such device' error... at com.itextpdf.text.io.FileChannelRandomAccessSource

the only difference is that the lpar is used in Poland by polish users and is configured with CCSID 870. 
I have tried to change locale, job ccsid, lang, ... but no success.. 

any idea ? 

Paul 


minimum working generally /notworking on 1 LPAR source attached

// 

import java.io.File;
import java.io.FileOutputStream;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

import com.itextpdf.text.Document;
import com.itextpdf.text.Image;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.io.FileChannelRandomAccessSource;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.RandomAccessFileOrArray;
import com.itextpdf.text.pdf.codec.TiffImage;


public class Tif2Pdf {

     public static void main(String[] args)  {
         String inputFileName  = args[0];
         String outputFileName = args[1];
         try{
             generatePdf(inputFileName , outputFileName);
             } catch (Exception e) {
                 e.printStackTrace( );
                 System.out.println(e.getMessage()+" / " +e);
                 }

     }
     private static void generatePdf(String pstrSrcFile, String 
pstrDestFile) throws Exception {

         Document document = null;
         RandomAccessFileOrArray ra = null;
         PdfCopy lobjWriter = null;
         Document lobjDocument = null;

         RandomAccessFile raFile = null;
         FileChannelRandomAccessSource fcra = null;

         try {
             raFile = new RandomAccessFile(pstrSrcFile, "r");
             FileChannel fChannel = raFile.getChannel();
             System.out.println(pstrSrcFile + " being processed for " + 
fChannel.size() + " bytes." );
             fcra =  new FileChannelRandomAccessSource(fChannel);

             File pdfFile = new File(pstrDestFile);
             Rectangle lobjPageRectangle = PageSize.A4;
             document = new Document(lobjPageRectangle);
             PdfWriter writer = PdfWriter.getInstance(document, new 
FileOutputStream(pdfFile));
             document.open();
             PdfContentByte cb = writer.getDirectContent();
             int pageCount = 0;
             ra = new RandomAccessFileOrArray(fcra);
             pageCount = TiffImage.getNumberOfPages(ra);
             System.out.println("processing " + pageCount + " page(s) 
to" + pstrDestFile);
             for (int page = 0; page < pageCount; ++page) {
                 ra = new RandomAccessFileOrArray(fcra);
                 Image img = TiffImage.getTiffImage(ra, page + 1);
                 if (img != null) {
                     if (img.getScaledWidth() > lobjPageRectangle.getWidth()
                             || img.getScaledHeight() > lobjPageRectangle
                             .getHeight()) {
  img.scaleToFit(lobjPageRectangle.getWidth(),
                                 lobjPageRectangle.getHeight());
                     }
                     img.setAbsolutePosition(0, 0);
                     cb.addImage(img);
                     document.newPage();
                 }
             }
         } catch (Exception e) {

             e.printStackTrace( );
             System.out.println(e.getMessage());
             if (document != null) {
                 document.close();
             }

             System.out.println(e.getMessage()+e);
         } finally {
             try {
                 if (lobjDocument != null) {
                     lobjDocument.close();
                 }
                 if (lobjWriter != null) {
                     lobjWriter.close();
                 }
                 if (ra != null) {
                     ra.close();
                 }
                 if (document != null) {
                     document.close();
                 }

             } catch (Exception e) {
                 e.printStackTrace( );
                 System.out.println(e.getMessage()+e);
             }
         }
     }

}

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.