I'm implementing a web application using spring 4.2.5 and jasperreports 6.4.3.
This app is supposed to generate a pdf file as output. There are three jrxml files:
firstpage.jrxml: contains logo and some titles
intro.jsrxml: contains some texts and a table of items overview
items.jrxml: contains some texts and an image to show a JFree MeterPlot output buffer image.
The code:
public void export() {
JasperPrint firstPagePrint = ...;
JasperPrint introPrint = ...;
List<JasperPrint> itemsPrints = new LinkedList<JapserPrint>();
List<Item> items = ...;
for (int i = 0; i < items.size(); i++) {
Item item = items.get(i);
MeterPlot meterPlot = new MeterPlot(new DefaultValueDataset(item.getValue()));
meterPlot.setRange(new Range(item.getMinValue(), item.getMaxValue()));
meterPlot.addInterval(new MeterInterval("bad", new Range(item.getMinValue(), item.getSect1()),
Color.red, new BasicStroke(2f), Color.red));
meterPlot.addInterval(new MeterInterval("weak", new Range(item.getSect1(), item.getSect2()),
Color.orange, new BasicStroke(2f), Color.orange));
meterPlot.addInterval(new MeterInterval("average", new Range(item.getSect2(), item.getSect3()),
Color.yellow, new BasicStroke(2f), Color.yellow));
meterPlot.addInterval(new MeterInterval("good", new Range(item.getSect3(), item.getSect4()),
Color.green, new BasicStroke(2f), Color.green));
meterPlot.addInterval(new MeterInterval("excellent", new Range(item.getSect4(), item.getMaxValue()),
Color.black, new BasicStroke(2f), Color.BLUE));
JFreeChart jFreeChart = new JFreeChart(item.getTitle(), meterPlot);
BufferedImage bufferedImage = jFreeChart.createBufferedImage(555, 250);
String tmpFile = FileService.JASPER + Util.randomNumeralString(20) + ".png";
ImageIO.write(bufferedImage, "png", new File(tmpFile));
itemAnalysisParams.put("chartImage", tmpFile);
analysisPrints.add(JasperFillManager.fillReport(ITEM_ANALYSIS, itemAnalysisParams, new JREmptyDataSource()));
}
...export pdf by jasper report prints
}
Notice:
sect1, sect2, sect3 and sect4 are internal limitation for intervals.
sect = (maxValue - minValue) * 20 / 100
sect1 = this.minValue + sect
sect2 = this.sect1 + sect
sect3 = this.sect2 + sect
sect4 = this.sect3 + sect
The problem:
The line BufferedImage bufferedImage = jFreeChart.createBufferedImage(555, 250); takes a long time- about 15min- to create image and it repeats for about 45 items and takes 15min*45 total time to generate report.
In advance, I appreciate any help.
Related
I need to add an itext watermark to my pdf android java pdf file
my sample current code for creating the pdf file:
File docsFolder = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "osary/estmara");
String currentDate = new SimpleDateFormat("dd-MM-yyyy_hh_mm_aaa", Locale.getDefault()).format(new Date());
String pdfname = myEstmaraa.getTalabId() + "_" + currentDate + ".pdf";
pdfFile = new File(docsFolder, pdfname);
OutputStream output = new FileOutputStream(pdfFile);
Document document = new Document(PageSize.A4);
document.setMargins(5, 5, 5, 5);
PdfWriter PdfWriters = PdfWriter.getInstance(document, output);
PdfWriters.createXmpMetadata();
PdfWriters.setTagged();
document.open();
//todo 2 preparing Header and directions and margin row 0
PdfPTable tableForRowZero = new PdfPTable(new float[]{1});
tableForRowZero.setSpacingBefore(5);
tableForRowZero.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
tableForRowZero.getDefaultCell().setFixedHeight(34);
tableForRowZero.setTotalWidth(PageSize.A4.getWidth());
tableForRowZero.setWidthPercentage(100);
tableForRowZero.setHeaderRows(0);
tableForRowZero.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
cellss = new PdfPCell(new Phrase("رقم الاستمارة", FONT2));
cellss.setHorizontalAlignment(Element.ALIGN_CENTER);
cellss.setVerticalAlignment(Element.ALIGN_CENTER);
cellss.setBackgroundColor(BaseColor.GRAY);
tableForRowZero.addCell(cellss);
tableForRowZero.setHeaderRows(0);
cellss = new PdfPCell(new Phrase(String.valueOf(myEstmaraa.getTalabId()), FONT2));
cellss.setHorizontalAlignment(Element.ALIGN_CENTER);
cellss.setVerticalAlignment(Element.ALIGN_CENTER);
tableForRowZero.addCell(cellss);
document.add(tableForRowZero);
document.close();
i have tried this code but it for desktop java:
enter link description here
and the problem that i faced is this line:
PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
when i change it to android i face a problem, i tried it like:
com.itextpdf.kernel.pdf.PdfDocument pdfDoc = new com.itextpdf.kernel.pdf.PdfDocument(new PdfReader(pdfFile.getPath()),new PdfWriter(pdfFile.getPath()));
it gives me this hint:
Cannot resolve constructor 'PdfWriter(java.lang.String)'
the code i tried to make watermark:
com.itextpdf.kernel.pdf.PdfDocument pdfDoc = new com.itextpdf.kernel.pdf.PdfDocument(new PdfReader(pdfFile.getPath()),new PdfWriter(pdfFile.getPath()));
PdfCanvas under = new PdfCanvas(pdfDoc.getFirstPage().newContentStreamBefore(), new PdfResources(), pdfDoc);
PdfFont font = PdfFontFactory.createFont(FontProgramFactory.createFont(StandardFonts.HELVETICA));
com.itextpdf.layout.element.Paragraph paragraph2 = new com.itextpdf.layout.element.Paragraph("This watermark is added UNDER the existing content")
.setFont(font)
.setFontSize(15);
Canvas canvasWatermark1 = new Canvas(under, pdfDoc.getDefaultPageSize())
.showTextAligned(paragraph2, 297, 550, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0);
canvasWatermark1.close();
PdfCanvas over = new PdfCanvas(pdfDoc.getFirstPage());
over.setFillColor(ColorConstants.BLACK);
paragraph2 = new com.itextpdf.layout.element.Paragraph("This watermark is added ON TOP OF the existing content")
.setFont(font)
.setFontSize(15);
Canvas canvasWatermark2 = new Canvas(over, pdfDoc.getDefaultPageSize())
.showTextAligned(paragraph2, 297, 500, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0);
canvasWatermark2.close();
paragraph2 = new com.itextpdf.layout.element.Paragraph("This TRANSPARENT watermark is added ON TOP OF the existing content")
.setFont(font)
.setFontSize(15);
over.saveState();
// Creating a dictionary that maps resource names to graphics state parameter dictionaries
PdfExtGState gs1 = new PdfExtGState();
gs1.setFillOpacity(0.5f);
over.setExtGState(gs1);
Canvas canvasWatermark3 = new Canvas(over, pdfDoc.getDefaultPageSize())
.showTextAligned(paragraph2, 297, 450, 1, TextAlignment.CENTER, VerticalAlignment.TOP, 0);
canvasWatermark3.close();
over.restoreState();
i tried also to add png image and set its opacity but it cover the content
try {
com.itextpdf.text.Image image1_emp_osary = null;
Drawable d_emp_osary = getResources().getDrawable(R.drawable.ketm_estmara);
BitmapDrawable bitDw_emp_osary = ((BitmapDrawable) d_emp_osary);
Bitmap bmp_emp_osary = bitDw_emp_osary.getBitmap();
ByteArrayOutputStream stream_emp_osary = new ByteArrayOutputStream();
bmp_emp_osary.compress(Bitmap.CompressFormat.PNG, 100, stream_emp_osary);
image1_emp_osary = com.itextpdf.text.Image.getInstance(stream_emp_osary.toByteArray());
image1_emp_osary.scaleToFit(200, 200);
image1_emp_osary.setAlignment(Element.ALIGN_BOTTOM);
image1_emp_osary.setSpacingBefore(200);
image1_emp_osary.setTransparency(new int[]{5, 5});
document.add(new Chunk(image1_emp_osary, 0, 200));
PdfContentByte canvas = PdfWriters.getDirectContentUnder();
PdfGState state = new PdfGState();
state.setFillOpacity(0.6f);
canvas.setGState(state);
canvas.addImage(image1_emp_osary);
canvas.restoreState();
} catch (Exception e) {
e.printStackTrace();
}
i have solved it,
the idea is:
1.we need to save the file with out water mark ,and that was easy:
File docsFolder = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "osary/estmara");
String currentDate = new SimpleDateFormat("dd-MM-yyyy_hh_mm_aaa", Locale.getDefault()).format(new Date());
String pdfname = myEstmaraa.getTalabId() + "_" + currentDate + ".pdf";
pdfFile = new File(docsFolder, pdfname);
OutputStream output = new FileOutputStream(pdfFile);
Document document = new Document(PageSize.A4);
document.setMargins(5, 5, 5, 5);
PdfWriter PdfWriters = PdfWriter.getInstance(document, output);
PdfWriters.createXmpMetadata();
PdfWriters.setTagged();
document.open();
//todo 2 preparing Header and directions and margin row 0
PdfPTable tableForRowZero = new PdfPTable(new float[]{1});
tableForRowZero.setSpacingBefore(5);
tableForRowZero.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
tableForRowZero.getDefaultCell().setFixedHeight(34);
tableForRowZero.setTotalWidth(PageSize.A4.getWidth());
tableForRowZero.setWidthPercentage(100);
tableForRowZero.setHeaderRows(0);
tableForRowZero.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
cellss = new PdfPCell(new Phrase("رقم الاستمارة", FONT2));
cellss.setHorizontalAlignment(Element.ALIGN_CENTER);
cellss.setVerticalAlignment(Element.ALIGN_CENTER);
cellss.setBackgroundColor(BaseColor.GRAY);
tableForRowZero.addCell(cellss);
tableForRowZero.setHeaderRows(0);
cellss = new PdfPCell(new Phrase(String.valueOf(myEstmaraa.getTalabId()), FONT2));
cellss.setHorizontalAlignment(Element.ALIGN_CENTER);
cellss.setVerticalAlignment(Element.ALIGN_CENTER);
tableForRowZero.addCell(cellss);
document.add(tableForRowZero);
document.close();
2.we will open the file but we can not override it directly,
so:
a. we will save it in a temp file with the watermark and close it:
File tempFile = new File(docsFolder.getPath(), "temp.pdf");
com.itextpdf.kernel.pdf.PdfWriter TempWriter = new com.itextpdf.kernel.pdf.PdfWriter(tempFile);
String font = "/res/font/arialbd.ttf";
PdfFontFactory.register(font);
FontProgram fontProgram = FontProgramFactory.createFont(font, true);
PdfFont f = PdfFontFactory.createFont(fontProgram, PdfEncodings.IDENTITY_H);
LanguageProcessor languageProcessor = new ArabicLigaturizer();
com.itextpdf.kernel.pdf.PdfDocument tempPdfDoc = new com.itextpdf.kernel.pdf.PdfDocument(new PdfReader(pdfFile.getPath()), TempWriter);
com.itextpdf.layout.Document TempDoc = new com.itextpdf.layout.Document(tempPdfDoc);
com.itextpdf.layout.element.Paragraph paragraph0 = new com.itextpdf.layout.element.Paragraph(languageProcessor.process("الاستماره الالكترونية--الاستماره الالكترونية--الاستماره الالكترونية--الاستماره الالكترونية"))
.setFont(f).setBaseDirection(BaseDirection.RIGHT_TO_LEFT)
.setFontSize(15);
Drawable d_ketm_estmara = getResources().getDrawable(R.drawable.ketm_estmara);
Bitmap bitDw_estmara = ((BitmapDrawable) d_ketm_estmara).getBitmap();
ByteArrayOutputStream stream_estmara = new ByteArrayOutputStream();
bitDw_estmara.compress(Bitmap.CompressFormat.PNG, 100, stream_estmara);
byte[] data = stream_estmara.toByteArray();
ImageData img = ImageDataFactory.create(data);
PdfExtGState gs1 = new PdfExtGState().setFillOpacity(0.2f);
for (int i = 1; i <= tempPdfDoc.getNumberOfPages(); i++) {
PdfPage pdfPage = tempPdfDoc.getPage(i);
com.itextpdf.kernel.geom.Rectangle pageSize = pdfPage.getPageSize();
float x = (pageSize.getLeft() + pageSize.getRight()) / 2;
float y = (pageSize.getTop() + pageSize.getBottom()) / 3;
PdfCanvas over = new PdfCanvas(pdfPage);
over.saveState();
over.setExtGState(gs1);
TempDoc.showTextAligned(paragraph0, 300, 760, i, TextAlignment.CENTER, VerticalAlignment.TOP, 0);
float leftImage = 20;
float bottomImage = 120;
float rightImage = 550;
float topImage = 720;
over.addImageWithTransformationMatrix(img, rightImage, 0, 0, topImage, leftImage, bottomImage, true);
over.restoreState();
}
TempDoc.close();
tempPdfDoc.close();
b. we will open the temp file and save it with the old name:
com.itextpdf.kernel.pdf.PdfDocument pdfDoc = new com.itextpdf.kernel.pdf.PdfDocument(new PdfReader(tempFile.getPath()), new com.itextpdf.kernel.pdf.PdfWriter(new File(docsFolder.getPath(), pdfname)));
com.itextpdf.layout.Document doc = new com.itextpdf.layout.Document(pdfDoc);
doc.close();
pdfDoc.close();
Using setSeriesPaint, I set the colors for the series: red and black. You can see the problem in the picture:
Instead of black, there is something in between black and red, because, apparently, there is an overlay on red. How to solve this problem?
TimeSeries all = new TimeSeries( "All" );
TimeSeries heal = new TimeSeries( "Heal" );
Document document = Jsoup.connect(. . .).get();
Elements h = document.select("tr");
int a = 0;
for(int i = h.size()-1;i>1;i--) {
String[] mas = String.valueOf(h.get(i).text()).split(" ");
SimpleDateFormat ft = new SimpleDateFormat ("dd.MM.yyyy");
Date da = ft.parse(mas[0]);
Day d = new Day(da);
all.add(d, Double.parseDouble(mas[10]));
heal.add(d, Double.parseDouble(mas[4]));
}
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(all);
dataset.addSeries(heal);
JFreeChart lineChartObject = ChartFactory.createXYAreaChart(. . .);
XYPlot plot = (XYPlot) lineChartObject.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.black);
plot.setRangeGridlinePaint(Color.black);
DateAxis domain = new DateAxis("Дата");
plot.setDomainAxis(domain);
XYAreaRenderer movingAverageRenderer = new XYAreaRenderer();
movingAverageRenderer.setUseFillPaint(false);
movingAverageRenderer.setSeriesPaint(0, Color.red);
movingAverageRenderer.setSeriesPaint(1, Color.black);
plot.setRenderer(movingAverageRenderer);
int width = 640;
int height = 480;
File lineChart = new File( "C://gr", "graph.jpeg");
ChartUtilities.saveChartAsJPEG(lineChart ,lineChartObject, width ,height);
XYSeriesCollection dataset = new XYSeriesCollection();
XYSeries validKoordinates = new XYSeries("Not dangerous");
for (SimulationResult sr : validSR.values()) {
validKoordinates.add(sr.getMinTTC(), sr.getMinTHW()); //x,y
}
dataset.addSeries(validKoordinates);
JFreeChart chart = chart = ChartFactory.createScatterPlot(
"Distribution of THW and TTC Values",
"TTC", "THW", dataset);
//Changes background color
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(new Color(255, 228, 196));
plot.getRendererForDataset(plot.getDataset(0)).setSeriesPaint(0, Color.GRAY);
XYSeriesCollection dataset2 = new XYSeriesCollection();
XYSeries warningKoordinates = new XYSeries("Very critical");
for (SimulationResult sr : criticalSR.values()) {
warningKoordinates.add(sr.getMinTTC(), sr.getMinTHW()); //x,y
}
dataset2.addSeries(warningKoordinates);
plot.setDataset(1, dataset2);
plot.getRendererForDataset(plot.getDataset(1)).setSeriesPaint(0, Color.RED);
So I have two different datasets (dataset 1 and dataset 2). Each dataset contains different values. My aim is to change the color of the dataset 1 to gray and the color of the second one to red. (BUT the shape should same the SAME). At the beginning I only had one dataset with 2 XYSeries. The problem at that time was that the shape was different for each XYSeries. Now I have the opposite problem. The shape stays but the color does not change.
This is what my table looks right now:
As you can see right now I cant seperate which one is very critical and whitch not.
It is found that only one dataSet is required, all series should be added to the dataSet. And using the first parameter of setSeriesPaint to configure color of the series. Since the version of jfreeChart is not provide, I used 1.0.12. The code is edited for testing.
public static void main(String[] args) throws IOException {
XYSeriesCollection dataset = new XYSeriesCollection();
int[][] sr = new int[3][2];
for (int i = 0; i < sr.length; i++) {
sr[i][0] = i + 3;
sr[i][1] = 2 * (i + 1) + 1;
}
XYSeries validKoordinates = new XYSeries("Not dangerous");
XYSeries warningKoordinates = new XYSeries("Very critical");
System.out.println(sr.length);
for (int i = 0; i < sr.length; i++) {
validKoordinates.add(sr[i][0], sr[i][1]);
}
for (int i = 0; i < sr.length; i++) {
warningKoordinates.add(sr[i][0]+1, sr[i][1]+1);
}
// Add dataset for all series
dataset.addSeries(validKoordinates);
dataset.addSeries(warningKoordinates);
// Only reference one dataset
JFreeChart chart = ChartFactory.createScatterPlot("Distribution of THW and TTC Values", "TTC", "THW", dataset,
PlotOrientation.HORIZONTAL, true, true, true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(new Color(255, 228, 196));
// Change the index of setSeriesPaint to set color
plot.getRendererForDataset(dataset).setSeriesPaint(0, Color.GRAY);
plot.getRendererForDataset(dataset).setSeriesPaint(1, Color.RED);
BufferedImage objBufferedImage = chart.createBufferedImage(600, 800);
ByteArrayOutputStream bas = new ByteArrayOutputStream();
try {
ImageIO.write(objBufferedImage, "png", bas);
} catch (IOException e) {
e.printStackTrace();
}
byte[] byteArray = bas.toByteArray();
InputStream in = new ByteArrayInputStream(byteArray);
BufferedImage image = ImageIO.read(in);
File outputfile = new File("testimage.png");
ImageIO.write(image, "png", outputfile);
}
The image generated by the above method
I need to insert a background image for my graphic. Actually, I did it, but I have problem.
How to remove everything except the red line itself?
Now I have this result(look below image).
XYSeries series4 = new XYSeries("Траектория движения ЛА");
for (int i = 0; i < La.size(); i++) {
series4.add(massLatitude[i], massLongitude[i]);
}
XYSeriesCollection seriesCollection4 = new XYSeriesCollection(series4);
Image icon = ImageIO.read(new File("image.jpg"));
final JFreeChart chart4 = ChartFactory.createScatterPlot("Траектория полета ЛА", null, null,
seriesCollection4);
chart4.setBackgroundImage(icon);
final ChartPanel chartPanel4 = new ChartPanel(chart4);
chartPanel4.setPreferredSize(new Dimension(1300, 480));
panel.add(chartPanel4);
How to remove everything except the red line itself?
You need to get rid of the grid lines, and the plot background (different from the chart background):
chart.getXYPlot().setDomainGridlinesVisible(false);
chart.getXYPlot().setRangeGridlinesVisible(false);
Color trans = new Color(0xFF, 0xFF, 0xFF, 0);
chart.getPlot().setBackgroundPaint( trans );
I achieved success by half) But how can I remove the notation XAxis and YAxis? Now I have it enter image description here
XYSeries series4 = new XYSeries("Траектория движения ЛА");
for (int i = 0; i < La.size(); i++) {
series4.add(massLongitude[i], massLatitude[i]);
}
XYSeriesCollection seriesCollection4 = new XYSeriesCollection(series4);
Image icon = ImageIO.read(new File("DlyaOpen.jpg"));
final JFreeChart chart4 = ChartFactory.createScatterPlot(null, null, null,
seriesCollection4);
chart4.removeLegend();
chart4.setBackgroundImage(icon);
Color trans = new Color(0xFF, 0xFF, 0xFF, 0);
chart4.getPlot().setBackgroundPaint( trans );
chart4.getPlot().setOutlineVisible(false);
chart4.getXYPlot().setRangeGridlinesVisible(false);
chart4.getXYPlot().setDomainGridlinesVisible(false);
final ChartPanel chartPanel4 = new ChartPanel(chart4);
chartPanel4.setPreferredSize(new Dimension(800, 480));
panel.add(chartPanel4);
I am trying to implement a batch export similar to one here (as in the link) in jasper reports.
Please give pointers.
What I have:
1. A Portrait Template
2. A Landscape Template
3. Order in which I need to generate the reports
4. Same Bean Datasource with filter queries for each template to fill
What I need:
Generate the reports separately and merge all the generated JasperPrint objects and tweak the Page Nos
Since you are generating the reports and then merging it, current page number and total pages are available only during the export, based on the number of reports you merge. We solved a similar issue using generic elements. You need to write your custom logic to handle the page number inside the handler you create.
My report page 1 (jr1) is portrait and page 2 (jr2) landscape.
JasperReport jr1 = (JasperReport) JRLoader.loadObject(...);
JasperReport jr2 = (JasperReport) JRLoader.loadObject(...);
JREmptyDataSource ds = new JREmptyDataSource(1);
JasperPrint print1 = JasperFillManager.fillReport(jr1, new HashMap(), ds);
ds.moveFirst();
JasperPrint print2 = JasperFillManager.fillReport(jr2, new HashMap(), ds);
List l = new ArrayList();
l.add(print1);
l.add(print2);
JRPdfExporter exp = new JRPdfExporter();
exp.setParameter(JRExporterParameter.JASPER_PRINT_LIST, l);
exp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, SAVE_LOCATION);
exp.exportReport();
This might work for page number issue:
private static void mergeAndNumber() throws IOException, DocumentException
{
PdfReader readerOne = new PdfReader("c:\file_one.pdf"«»);
// we retrieve the total number of pages
int nOne = readerOne.getNumberOfPages();
PdfReader readerTwo = new PdfReader("c:\file_two.pdf"«»);
// we retrieve the total number of pages
int nTwo = readerTwo.getNumberOfPages();
int totalPages = (nOne + nTwo);
System.out.println("Total number of pages: " + (nOne + nTwo));
Rectangle psize = readerOne.getPageSize(1);
float widthPort = psize.width();
float heightPort = psize.height();
// step 1: creation of a document-object
Document document = new Document(psize, 50, 50, 50, 50);
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("c:\file_combined.pdf"«»));
document.open();
// step 4: we add content
PdfContentByte cb = writer.getDirectContent();
PdfImportedPage importPage = null;
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
float pageNumXPos = widthPort;
float pageNumYPos = heightPort;
for (int i = 1; i <= nOne; i++) {
document.newPage();
importPage = writer.getImportedPage(readerOne, i);
cb.addTemplate(importPage, 0,0);
cb.moveTo(400, 40);
cb.beginText();
cb.setFontAndSize(bf, 10);
//cb.showText("Page " + i + " of " + totalPages);
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, "Page " + i + " of " + totalPages, pageNumXPos - 45, pageNumYPos - 55, 0);
cb.endText();
}
document.setPageSize(PageSize.A4.rotate());
for (int i = 1; i <= nTwo; i++) {
document.newPage();
importPage = writer.getImportedPage(readerTwo, i);
cb.addTemplate(importPage, 0,0);
cb.moveTo(400, 40);
cb.beginText();
cb.setFontAndSize(bf, 10);
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, "Page " + (nOne + i) + " of " + totalPages, pageNumYPos - 20, pageNumXPos - 60, 0);
cb.endText();
}
document.close();
}