Hi Tech-support friends.
I had created a short version of my program to demonstrate that activating the two licenses for PDF and BARCODE in the same program some how “It does Not Work” and i am getting an error which i will show below. Just remember that i am trying to create a PDF document which must contain a Bar-code at the bottom.
I am sorry if my program still is a little long but i hope you can TEST why i am getting Error when creating a barcode.
Also this is my configuration: am using Eclipse - IBM Rational Developer for i (AS400)
JRE 8, JDK 8.
I develop my Java programs on a PC with windows-7 PRO
after i compile my java programs into a JAR file, I move it to the IBM AS400 IFS which is similar to unix and I run the program there:
Symptoms: 1. when i run the program on the PC it runs GOOD, i get the PDF document and the barcode is there (all good here).
Symptoms: 2. when i run the program on the AS400 and i don’t print Barcode it runs GOOD, i get the PDF document. (all good here)
Symptoms: 3. when i run the program on the AS400 and print the Barcode, i am getting the error below: (NO-GOOD HERE)
java.lang.Exception: Failed to set license. Details: Cannot find license ‘Aspose.Total.Java.lic’.
Please Help. . . .
========= My Program =======================================================
package rr.formpdf;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.aspose.barcode.BarCodeImageFormat;
import com.aspose.barcode.generation.BarCodeGenerator;
import com.aspose.pdf.Document;
import com.aspose.pdf.Field;
import com.aspose.pdf.ImageStamp;
import com.aspose.pdf.TextBoxField;
public class FormPDFfill {
static TextBoxField textBoxField = null;
static Date sysDate = new Date();
static DateFormat dtFmt = new SimpleDateFormat("yyMMdd-HHmm");
static String pathSeparator;
static Path currentRelativePath;
static String pgmPath;
static String templatePath;
static String savePath;
public static void main(String[] args) {
com.aspose.pdf.License license = new com.aspose.pdf.License();
// Call setLicense method to set license
try {
license.setLicense("Aspose.Total.Java.lic");
System.out.println(" Aspose.pdf.License() Loaded. . . . ");
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
com.aspose.barcode.License license1 = new com.aspose.barcode.License();
try {
license1.setLicense("Aspose.Total.Java.lic");
System.out.println(" Aspose.barcode.License() Loaded. . . . ");
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
String strDtTm = dtFmt.format(sysDate);
//Setup Path ------------------------------------------------------
pathSeparator = File.separator;
if (pathSeparator.equals("\\")) {
System.out.println("=== Windows ENV. ===");
currentRelativePath = Paths.get("");
pgmPath = currentRelativePath.toAbsolutePath().toString();
templatePath = pgmPath + "\\TEMPLATE\\";
savePath = pgmPath + "\\DOCHST\\";
}else{
System.out.println("=== AS400 UNIX ENV. ===");
templatePath = "/qopensys/QIBM/UserData/DOCDTA/TEMPLATE/";
savePath = "/qopensys/QIBM/UserData/DOCDTA/DOCHST/";
};
System.out.println("templatePath: " + templatePath);
System.out.println("historyPath: " + savePath);
String templateDoc = "FormA.pdf";
String docIn = templatePath.trim() + templateDoc;
String docOut = savePath.trim() + "FormA_Barcode_" + strDtTm + ".pdf";;
// Open a document, this is PDF fillable document
Document pdfDocument = new Document(docIn);
System.out.println("-------------------------------");
System.out.println("Display Form fields before populated...");
System.out.println("-------------------------------");
Field[] fields = pdfDocument.getForm().getFields();
for (int i = 0; i < fields.length; i++) {
System.out.println("Form field: " + fields[i].getFullName() + " " +
"value: " + fields[i].getValue());
}
//Populating PDF Form Fields
for (int i = 0; i < fields.length; i++) {
if (fields[i].getFullName().toString().equals("Given Name Text Box")) {
fields[i].setValue("Thomas Lawrence");
};
if (fields[i].getFullName().toString().equals("Family Name Text Box")) {
fields[i].setValue("Jefferson West");
};
if (fields[i].getFullName().toString().equals("Address 1 Text Box")) {
fields[i].setValue("220 Avenue of Americas");
};
if (fields[i].getFullName().toString().equals("Address 2 Text Box")) {
fields[i].setValue("Date/Time: " + strDtTm);
};
// fields[i].setReadOnly(true);
}
System.out.println("\n %%%%%%%% WRITE BAR CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ---BEG---");
ByteArrayOutputStream imageStream2 = new ByteArrayOutputStream();
String barcodeText = "BARCODE 12345";
BarCodeGenerator bb = new BarCodeGenerator(com.aspose.barcode.EncodeTypes.CODE_39_STANDARD, barcodeText );
bb.getBarHeight().setPoint(30.0f);
try {
bb.save(imageStream2, BarCodeImageFormat.PNG);
} catch (Exception ex) {
System.out.println(" >>> Error saving Object: ImageStream2 ");
}
byte[] bytes2 = imageStream2.toByteArray();
ByteArrayInputStream inputStream2 = new ByteArrayInputStream(bytes2);
// create image stamp
ImageStamp imageStamp2 = new ImageStamp(inputStream2);
imageStamp2.setBackground(true);
imageStamp2.setXIndent(380);
imageStamp2.setYIndent(120);
imageStamp2.setHeight(30);
imageStamp2.setWidth(180);
// Add stamp to particular page
pdfDocument.getPages().get_Item(1).addStamp(imageStamp2);
System.out.println(" Bar-Code Text: " + barcodeText.trim());
System.out.println(" %%%%%%%% WRITE BAR CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ---END---");
// Save the updated document
System.out.println("\nOutput Document is: " + docOut);
pdfDocument.save(docOut.toString());
System.out.println("END OF PROCESS. . . ");
}
}
FormA_Barcode_190823-1705.pdf (68.2 KB)