/*
* $Id$
*
* This code is part of the 'iText Tutorial'.
* You can find the complete tutorial at the following address:
* http://itextdocs.lowagie.com/tutorial/
*
* This code 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.
*
* itext-questions@lists.sourceforge.net
*/
package org.geoforge.demo;
import com.lowagie.text.LwgDocument;
import com.lowagie.text.LwgElement;
import com.lowagie.text.LwgFont;
import com.lowagie.text.FontFactory;
import com.lowagie.text.LwgPageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.LwgPhrase;
import com.lowagie.text.html.Markup;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfDestination;
import com.lowagie.text.pdf.PdfOutline;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
import java.io.File;
import java.io.FileOutputStream;
/**
* Creates a document with outlines (bookmarks).
*
* Geoforge demo, author : amadeus sowerby, adapted from :
*
* com.lowagie.examples.directcontent.pageevents.Bookmarks.java
* and other demos from itext v 4.2.0
*
* @author blowagie
*/
public class GfrDemoJfcAndTextDemo extends PdfPageEventHelper
{
/** Keeps the number of the current paragraph. */
private int n = 0;
/**
* Adds an outline for every new Paragraph
* @param writer
* @param document
* @param position
*/
@Override
public void onParagraph(PdfWriter writer, LwgDocument document, float position)
{
n++;
PdfContentByte cb = writer.getDirectContent();
PdfDestination destination = new PdfDestination(PdfDestination.FITH, position);
new PdfOutline(cb.getRootOutline(), destination, "paragraph " + n);
}
/**
* Creates a document with outlines.
*
* @param args
* no arguments needed
*/
public static void doJob(
File fle,
String strTestDate,
String strKind,
boolean blnZStepTenCm)
{
int intZStep = 10;
if (!blnZStepTenCm)
intZStep += 10;
// step 1: creation of a document-object
LwgDocument document = new LwgDocument(LwgPageSize.A4);
try
{
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fle));
// step 3:
//writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
document.open();
// step 4: we grab the ContentByte and do some stuff with it
writer.setPageEvent(new GfrDemoJfcAndTextDemo());
LwgFont font9 = FontFactory.getFont(FontFactory.HELVETICA, 9);
LwgFont font15 = FontFactory.getFont(FontFactory.HELVETICA, 15);
font15.setStyle(Markup.CSS_VALUE_BOLD);
Paragraph pghTitleA = new Paragraph("Summary log for dynamic probing", font15);
pghTitleA.setAlignment(LwgElement.ALIGN_CENTER);
document.add(pghTitleA);
document.add(new Paragraph("Location of penetration test:", font9));
document.add(new Paragraph("x, y, z-coordinates:", font9));
document.add(new Paragraph("Client/job number:", font9));
document.add(new Paragraph("Name and location of project:", font9));
document.add(new Paragraph("Contractor:", font9));
document.add(new Paragraph("Equipment operator:", font9));
document.add(new Paragraph("Date of test: " + strTestDate, font9));
document.add(new Paragraph("Type of dynamic probing:", font9));
document.add(new Paragraph("Equipment checked and in accordance with EN ISO 22476-2, 5.1:", font9));
document.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", font9));
document.add(new Paragraph("Other relevant data:", font9));
document.add(new Paragraph("Signature:", font9));
document.add(new Paragraph("Name of the operator in charge:", font9));
document.newPage();
// step 4
Paragraph pghTitleB = new Paragraph("Record of measured values and test results for dynamic probing", font15);
pghTitleB.setAlignment(LwgElement.ALIGN_CENTER);
document.add(pghTitleB);
document.add(new Paragraph("\n\n", font9));
LwgPdfPTable tableBeg = new LwgPdfPTable(3);
tableBeg.setWidthPercentage(100);
tableBeg.getDefaultCell().setHorizontalAlignment(LwgElement.ALIGN_LEFT);
tableBeg.getDefaultCell().setVerticalAlignment(LwgElement.ALIGN_MIDDLE);
tableBeg.add(new LwgPhrase("Contractor:", font9));
tableBeg.add(new LwgPhrase("Job number:", font9));
tableBeg.add(new LwgPhrase("Enclosure:", font9));
document.add(tableBeg);
float[] columnDefinitionSizePrj =
{
15f, 40f,
};
LwgPdfPTable tablePrj = new LwgPdfPTable(columnDefinitionSizePrj);
tablePrj.setWidthPercentage(100);
tablePrj.getDefaultCell().setHorizontalAlignment(LwgElement.ALIGN_LEFT);
tablePrj.getDefaultCell().setVerticalAlignment(LwgElement.ALIGN_MIDDLE);
tablePrj.add(new LwgPhrase("Client/name of project:", font9));
tablePrj.add(new LwgPhrase("", font9));
tablePrj.add(new LwgPhrase("Dynamic probing test NÂș:", font9));
tablePrj.add(new LwgPhrase("", font9));
tablePrj.add(new LwgPhrase("Date:", font9));
tablePrj.add(new LwgPhrase("", font9));
tablePrj.add(new LwgPhrase("Type of dynamic probing test:", font9));
tablePrj.add(new LwgPhrase(strKind, font9));
tablePrj.add(new LwgPhrase("Lost/fixed cone", font9));
tablePrj.add(new LwgPhrase("Fixed/loose anvil", font9));
document.add(tablePrj);
float fltWidthDepth = 13f;
float fltWidthBlowCount = 17f;
float[] columnDefinitionSize =
{
fltWidthDepth, fltWidthBlowCount,
fltWidthDepth, fltWidthBlowCount,
fltWidthDepth, fltWidthBlowCount,
fltWidthDepth, fltWidthBlowCount,
fltWidthDepth, fltWidthBlowCount
};
LwgPdfPTable table = new LwgPdfPTable(columnDefinitionSize);
table.setWidthPercentage(100);
table.getDefaultCell().setHorizontalAlignment(LwgElement.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(LwgElement.ALIGN_MIDDLE);
String strNBlowcount = "N" + Integer.toString(intZStep);
LwgPhrase phrDepth = new LwgPhrase("Depth (m)", font9);
LwgPhrase phrBlowcount = new LwgPhrase(strNBlowcount, font9);
LwgPhrase phrTorque = new LwgPhrase("Torque :", font9);
//--
for (int i = 0; i < 5; i++)
{
table.add(phrDepth);
table.add(phrBlowcount);
}
int rowPack = (int) (100 / intZStep);
for (int j = 0; j < rowPack; j++)
{
for (int i = 0; i < 5; i++)
{
double dblDepth = (double) (intZStep * (j + 1)) / 100d + (double) 2 * i;
String strDepth = Double.toString(dblDepth);
table.add(new LwgPhrase(strDepth, font9));
table.add("");
}
}
for (int i = 0; i < 5; i++)
{
table.add(phrTorque);
table.add(new LwgPhrase("xxx Nm", font9));
}
for (int j = 0; j < rowPack; j++)
{
for (int i = 0; i < 5; i++)
{
double dblDepth = (double) (intZStep * (j + 1)) / 100d + (double) 2 * i + 1d;
String strDepth = Double.toString(dblDepth);
table.add(new LwgPhrase(strDepth, font9));
table.add("");
}
}
for (int i = 0; i < 5; i++)
{
table.add(phrTorque);
table.add(new LwgPhrase("xxx Nm", font9));
}
document.add(table);
String str = "\n"
+ "Other dataName" + "\n" + "\n"
+ "Groundwater: ....... m below starting point "
+ "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n"
+ "\n" + "\n" + "\n" + "\n"
+ "Name and signature of the operator in charge:" + "\n" + "\n";
LwgPdfPTable tableEnd = new LwgPdfPTable(1);
tableEnd.setWidthPercentage(100);
tableEnd.add(new Paragraph(str, font9));
document.add(tableEnd);
// step n+1
/*PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(400, 600);
Graphics2D g2d = tp.createGraphics(400, 600, new DefaultFontMapper());
Rectangle2D r2d = new Rectangle2D.Double(0, 0, 400, 600);
JFreeChartExample.getPieChart().draw(g2d, r2d);
g2d.dispose();
tp.sanityCheck();
cb.addTemplate(tp, 0, 0);
cb.sanityCheck();*/
}
catch (Exception de)
{
de.printStackTrace();
}
// step 5: we close the document
document.close();
}
}