I want to integrate a Posiflex printer with my application, where the logical name is "PP Demo" and the device model is PP-8900.
The printer is connected to my system and is able to print with Posiflex software. How can I integrate it with my application?
I just needed to paste the needed dll files into the lib of my java that's it, and the jpos.xml file is mentioned in the code...
package practice;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterJob;
public class PrintableComponent {
public static void main(String[] args) {
PrintableComponent example3 = new PrintableComponent();
System.exit(0);
}
// --- Private instances declarations
private final static int POINTS_PER_INCH = 72;
/**
* Constructor: Example3
* <p>
*
*/
public PrintableComponent() {
// --- Create a new PrinterJob object
PrinterJob printJob = PrinterJob.getPrinterJob();
// --- Create a new book to add pages to
Book book = new Book();
// --- Add the cover page using the default page format for this print
// job
book.append(new IntroPage(), printJob.defaultPage());
// --- Add the document page using a landscape page format
PageFormat documentPageFormat = new PageFormat();
documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
book.append(new Document(), documentPageFormat);
// --- Add a third page using the same painter
book.append(new Document(), documentPageFormat);
// --- Tell the printJob to use the book as the pageable object
printJob.setPageable(book);
// --- Show the print dialog box. If the user click the
// --- print button we then proceed to print else we cancel
// --- the process.
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception PrintException) {
PrintException.printStackTrace();
}
}
}
/**
* Class: IntroPage
* <p>
*
* This class defines the painter for the cover page by implementing the
* Printable interface.
* <p>
*
* #author Jean-Pierre Dube <jpdube#videotron.ca>
* #version 1.0
* #since 1.0
* #see Printable
*/
private class IntroPage implements Printable {
/**
* Method: print
* <p>
*
* #param g
* a value of type Graphics
* #param pageFormat
* a value of type PageFormat
* #param page
* a value of type int
* #return a value of type int
*/
public int print(Graphics g, PageFormat pageFormat, int page) {
// --- Create the Graphics2D object
Graphics2D g2d = (Graphics2D) g;
// --- Translate the origin to 0,0 for the top left corner
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
// --- Set the default drawing color to black
g2d.setPaint(Color.black);
// --- Draw a border arround the page
Rectangle2D.Double border = new Rectangle2D.Double(0, 0, pageFormat.getImageableWidth(),
pageFormat.getImageableHeight());
g2d.draw(border);
// --- Print the title
String titleText = "Printing in Java Part 2";
Font titleFont = new Font("helvetica", Font.BOLD, 36);
g2d.setFont(titleFont);
// --- Compute the horizontal center of the page
FontMetrics fontMetrics = g2d.getFontMetrics();
double titleX = (pageFormat.getImageableWidth() / 2) - (fontMetrics.stringWidth(titleText) / 2);
double titleY = 3 * POINTS_PER_INCH;
g2d.drawString(titleText, (int) titleX, (int) titleY);
return (PAGE_EXISTS);
}
}
/**
* Class: Document
* <p>
*
* This class is the painter for the document content.
* <p>
*
*
* #author Jean-Pierre Dube <jpdube#videotron.ca>
* #version 1.0
* #since 1.0
* #see Printable
*/
private class Document implements Printable {
/**
* Method: print
* <p>
*
* #param g
* a value of type Graphics
* #param pageFormat
* a value of type PageFormat
* #param page
* a value of type int
* #return a value of type int
*/
public int print(Graphics g, PageFormat pageFormat, int page) {
// --- Create the Graphics2D object
Graphics2D g2d = (Graphics2D) g;
// --- Translate the origin to 0,0 for the top left corner
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
// --- Set the drawing color to black
g2d.setPaint(Color.black);
// --- Draw a border arround the page using a 12 point border
g2d.setStroke(new BasicStroke(12));
Rectangle2D.Double border = new Rectangle2D.Double(0, 0, pageFormat.getImageableWidth(),
pageFormat.getImageableHeight());
g2d.draw(border);
// --- Print page 1
if (page == 1) {
// --- Print the text one inch from the top and laft margins
g2d.drawString("This the content page of page: " + page, POINTS_PER_INCH, POINTS_PER_INCH);
return (PAGE_EXISTS);
}
// --- Print page 2
else if (page == 2) {
// --- Print the text one inch from the top and laft margins
g2d.drawString("This the content of the second page: " + page, POINTS_PER_INCH, POINTS_PER_INCH);
return (PAGE_EXISTS);
}
// --- Validate the page
return (NO_SUCH_PAGE);
}
}
} // Example3
Related
I want to add the polygon in the PDF at the given coordinates, I referred this link for adding the annotation of circle and rectangle, but it does not contain anything for polygon. Does anyone know how to do it? Or does anyone know where do I get all documentation about PDFBox annotation.
Here I am sharing what I'vs done until now. But I couldn't proceed further.
import java.io.IOException;
import java.io.File;
import java.io.FileReader;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.json.simple.parser.ParseException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo;
import org.apache.pdfbox.pdmodel.interactive.action.PDActionURI;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLine;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationText;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationSquareCircle;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageFitWidthDestination;
public class Polygon{
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
// Loading the PDF File
File file = new File("abc.pdf");
PDDocument document = PDDocument.load(file);
System.out.println("PDF Loaded.");
PDPage page = document.getPage(0);
List<PDAnnotation> polygon = page.getAnnotations();
// Color of polygon
PDColor color = new PDColor(new float[] {0, 0, 1}, PDDeviceRGB.INSTANCE);
// Define border thickness
PDBorderStyleDictionary thickness = new PDBorderStyleDictionary();
thickness.setWidth((float)2);
float[] vertices = {418, 110, 523, 110, 522, 132, 419, 133};
PDAnnotationSquareCircle lines = new PDAnnotationSquareCircle(PDAnnotationSquareCircle.SUB_TYPE_POLYGON);
lines.setColor(color);
lines.setBorderStyle(thickness);
/*****************
*
* ????
* *************************************/
// Save annotations
document.save(file);
// Close document
document.close();
}
}
As far I have seen, There isn't any method for adding vertices in polygon in PDAnnotation jar. So is there any way we can draw polygon here?
Thanks.
Here's some code that will soon be added to the AddAnnotations.java example from the source code download:
static final float INCH = 72;
float pw = page1.getMediaBox().getUpperRightX();
float ph = page1.getMediaBox().getUpperRightY();
PDAnnotationMarkup polygon = new PDAnnotationMarkup();
polygon.getCOSObject().setName(COSName.SUBTYPE, PDAnnotationMarkup.SUB_TYPE_POLYGON);
position = new PDRectangle();
position.setLowerLeftX(pw - INCH);
position.setLowerLeftY(ph - INCH);
position.setUpperRightX(pw - 2 * INCH);
position.setUpperRightY(ph - 2 * INCH);
polygon.setRectangle(position);
polygon.setColor(blue); // border color
polygon.getCOSObject().setItem(COSName.IC, red.toCOSArray()); // interior color
COSArray triangleVertices = new COSArray();
triangleVertices.add(new COSFloat(pw - INCH));
triangleVertices.add(new COSFloat(ph - 2 * INCH));
triangleVertices.add(new COSFloat(pw - INCH * 1.5f));
triangleVertices.add(new COSFloat(ph - INCH));
triangleVertices.add(new COSFloat(pw - 2 * INCH));
triangleVertices.add(new COSFloat(ph - 2 * INCH));
polygon.getCOSObject().setItem(COSName.VERTICES, triangleVertices);
polygon.setBorderStyle(borderThick);
annotations.add(polygon);
to adjust your own code, you need to adjust the rectangle and pass your vertices:
position.setLowerLeftX(418);
position.setLowerLeftY(110);
position.setUpperRightX(523);
position.setUpperRightY(133);
polygon.setRectangle(position);
float[] vertices = {418, 110, 523, 110, 522, 132, 419, 133};
COSArray verticesArray = new COSArray();
for (float v : vertices)
verticesArray.add(new COSFloat(v));
polygon.getCOSObject().setItem(COSName.VERTICES, verticesArray);
This is for 2.0 only. In 3.0 there will be a PDAnnotationPolygon type with appropriate methods. That version will also support the construction of appearance streams, i.e. you will be able to show the PDF with other viewers than Adobe Reader. Most viewers, e.g. PDF.js and PDFBox don't build missing appearances so you'll see nothing.
If you need the appearance for 2.0 you can try with the code in the file ShowAnnotation-6.java in https://issues.apache.org/jira/browse/PDFBOX-3353 .
To test with the 3.0 version, get the jar here:
https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/3.0.0-SNAPSHOT/
To build the appearance, call polygon.constructAppearances();
I would like to perform a 10 fold cross validation on my data and I used the weka java programme. However, I encountered exception problems.
Here is the exceptions:
---Registering Weka Editors---
Trying to add database driver (JDBC): jdbc.idbDriver - Error, not in CLASSPATH?
Exception in thread "main" java.lang.IllegalArgumentException: No suitable converter found for ''!
at weka.core.converters.ConverterUtils$DataSource.<init>(ConverterUtils.java:137)
at weka.core.converters.ConverterUtils$DataSource.read(ConverterUtils.java:441)
at crossvalidationmultipleruns.CrossValidationMultipleRuns.main(CrossValidationMultipleRuns.java:45)
C:\Users\TomXavier\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)
Here is the programme I used:
import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.core.Utils;
import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import java.util.Random;
/**
* Performs a single run of cross-validation.
*
* Command-line parameters:
* <ul>
* <li>-t filename - the dataset to use</li>
* <li>-x int - the number of folds to use</li>
* <li>-s int - the seed for the random number generator</li>
* <li>-c int - the class index, "first" and "last" are accepted as well;
* "last" is used by default</li>
* <li>-W classifier - classname and options, enclosed by double quotes;
* the classifier to cross-validate</li>
* </ul>
*
* Example command-line:
* <pre>
* java CrossValidationSingleRun -t anneal.arff -c last -x 10 -s 1 -W "weka.classifiers.trees.J48 -C 0.25"
* </pre>
*
* #author FracPete (fracpete at waikato dot ac dot nz)
*/
public class CrossValidationSingleRun {
/**
* Performs the cross-validation. See Javadoc of class for information
* on command-line parameters.
*
* #param args the command-line parameters
* #throws Excecption if something goes wrong
*/
public static void main(String[] args) throws Exception {
// loads data and set class index
Instances data = DataSource.read(Utils.getOption("C:/Users/TomXavier/Documents/MATLAB/total_data.arff", args));
String clsIndex = Utils.getOption("first", args);
if (clsIndex.length() == 0)
clsIndex = "last";
if (clsIndex.equals("first"))
data.setClassIndex(0);
else if (clsIndex.equals("last"))
data.setClassIndex(data.numAttributes() - 1);
else
data.setClassIndex(Integer.parseInt(clsIndex) - 1);
// classifier
String[] tmpOptions;
String classname;
tmpOptions = Utils.splitOptions(Utils.getOption("weka.classifiers.trees.J48", args));
classname = tmpOptions[0];
tmpOptions[0] = "";
Classifier cls = (Classifier) Utils.forName(Classifier.class, classname, tmpOptions);
// other options
int seed = Integer.parseInt(Utils.getOption("1", args));
int folds = Integer.parseInt(Utils.getOption("10", args));
// randomize data
Random rand = new Random(seed);
Instances randData = new Instances(data);
randData.randomize(rand);
if (randData.classAttribute().isNominal())
randData.stratify(folds);
// perform cross-validation
Evaluation eval = new Evaluation(randData);
for (int n = 0; n < folds; n++) {
Instances train = randData.trainCV(folds, n);
Instances test = randData.testCV(folds, n);
// the above code is used by the StratifiedRemoveFolds filter, the
// code below by the Explorer/Experimenter:
// Instances train = randData.trainCV(folds, n, rand);
// build and evaluate classifier
Classifier clsCopy = Classifier.makeCopy(cls);
clsCopy.buildClassifier(train);
eval.evaluateModel(clsCopy, test);
}
// output evaluation
System.out.println();
System.out.println("=== Setup ===");
System.out.println("Classifier: " + cls.getClass().getName() + " " + Utils.joinOptions(cls.getOptions()));
System.out.println("Dataset: " + data.relationName());
System.out.println("Folds: " + folds);
System.out.println("Seed: " + seed);
System.out.println();
System.out.println(eval.toSummaryString("=== " + folds + "-fold Cross-validation ===", false));
}
}
Is there any solution for this problem?
Many thanks!
In a swing application, I need to foresee text wrapping of a string like when putting it in a word processor program such as MS Word or LibreOffice. Providing the same width of the displayable area, the same font (face and size) and the same string as following:
displayable area width: 179mm (in a .doc file, setup an A4 portrait page - width = 210mm, margin left = 20mm, right = 11mm; the paragraph is formatted with zero margins)
Font Times New Roman, size 14
Test string: Tadf fdas fdas daebjnbvx dasf opqwe dsa: dfa fdsa ewqnbcmv caqw vstrt vsip d asfd eacc
And the result:
On both MS Word and LibreOffice, that test string is displayed on single line, no text wrapping occurs.
My bellow program report a text wrapping occurs, 2 lines
Line 1: Tadf fdas fdas daebjnbvx dasf opqwe dsa: dfa fdsa ewqnbcmv caqw vstrt vsip d asfd
Line 2: eacc
Is it possible to achieve the same text wrapping effect like MS Word in swing? What could be wrong in the code?
Bellow the my program
public static List<String> wrapText(String text, float maxWidth,
Graphics2D g, Font displayFont) {
// Normalize the graphics context so that 1 point is exactly
// 1/72 inch and thus fonts will display at the correct sizes:
GraphicsConfiguration gc = g.getDeviceConfiguration();
g.transform(gc.getNormalizingTransform());
AttributedCharacterIterator paragraph = new AttributedString(text).getIterator();
Font backupFont = g.getFont();
g.setFont(displayFont);
LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(
paragraph, BreakIterator.getWordInstance(), g.getFontRenderContext());
// Set position to the index of the first character in the paragraph.
lineMeasurer.setPosition(paragraph.getBeginIndex());
List<String> lines = new ArrayList<String>();
int beginIndex = 0;
// Get lines until the entire paragraph has been displayed.
while (lineMeasurer.getPosition() < paragraph.getEndIndex()) {
lineMeasurer.nextLayout(maxWidth);
lines.add(text.substring(beginIndex, lineMeasurer.getPosition()));
beginIndex = lineMeasurer.getPosition();
}
g.setFont(backupFont);
return lines;
}
public static void main(String[] args) throws Exception {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextPane txtp = new JTextPane();
frame.add(txtp);
frame.setSize(200,200);
frame.setVisible(true);
Font displayFont = new Font("Times New Roman", Font.PLAIN, 14);
float textWith = (179 * 0.0393701f) // from Millimeter to Inch
* 72f; // From Inch to Pixel (User space)
List<String> lines = wrapText(
"Tadf fdas fdas daebjnbvx dasf opqwe dsa: dfa fdsa ewqnbcmv caqw vstrt vsip d asfd eacc",
textWith,
(Graphics2D) txtp.getGraphics(),
displayFont);
for (int i = 0; i < lines.size(); i++) {
System.out.print("Line " + (i + 1) + ": ");
System.out.println(lines.get(i));
}
frame.dispose();
}
+1 for the question
From my experience with text editors it's not possible to achieve exactly the same measuring.
You can try to play with DPI there is default DPI=72 and 96 on windows.
Also you can try to play with all the rendering hints of the Graphics - text antialiasing etc.
I'm trying to figure out how to best parse the following log file, splitting each section seperated by the horizontal lines and extract various pieces of data, e.g. 'COMPANY123', 'BIMMU', the date (2/18 etc.) and then create a string containing all of the other data contained in a section delimited by the horizontal lines.
I.e., I want to create an array of 'statement' objects each with the following attributes:
Company name, Account, Date, Data.
E.g. for the second record below,
Account = 'BIMMU'
Firm = 'Super Corporation'
Date= 9/14/11
Data = '* * * * * * * * TODAYS ACCOUNT ACTIVITY * * * * * * * * * * *
9/14/11 Y9 CALL OESX OCT 11 ........ etc'
The log is a fixed-width text file and the variables (date etc.) always occur at the same position in the line, e.g. sSalesCode = line.substring(142, 147);
Should I maybe do this in two passes, e.g. split the code into sections delimited by the horizontal line, and then parse these sections individually?
Just writing this out here has helped me get my train of thought, but if anybody else has any smart ideas then it would be great to hear them.
------------------------------------------------------------------------------------------------------------------------------------F BIASPBIMMU
BIMMU BIASP-COMPANY123 KG (Z ) 9/14/11 EU (T- I- ) MT-0 F BIASP²BIMMU
CALLS 2/18 YI 50.00-X (49) F BIASP²BIMMU
------------------------------------------------------------------------------------------------------------------------------------F BIASPBIMMU
BIMMU BIMM2-SUPER CORPORATION KG (Z ) 9/14/11 EU (T- I- ) MT-0 F BIMM2²BIMMU
F BIMM2²BIMMU
* * * * * * * * * * * * * * * * * * * T O D A Y S A C C O U N T A C T I V I T Y * * * * * * * * * * * * * * * * * * * *F BIMM2²BIMMU
9/14/11 Y9 500 GO CALL OESX OCT 11 2400 9.60 EU .00 F BIMM2²BIMMU
GO-PARFSecurities Ser F BIMM2²BIMMU
Y9 * 500 * COMMISSIONS EU 250.00- F BIMM2²BIMMU
Y9 PERTES & PROFITS NETS EU 250.00- F BIMM2BIMMU
CALLS 9/14 E1 17,825.00-H ( 1) F BIMM2²BIMMU
CALLS 9/14 E1 17,825.00-N ( 1) F BIMM2²BIMMU
-----------------------------------------------------------------------------------------------------------------------------------
You can try to use framework Fixedformat4j. It uses annotations and works fast. I have implemented it partially for my project to understand how it works.
You can create class with annotations like this:
#Record
public class LogRecord {
private String firm;
private String user;
private Date logonDate;
private String logData;
public String getFirm() {
return firm;
}
#field(offset=10, length=10)
public void setFirm(String firm) {
this.firm = firm;
}
public String getUser() {
return user;
}
#field(offset=0, length=10)
public void setUser(String user) {
this.user = user;
}
public Date getLogonDate() {
return logonDate;
}
#field(offset=nn, length=8)
#FixedFormatPattern("mm/dd/yy")
public void setLogonDate(Date logonDate) {
this.logonDate = logonDate;
}
public String getLogData() {
return logData;
}
#field(offset=mm, length=yy)
public void setLogData(String logData) {
this.logData = logData;
}
}
And then instantiate it with FixedFormatManager.
i had similar problem recenly, i ended up using Flapjack (Google Code: Flapjack)... See the examples on google code, i guess it should help you out.
/*
* DynamicJasper: A library for creating reports dynamically by specifying
* columns, groups, styles, etc. at runtime. It also saves a lot of development
* time in many cases! (http://sourceforge.net/projects/dynamicjasper)
*
* Copyright (C) 2008 FDV Solutions (http://www.fdvsolutions.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*
* License as published by the Free Software Foundation; either
*
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
*
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
*
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*
*/
package ar.com.fdvs.dj.test;
import java.sql.*;
import java.awt.Color;
import java.util.Date;
import java.util.Locale;
import net.sf.jasperreports.view.*;
import ar.com.fdvs.dj.domain.AutoText;
import ar.com.fdvs.dj.domain.DynamicReport;
import ar.com.fdvs.dj.domain.Style;
import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
import ar.com.fdvs.dj.domain.builders.StyleBuilder;
import ar.com.fdvs.dj.domain.constants.Font;
import ar.com.fdvs.dj.core.DJConstants;
// import ar.com.fdvs.dj.test.*;
public class Main extends BaseDjReportTest {
public DynamicReport buildReport() throws Exception {
// Connection C = new Connection();
// C.Con();
CConnection C= new CConnection();
C.Connection();
Statement stmt;
ResultSet rs = null;
String SQL = "SELECT * FROM student";
stmt = C.Con().createStatement();
rs = stmt.executeQuery(SQL);
String res= "";
FastReportBuilder drb = new FastReportBuilder();
drb.setQuery(SQL, DJConstants.QUERY_LANGUAGE_SQL);
while (rs.next()){
res= rs.getString("Name");
**drb.addColumn("Name","Name", String.class.getName(),30);**
// drb.addc
}
//.addColumn("Branch", "branch", String.class.getName(),30)
// .addColumn("Item", "item", String.class.getName(),50)
// .addColumn("Item Code", "id", Long.class.getName(),30,true)
// .addColumn("Quantity", "quantity", Long.class.getName(),60,true)
// .addColumn("Amount", "amount", Float.class.getName(),70,true)
drb.addGroups(2);
DynamicReport sa =drb.build();
drb.setSubtitle("This report was generated at " + new Date())
.setTemplateFile("templates/TemplateReportTest.jrxml")
.setUseFullPageWidth(true);
Style atStyle = new StyleBuilder(true).setFont(Font.COMIC_SANS_SMALL).setTextColor(Color.red).build();
Style atStyle2 = new StyleBuilder(true).setFont(new Font(9, Font._FONT_TIMES_NEW_ROMAN, false, true, false)).setTextColor(Color.BLUE).build();
/***
* Adding many autotexts in the same position (header/footer and aligment) makes them to be one on top of the other
*/
//First add in the FOOTER
drb.addAutoText(AutoText.AUTOTEXT_PAGE_X, AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,200,40, atStyle);
drb.addAutoText("Autotext below Page counter", AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_LEFT);
//Note the styled text: <b>msimone</b>, valid tags are: <b>, <i> and <u>
drb.addAutoText("Created by <b>msimone</b>", AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_RIGHT,200);
drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_SLASH_Y, AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_RIGHT,30,30,atStyle2);
drb.addAutoText(AutoText.AUTOTEXT_CREATED_ON, AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_LEFT,AutoText.PATTERN_DATE_DATE_TIME);
//Now in HEADER
drb.addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,100,40);
drb.addAutoText("Autotext at top-left", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,200);
drb.addAutoText("Autotext at top-left (2)", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_LEFT,200);
drb.addAutoText("Autotext at top-center", AutoText.POSITION_HEADER, AutoText.ALIGNMENT_CENTER,200,atStyle);
// DynamicReport dr = drb.build();
//i18N, you can set a Locale, different tha n the default in the VM
drb.setReportLocale(new Locale("es","AR"));
drb.setReportLocale(new Locale("pt","BR"));
drb.setReportLocale(new Locale("fr","FR"));
return sa;
}
public static void main(String[] args) throws Exception {
**Main test = new Main();
test.testReport();**
JasperViewer.viewReport(test.jp);
JasperDesignViewer.viewReportDesign(test.jr);
//JasperDesignViewer.viewReportDesign(DynamicJasperHelper.generateJasperReport(test.dr, test.getLayoutManager(),new HashMap()));
}
}
Writing this code i m getting following exception and i really cant figure out the reason
Exception in thread "main" net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : varchar at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:100)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:818)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:782)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1448)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:108)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:923)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:845)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:85)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:624)
at ar.com.fdvs.dj.test.BaseDjReportTest.testReport(BaseDjReportTest.java:93)
at ar.com.fdvs.dj.test.Main.main(Main.java:121)
Caused by: java.lang.NoSuchMethodException: Unknown property 'varchar' on class 'class ar.com.fdvs.dj.test.domain.Product'
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1322)
at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:770)
at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:846)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:111)
... 12 more
Java Result: 1
You may be aware of this already, but it appears that somewhere, the code is trying to access a property called "varchar" on the Product object:
Caused by: java.lang.NoSuchMethodException: Unknown property 'varchar' on class 'class ar.com.fdvs.dj.test.domain.Product' at .....
I don't see where this is happening in your example. It may be that there is a place where name is expected and you are instead passing in type. Or somewhere in your configuration, you've got name and type switched around, so it's looking for a field named "varchar". Does that make sense?
In general, I find that the "Caused by" portion of the error log is the most informative.