Closed
Compress File PDF with Acitivity
How to Compress File PDF with acitivity?
***Edited by Moderator Marije to add Capability tags***
To see attachments, please log in.
This content is closed to future replies and is no longer being maintained or updated.
Links may no longer function. If you have a similar request, please write a new post.
How to Compress File PDF with acitivity?
Use java method in activity to create zip file, this is sample
// Prepare a date-time stamp for the file name to ensure it is unique
java.util.Date today = new java.util.Date();
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String datenewformat = formatter.format(today);
int BUFFER = 2048;
// Prepare the filename
String exportFileName = tools.getParamValue("FileName");
if (exportFileName.indexOf(".") < 0)
{
// Append the date and .zip. If an extension is specified, it overrides this.
exportFileName += ".zip";
}
// Prepare the temp directory path for saving
char sep = PRFile.separatorChar;
String sRulesMovePathName = tools.getProperty("pxProcess.pxServiceExportPath").getStringValue();
if (sRulesMovePathName.charAt(sRulesMovePathName.length() - 1) == sep)
{
sRulesMovePathName = sRulesMovePathName.substring(0, sRulesMovePathName.length() - 1);
}
String targetDir = sRulesMovePathName + "/";
//Prepare csv file
String csvFileName = sRulesMovePathName + sep + FileName;
int lenRead = 0;
byte[] buf = new byte[1024];
// Prepare the zip file
PRFile targetZipFile = null;
if( targetDir.length() > 0 )
{
targetZipFile = new PRFile(targetDir);
((PRFile) targetZipFile).mkdirs();
}
// Create the ZIP file
try
{
targetZipFile = new PRFile(new PRFile(targetDir), exportFileName);
java.util.zip.ZipOutputStream zoutLocal = new java.util.zip.ZipOutputStream(new PROutputStream(((PRFile) targetZipFile)));
// Aquire the output stream
java.util.zip.ZipOutputStream zout = (java.util.zip.ZipOutputStream) zoutLocal;
// Create the file in the zip archive
zout.putNextEntry(new java.util.zip.ZipEntry(FileName));
// Write the csv
PRFile csvFile = new PRFile(csvFileName);
PRInputStream fileIn = new PRInputStream(csvFile);
while((lenRead = fileIn.read(buf)) > 0) {
zout.write(buf,0, lenRead);
}
// Close the file
zout.closeEntry();
fileIn.close();
zout.close();
FileName = exportFileName;
}
catch (java.io.IOException ioe)
{
// Should really set error messages on a property/page here rather than using oLog.infoForce(...).
// Should really just abort processing here after reporting the error since if we cannot create the zip file we're totally done.
oLog.infoForced("Exception encountered creating zip output file/stream: " + ioe.toString());
StackTraceElement[] trace = ioe.getStackTrace();
for(int i = 0; i < trace.length; i++)
{
oLog.infoForced(trace[i].toString());
}
}
Question
Question
Discussion
Question Solved
Question
Question
Question
Question
Discussion
Discussion
Pega Collaboration Center has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.