Topic
  • 3 replies
  • Latest Post - ‏2013-02-16T07:21:08Z by SystemAdmin
Ravi_Hariharan
Ravi_Hariharan
3 Posts

Pinned topic SpoolFile to PDF

‏2012-03-09T18:52:41Z |
I able to retive a spool file in txt format. but i am not able to get it in PDF format. can someone pls help me.

what am i missing??? iseries is IBM iV6R1.

printParameterList.setParameter( PrintObject.ATTR_WORKSTATION_CUST_OBJECT, 
"/QSYS.LIB/QCTXPDF.WSCST"); printParameterList.setParameter(PrintObject.ATTR_MFGTYPE, 
"*WSCST"); printParameterList.setParameter(PrintObject.ATTR_MFGTYPE, 
"*WSCST"); printParameterList.setParameter(PrintObject.ATTR_AFP, 
"*YES"); printParameterList.setParameter(PrintObject.ATTR_DEVTYPE , 
"*AFPDS");




package com.lntinfotech.unitrax.spoolfile;   

import java.io.FileOutputStream; 

import java.io.InputStream; 

import java.io.OutputStream; 

import java.util.Date; 

import java.util.Enumeration;   

import com.ibm.as400.access.AS400; 

import com.ibm.as400.access.PrintObject; 

import com.ibm.as400.access.PrintParameterList; 

import com.ibm.as400.access.SpooledFile; 

import com.ibm.as400.access.Trace; 

import com.ibm.as400.access.list.SpooledFileListItem; 

import com.ibm.as400.access.list.SpooledFileOpenList;   

public 

class SpoolFile 
{   

public 

static 

void main(String[] args) 
{   

try 
{ 

int count = 0;   

byte[] buf = 

new 

byte[2048]; 

int bytesRead; 
// AS400 as400Con = new AS400("TESTING.AGF.CA", 
// "SQAACCJZZ","SQAACCJZZ"); AS400 as400Con = 

new AS400(
"DEVSQA", 
"111", 
"111"); Trace.setTraceOn(

true);   System.out.println(

new Date(as400Con.getPreviousSignonDate() .getTimeInMillis()));   SpooledFileOpenList spooledFileOpenList = 

new SpooledFileOpenList( as400Con); spooledFileOpenList.setFilterUsers(

new String[] 
{ 
"DVPR02DJRH" 
}); spooledFileOpenList.addSortField(SpooledFileOpenList.JOB_NUMBER, 

true); spooledFileOpenList.open();   Enumeration<?> spooledFiles = spooledFileOpenList.getItems(); 
// The Code is currently written to read all spool file for a user. 
// we can read one spool file 
// at a time by just creating a spoolfile using name , number , job 
// name , job user and job number 

while (spooledFiles.hasMoreElements()) 
{ 

if (count++ < 5) 
{ SpooledFileListItem spooledFileListItem = (SpooledFileListItem) spooledFiles .nextElement(); System.out.println(spooledFileListItem.getName()); System.out.println(spooledFileListItem.getNumber());   System.out.println(spooledFileListItem.getJobName()); System.out.println(spooledFileListItem.getJobUser()); System.out.println(spooledFileListItem.getJobNumber()); System.out.println(
"----------------");   String fileName = spooledFileListItem.getName() + 
"_" + spooledFileListItem.getJobName() + 
"_" + spooledFileListItem.getJobNumber();   SpooledFile spooledFile = 

new SpooledFile(as400Con, 
// AS400 spooledFileListItem.getName(), 
// splf name spooledFileListItem.getNumber(), 
// splf number spooledFileListItem.getJobName(), 
// job name spooledFileListItem.getJobUser(), 
// job user spooledFileListItem.getJobNumber()); 
// job number   
/******************************************************** * Set up a print parameter list that specifies what a * spooled file should be transformed into. * * Use QWPDEFAULT ("text only") to get a text stream ********************************************************/ PrintParameterList printParameterList = 

new PrintParameterList(); 
//printParameterList.setParameter(PrintObject.ATTR_MFGTYPE,"*WSCST"); 
//printParameterList.setParameter(PrintObject.ATTR_WORKSTATION_CUST_OBJECT,"/QSYS.LIB/QWPDEFAULT.WSCST");   
// The OS version should be greater than 7.1 and 5770TS1 
// should be installed printParameterList.setParameter( PrintObject.ATTR_WORKSTATION_CUST_OBJECT, 
"/QSYS.LIB/QCTXPDF.WSCST"); printParameterList.setParameter(PrintObject.ATTR_MFGTYPE, 
"*WSCST"); printParameterList.setParameter(PrintObject.ATTR_MFGTYPE, 
"*WSCST"); printParameterList.setParameter(PrintObject.ATTR_AFP, 
"*YES"); printParameterList.setParameter(PrintObject.ATTR_DEVTYPE , 
"*AFPDS"); 
// open the spooled file for reading and get the input 
// stream to 
// read from it. InputStream in = spooledFile .getTransformedInputStream(printParameterList); OutputStream os = 

new FileOutputStream(
"c:/spool/" + fileName + 
".txt");
// System.out;// 

do 
{ 
// read up to buf.length bytes of raw spool data into 
// our buffer. The actual bytes read will be returned. 
// The data will be a binary printer data stream that is 
// the 
// contents of the spooled file. bytesRead = in.read(buf); 

if (bytesRead != -1) 
{ 
// process the spooled file data. System.out.println(
"Read " + bytesRead + 
" bytes");   

int numRead; 

while ((numRead = in.read(buf)) >= 0) 
{ os.write(buf, 0, numRead); 
} 
} 
} 

while (bytesRead != -1);   in.close(); 
} 

else 
{ 

break; 
} 
} 
} 

catch (Exception e) 
{ e.printStackTrace(System.out); 
}   System.out.println(); 
} 
}
Updated on 2013-02-16T07:21:08Z at 2013-02-16T07:21:08Z by SystemAdmin
  • Ravi_Hariharan
    Ravi_Hariharan
    3 Posts

    Re: SpoolFile to PDF

    ‏2012-12-07T14:40:53Z  
    
    
    
    import java.io.FileOutputStream; 
    
    import java.util.Date; 
    
    import java.util.Enumeration;   
    
    import com.ibm.as400.access.AS400; 
    
    import com.ibm.as400.access.PrintObject; 
    
    import com.ibm.as400.access.PrintObjectTransformedInputStream; 
    
    import com.ibm.as400.access.PrintParameterList; 
    
    import com.ibm.as400.access.SpooledFile; 
    
    import com.ibm.as400.access.list.SpooledFileListItem; 
    
    import com.ibm.as400.access.list.SpooledFileOpenList;   
    
    public 
    
    class SpooledFileToPDFExample 
    {   
    
    private 
    
    static String location = 
    "C:/workspace/POC/JavaPOCCode/result/";   
    
    public 
    
    static 
    
    void main(String[] args) 
    { FileOutputStream fileoutputstream = 
    
    null; 
    
    try 
    { 
    
    int count = 0;   
    // AS400 as400Con = new AS400("TESTING.AGF.CA", 
    // "SQAACCJZZ","SQAACCJZZ"); AS400 as400Con = 
    
    new AS400(
    "NEWREL", 
    "RAVIH", 
    "RAVIH"); as400Con.setGuiAvailable(
    
    false);   System.out.println(
    
    new Date(as400Con.getPreviousSignonDate() .getTimeInMillis()));   System.out.println(
    "getVersion :: " + as400Con.getVersion()); System.out.println(
    "getVersion :: " + as400Con.getVersion());   SpooledFileOpenList spooledFileOpenList = 
    
    new SpooledFileOpenList( as400Con);   
    // spooledFileOpenList.setFilterJobInformation("JOBACCRORP", 
    // "SQAACCS1RH", "584373"); spooledFileOpenList.setFilterUsers(
    
    new String[] 
    { 
    "RAVIH" 
    }); spooledFileOpenList.addSortField(SpooledFileOpenList.JOB_NUMBER, 
    
    true);   spooledFileOpenList.open();   Enumeration<?> spooledFiles = spooledFileOpenList.getItems();   
    // The Code is currently written to read all spool file for a user. 
    // we can read one spool file 
    // at a time by just creating a spoolfile using name , number , job 
    // name , job user and job number   
    
    while (spooledFiles.hasMoreElements()) 
    {   SpooledFileListItem spooledFileListItem = (SpooledFileListItem) spooledFiles .nextElement(); System.out.println(spooledFileListItem.getName()); System.out.println(spooledFileListItem.getNumber());   System.out.println(spooledFileListItem.getJobName()); System.out.println(spooledFileListItem.getJobUser()); System.out.println(spooledFileListItem.getJobNumber()); System.out.println(
    "----------------");   String fileName = location + spooledFileListItem.getName() + 
    "_" + spooledFileListItem.getJobName() + 
    "_" + spooledFileListItem.getJobNumber() + 
    ".pdf";   SpooledFile spooledFile = 
    
    new SpooledFile(as400Con, 
    // AS400 spooledFileListItem.getName(), 
    // splf name spooledFileListItem.getNumber(), 
    // splf number spooledFileListItem.getJobName(), 
    // job name spooledFileListItem.getJobUser(), 
    // job user spooledFileListItem.getJobNumber()); 
    // job number PrintParameterList plist = 
    
    new PrintParameterList();   plist.setParameter(PrintObject.ATTR_WORKSTATION_CUST_OBJECT, 
    "/QSYS.LIB/QCTXPDF.WSCST"); plist.setParameter(PrintObject.ATTR_MFGTYPE, 
    "*WSCST"); PrintObjectTransformedInputStream pdfInStream = spooledFile .getTransformedInputStream(plist); 
    
    if (pdfInStream != 
    
    null) 
    { 
    
    byte[] buffer = 
    
    new 
    
    byte[64 * 1024]; fileoutputstream = 
    
    new FileOutputStream(fileName); 
    
    int bytesRead = 0; 
    
    while ((bytesRead = pdfInStream.read(buffer)) != -1) 
    { fileoutputstream.write(buffer, 0, bytesRead); 
    } fileoutputstream.close(); pdfInStream.close(); 
    } 
    }   
    } 
    
    catch (Exception e) 
    { e.printStackTrace(System.out); 
    }   System.out.println(); 
    } 
    }
    


    The code works for IBMi7. :)
  • Ravi_Hariharan
    Ravi_Hariharan
    3 Posts

    Re: SpoolFile to PDF

    ‏2012-12-07T14:41:07Z  
    Done
  • SystemAdmin
    SystemAdmin
    4895 Posts

    Re: SpoolFile to PDF

    ‏2013-02-16T07:21:08Z  
    Done
    Thanks for your post.
    If you need a iphone case, please visit here: http://www.stylishiphonecase.net/crocodile-embossed-protective-leather-iphone5-case-p-53.html.