iText footer alignment without tabbing - itext

is there a better way of doing this at the bottom?
The code at the bottom works but it is very cumbersome.
The tabbing is ok, but it would be great if there would be an other solution.
Thanks for help!
// Footer
final Phrase footerPhraseDate = new Phrase();
footerPhraseDate.add(new Chunk("23.01.2011", fontUnderlined10));
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(new Chunk(" ", fontUnderlined10));
footerPhraseDate.add(new Chunk("\n"));
footerPhraseDate.add(new Chunk("Datum", fontNormal8));
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(Chunk.TABBING);
footerPhraseDate.add(new Chunk("Date", fontNormal8));
final Paragraph footerParagraphDate = new Paragraph();
footerParagraphDate.setAlignment(Element.ALIGN_JUSTIFIED);
footerParagraphDate.add(footerPhraseDate);
footerParagraphDate.setSpacingBefore(40f);
footerParagraphDate.setIndentationLeft(90f);
document.add(footerParagraphDate);

Related

problems with rowspan while generating a PDF using iText

Below is my sample application where I am getting an error on line
Add2CellRow(table, "Age", 1, "Gender", 2);
I think the rowspan value is creating the issue as the next line is not building.
Can someone help on the same?
The code is for Arabic Culture so need to set
Thread.CurrentThread.CurrentCulture = new CultureInfo("ar-SA");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("ar-SA");
private static void Add3CellRow(PdfPTable table, string cell1Value, string cell2Value, int rowspan, string imgPath)
{
PdfPCell new1Cell = new PdfPCell(new Phrase(cell1Value, tableFont));
new1Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
new1Cell.MinimumHeight = 25f;
new1Cell.Padding = 6f;
table.AddCell(new1Cell);
PdfPCell new2Cell = new PdfPCell(new Phrase(cell2Value, tableFont));
new2Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
new2Cell.MinimumHeight = 25f;
new2Cell.Padding = 6f;
new2Cell.Colspan = 2;
table.AddCell(new2Cell);
PdfPCell new3Cell = null;
if (!String.IsNullOrWhiteSpace(imgPath))
{
Image img = Image.GetInstance(imgPath);
img.ScaleToFit(150, 150);
new3Cell = new PdfPCell(img);
}
else
{
new3Cell = new PdfPCell(new Phrase(String.Empty));
}
new3Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
new3Cell.HorizontalAlignment = Element.ALIGN_CENTER;
new3Cell.MinimumHeight = 25f;
new3Cell.Rowspan = rowspan;
new3Cell.Colspan = 2;
new3Cell.Padding = 6f;
table.AddCell(new3Cell);
}
private static void Add2CellRow(PdfPTable table, string cell1Value, int colspanCell1, string cell2Value, int colspanCell2 = 2)
{
PdfPCell new1Cell = new PdfPCell(new Phrase(cell1Value, tableFont));
new1Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
new1Cell.MinimumHeight = 25f;
new1Cell.Colspan = colspanCell1;
table.AddCell(new1Cell);
PdfPCell new2Cell = new PdfPCell(new Phrase(cell2Value, tableFont));
new2Cell.VerticalAlignment = Element.ALIGN_MIDDLE;
new2Cell.Colspan = colspanCell2;
new2Cell.MinimumHeight = 25f;
new2Cell.Padding = 6f;
table.AddCell(new2Cell);
}
public static MemoryStream Generate()
{
var doc = new Document(PageSize.A4, 10, 10, 90, 110);
MemoryStream memoryStream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);
doc.Open();
PdfPTable table = new PdfPTable(5);
table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
table.WidthPercentage = 89.5f;
table.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
table.DefaultCell.Padding = 6f;
table.DefaultCell.UseAscender = true;
table.DefaultCell.UseDescender = true;
Add3CellRow(table,"Name","Harshit Verma",4,"");
Add2CellRow(table, "Age", 1, "Gender", 2);
Add2CellRow(table, "Age", 1, "Gender", 2);
Add2CellRow(table, "Age", 1, "Gender", 2);
table.SplitLate = false;
Paragraph p = new Paragraph("");
doc.Add(p);
table.SpacingBefore = 30f;
doc.Add(table);
writer.CloseStream = false;
doc.Close();
memoryStream.Position = 0;
return memoryStream;
}

JavaFX 2.x : Using StackPane to layer more different type charts

Having this suggestion,
https://forums.oracle.com/forums/thread.jspa?threadID=2435573&tstart=0
I have tryed to use StackPane but second chart replace first one.
How to plot two or more different Chart (as in my example) in the same graph?
Here is my code
public class XyChartInSplitStackpane extends Application {
SplitPane splitPane1 = null;
#Override
public void start(Stage stage) {
stage.setTitle("Line plot");
final CategoryAxis xAxis1 = new CategoryAxis();
final NumberAxis yAxis1 = new NumberAxis();
yAxis1.setTickUnit(1);
yAxis1.setPrefWidth(35);
yAxis1.setMinorTickCount(10);
yAxis1.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis1){
#Override
public String toString(Number object){
String label;
label = String.format("%7.2f", object.floatValue());
return label;
}
});
final BarChart<String, Number>barChart1 = new BarChart<String, Number>(xAxis1, yAxis1);
barChart1.setAlternativeRowFillVisible(false);
barChart1.setLegendVisible(false);
barChart1.setAnimated(false);
XYChart.Series series1 = new XYChart.Series();
series1.getData().add(new XYChart.Data("Jan", 1));
series1.getData().add(new XYChart.Data("Feb", 2));
series1.getData().add(new XYChart.Data("Mar", 1.5));
series1.getData().add(new XYChart.Data("Apr", 3));
series1.getData().add(new XYChart.Data("May", 2.5));
series1.getData().add(new XYChart.Data("Jun", 5));
series1.getData().add(new XYChart.Data("Jul", 4));
series1.getData().add(new XYChart.Data("Aug", 8));
series1.getData().add(new XYChart.Data("Sep", 6.5));
series1.getData().add(new XYChart.Data("Oct", 13));
series1.getData().add(new XYChart.Data("Nov", 10));
series1.getData().add(new XYChart.Data("Dec", 20));
barChart1.getData().addAll(series1);
final CategoryAxis xAxis2 = new CategoryAxis();
final NumberAxis yAxis2 = new NumberAxis(1, 21,0.1);
yAxis2.setTickUnit(1);
yAxis2.setPrefWidth(35);
yAxis2.setMinorTickCount(10);
yAxis2.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis2){
#Override
public String toString(Number object){
String label;
label = String.format("%7.2f", object.floatValue());
return label;
}
});
final LineChart<String, Number>lineChart2 = new LineChart<String, Number>(xAxis2, yAxis2);
lineChart2.setCreateSymbols(false);
lineChart2.setAlternativeRowFillVisible(false);
lineChart2.setLegendVisible(false);
lineChart2.setAnimated(false);
XYChart.Series series2 = new XYChart.Series();
series2.getData().add(new XYChart.Data("Jan", 2));
series2.getData().add(new XYChart.Data("Feb", 10));
series2.getData().add(new XYChart.Data("Mar", 8));
series2.getData().add(new XYChart.Data("Apr", 4));
series2.getData().add(new XYChart.Data("May", 7));
series2.getData().add(new XYChart.Data("Jun", 5));
series2.getData().add(new XYChart.Data("Jul", 4));
series2.getData().add(new XYChart.Data("Aug", 8));
series2.getData().add(new XYChart.Data("Sep", 16.5));
series2.getData().add(new XYChart.Data("Oct", 13.9));
series2.getData().add(new XYChart.Data("Nov", 17));
series2.getData().add(new XYChart.Data("Dec", 10));
Set<Node> nodes1 = barChart1.lookupAll(".series0");
for (Node n: nodes1) {
n.setStyle("-fx-blend-mode: src-over");
}
lineChart2.getData().addAll(series2);
Set<Node> nodes2 = lineChart2.lookupAll(".series0");
for (Node n: nodes2) {
n.setStyle("-fx-stroke: red; -fx-background-color: red, white; -fx-blend-mode: src-over; -fx-opacity: 0.5");
}
splitPane1 = new SplitPane();
StackPane stackpane = new StackPane();
stackpane.getChildren().add(barChart1);
stackpane.getChildren().add(lineChart2);
splitPane1.setOrientation(Orientation.VERTICAL);
splitPane1.getItems().addAll(stackpane);
splitPane1.setDividerPosition(0, 1);
Scene scene = new Scene(splitPane1, 800, 600);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
As far as i can see your adding the series to two different charts
ie.
lineChart2.getData().addAll(series2); & barChart1.getData().addAll(series1);
However if this is intentional all you need to do to add the other data to one of the charts is to simply use: barChart1.getData().addAll(series1, series2);

JavaFX 2.x : how to move both panes?

My class below plots two charts in a splitpane.
By left mouse click and drag the upper line chart moves left/right (and up/down).
I would like to move both panes together left/right when I click and drag with left mouse on the upper graph: how to accomplish this?
Thanks
public class XyChartInSplitMove extends Application {
SplitPane splitPane1 = null;
BorderPane pane;
BorderPane pane2;
XYChart.Series series1 = new XYChart.Series();
XYChart.Series series2 = new XYChart.Series();
SimpleDoubleProperty rectinitX = new SimpleDoubleProperty();
SimpleDoubleProperty rectinitY = new SimpleDoubleProperty();
#Override
public void start(Stage stage) {
final NumberAxis xAxis = new NumberAxis(1, 12, 1);
final NumberAxis yAxis = new NumberAxis(0.53000, 0.53910, 0.0005);
xAxis.setAnimated(false);
yAxis.setAnimated(false);
yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis) {
#Override
public String toString(Number object) {
return String.format("%7.5f", object);
}
});
final LineChart<Number, Number> lineChart1 = new LineChart<Number, Number>(xAxis, yAxis);
lineChart1.setCreateSymbols(false);
lineChart1.setAlternativeRowFillVisible(false);
lineChart1.setAnimated(false);
lineChart1.setLegendVisible(false);
series1.getData().add(new XYChart.Data(1, 0.53185));
series1.getData().add(new XYChart.Data(2, 0.532235));
series1.getData().add(new XYChart.Data(3, 0.53234));
series1.getData().add(new XYChart.Data(4, 0.538765));
series1.getData().add(new XYChart.Data(5, 0.53442));
series1.getData().add(new XYChart.Data(6, 0.534658));
series1.getData().add(new XYChart.Data(7, 0.53023));
series1.getData().add(new XYChart.Data(8, 0.53001));
series1.getData().add(new XYChart.Data(9, 0.53589));
series1.getData().add(new XYChart.Data(10, 0.53476));
series1.getData().add(new XYChart.Data(11, 0.530123));
series1.getData().add(new XYChart.Data(12, 0.531035));
lineChart1.getData().addAll(series1);
pane = new BorderPane();
pane.setCenter(lineChart1);
splitPane1 = new SplitPane();
splitPane1.setOrientation(Orientation.VERTICAL);
splitPane1.getItems().addAll(pane);
splitPane1.setDividerPosition(0, 1);
Platform.runLater(new Runnable() {
#Override
public void run() {
double percSplit;
ObservableList<SplitPane.Divider> splitDiv = splitPane1.getDividers();
percSplit = 1/(double)(splitDiv.size()+1);
for (int i = 0; i< splitDiv.size(); i++) {
splitPane1.setDividerPosition(i, percSplit);
percSplit += 1/(double)(splitDiv.size()+1);
}
}
});
//BarChart
final CategoryAxis xAxis2 = new CategoryAxis();
final NumberAxis yAxis2 = new NumberAxis();
yAxis2.setTickUnit(1);
yAxis2.setPrefWidth(35);
yAxis2.setMinorTickCount(10);
yAxis2.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis2){
#Override
public String toString(Number object){
String label;
label = String.format("%7.2f", object.floatValue());
return label;
}
});
final BarChart<String, Number>BarChart2 = new BarChart<String, Number>(xAxis2, yAxis2);
BarChart2.setAlternativeRowFillVisible(false);
BarChart2.setLegendVisible(false);
BarChart2.setAnimated(false);
XYChart.Series series2 = new XYChart.Series();
series2.getData().add(new XYChart.Data("Jan", 1));
series2.getData().add(new XYChart.Data("Feb", 3));
series2.getData().add(new XYChart.Data("Mar", 1.5));
series2.getData().add(new XYChart.Data("Apr", 3));
series2.getData().add(new XYChart.Data("May", 4.5));
series2.getData().add(new XYChart.Data("Jun", 5));
series2.getData().add(new XYChart.Data("Jul", 4));
series2.getData().add(new XYChart.Data("Aug", 8));
series2.getData().add(new XYChart.Data("Sep", 16.5));
series2.getData().add(new XYChart.Data("Oct", 13.9));
series2.getData().add(new XYChart.Data("Nov", 17));
series2.getData().add(new XYChart.Data("Dec", 20));
BarChart2.getData().addAll(series2);
Platform.runLater(new Runnable() {
#Override
public void run() {
double percSplit;
splitPane1.getItems().addAll(BarChart2);
ObservableList<SplitPane.Divider> splitDiv = splitPane1.getDividers();
percSplit = 1/(double)(splitDiv.size()+1);
for (int i = 0; i< splitDiv.size(); i++) {
splitPane1.setDividerPosition(i, percSplit);
percSplit += 1/(double)(splitDiv.size()+1);
}
}
});
Scene scene = new Scene(splitPane1, 800, 600);
stage.setScene(scene);
pane.setOnMouseClicked(mouseHandler);
pane.setOnMouseDragged(mouseHandler);
pane.setOnMouseEntered(mouseHandler);
pane.setOnMouseExited(mouseHandler);
pane.setOnMouseMoved(mouseHandler);
pane.setOnMouseReleased(mouseHandler);
stage.show();
}
EventHandler<MouseEvent> mouseHandler = new EventHandler<MouseEvent>(){
#Override
public void handle(MouseEvent mouseEvent) {
if (mouseEvent.getEventType() == MouseEvent.MOUSE_DRAGGED || mouseEvent.getEventType() == MouseEvent.MOUSE_MOVED){
LineChart<Number, Number> lineChart = (LineChart<Number, Number>) pane.getCenter();
NumberAxis yAxis = (NumberAxis) lineChart.getYAxis();
NumberAxis xAxis = (NumberAxis) lineChart.getXAxis();
double Tgap = xAxis.getWidth()/(xAxis.getUpperBound() - xAxis.getLowerBound());
double newXlower=xAxis.getLowerBound(), newXupper=xAxis.getUpperBound();
double newYlower=yAxis.getLowerBound(), newYupper=yAxis.getUpperBound();
double xAxisShift = getSceneShift(xAxis);
double yAxisShift = getSceneShift(yAxis);
double yAxisStep=yAxis.getHeight()/(yAxis.getUpperBound()-yAxis.getLowerBound());
double CurrentPrice=yAxis.getUpperBound()-((mouseEvent.getY()-yAxisShift)/yAxisStep);
double Delta=0.3;
if(mouseEvent.getEventType() == MouseEvent.MOUSE_DRAGGED){
if(rectinitX.get() < mouseEvent.getX()){
newXlower=xAxis.getLowerBound()-Delta;
newXupper=xAxis.getUpperBound()-Delta;
}
else if(rectinitX.get() > mouseEvent.getX()){
newXlower=xAxis.getLowerBound()+Delta;
newXupper=xAxis.getUpperBound()+Delta;
}
xAxis.setLowerBound( newXlower );
xAxis.setUpperBound( newXupper );
//========== Y-Axis Moving ============================
if(rectinitY.get() < mouseEvent.getY()){
newYlower=yAxis.getLowerBound()+Delta/1000;
newYupper=yAxis.getUpperBound()+Delta/1000;
}
else if(rectinitY.get() > mouseEvent.getY()){
newYlower=yAxis.getLowerBound()-Delta/1000;
newYupper=yAxis.getUpperBound()-Delta/1000;
}
yAxis.setLowerBound(newYlower);
yAxis.setUpperBound(newYupper);
}
rectinitX.set(mouseEvent.getX());
rectinitY.set(mouseEvent.getY());
if(mouseEvent.getEventType() == MouseEvent.MOUSE_MOVED && mouseEvent.getY()>yAxisShift && mouseEvent.getY()<yAxisShift+yAxis.getHeight() && mouseEvent.getX()>xAxisShift && mouseEvent.getX()<xAxisShift+xAxis.getWidth()){
double XX=((mouseEvent.getX() - xAxisShift) / Tgap) + xAxis.getLowerBound();
double YY=CurrentPrice;
int XLB=(int) xAxis.getLowerBound();
int XUB=(int) xAxis.getUpperBound();
}
}
}
};
private static double getSceneShift(Node node) {
double shift = 0;
do {
shift += node.getLayoutX();
node = node.getParent();
} while (node != null);
return shift;
}
private static String getHIstLOstY(XYChart.Series S,int XLowerBound,int XUpperBound) {
double ValLOst=1000000;
double ValHIst=-1000000;
for(int i=XLowerBound; i<XUpperBound; i++){
double P=GetPrice(S,i);
if(ValHIst<P){
ValHIst=P;
}
if(ValLOst>P){
ValLOst=P;
}
}
return Double.toString(ValLOst) + "," + Double.toString(ValHIst);
}
private static double GetPrice(XYChart.Series S,int IX) {
Object SVal=S.getData().get(IX);
String Temp=SVal.toString().replaceAll("Data", "");
Temp=Temp.replace("[", "");
Temp=Temp.replace("]", "");
String[] TempArray=Temp.split(",");
return Double.parseDouble(TempArray[1]);
}
public static void main(String[] args) {
launch(args);
}
}
Option 1 (simple):
Imagine you have the same mouse handlers in both charts, then you can drag both charts separately. In this circumstances you need to update mouse handlers in top chart to call same events in bottom chart (minus y coordinate difference)
Option 2 (good):
Bind bottom chart axis ranges to top chart ones (yes, it may involve some complex math) as you did it for chart's starting states. So on update of top chart bottom chart will get updated automatically.

emacs - replace C++ comment (//) wth C comment (/* */)

Is there any easy way to replace a C++ comment (//) with a C comment (/* */) in emacs?
Has someone written an elisp function to do it?
Or can some sort of clever regexp be applied?
use query-replace-regex or similar function with following search string: ^\(.*?\)//\(.*\)$ and following replacement string \1/* \2 */
This C program converts all the consecutive occurrences of '//' comments in a file sample.txt with '/* ...*/' and saves result to output.txt.
#include <stdio.h>
#include<string.h>
void trimLeading(char * string);
int main(int argc, char* argv[])
{
FILE* file = fopen("sample.txt", "r");
FILE* fp = fopen("output.txt", "w"); //to create file if it does not exist and to empty file if it exists.
fclose(fp);
if(file==NULL) {
perror("Error opening file sample.txt.");
}
if(fp==NULL) {
perror("Error opening file output.txt.");
}
/* should check the result */
long pos;
char line[256];
char buff[256];
int flag=0; //flag=1,when multi-line comment occurs in input file.
int line_length=0;
while (fgets(line, sizeof(line), file)) {
trimLeading(line);
while((strlen(line)==0)){
fgets(line,sizeof(line),file);
trimLeading(line);
}
//line_length=strlen(line);
//printf("%d",line_length);
strcpy(buff,line);
if(strstr(buff,"//")){
trimLeading(buff);
//printf("\nbuff=%s,line=%s,flag=%d\n",buff,line,flag);
if((buff[0]=='/')&&(buff[1]=='/')) {
/*******************/
if(flag==0){
/*look at next line*/
pos = ftell(file);
fgets(line,sizeof(line),file);
trimLeading(line);
//line_length=strlen(line);
//printf("%d",line_length);
while((strlen(line)==0)){
fgets(line,sizeof(line),file);
trimLeading(line);
}
fseek( file,pos, SEEK_SET );
//printf("line==%s,flag=%d",line,flag);
if((line[0]=='/')&&(line[1]=='/') ){
flag=1;
buff[0]='/';
buff[1]='*';
/*write output to file output.txt*/
fp = fopen("output.txt", "a");
fseek( fp,0, SEEK_END);
fprintf(fp, "%s",buff);
fclose(fp);
/************/
printf("%s", buff);
} else{
/*write output to file output.txt*/
fp = fopen("output.txt", "a");
fseek( fp,0, SEEK_END);
fprintf(fp, "%s",buff);
fclose(fp);
/************/
printf("%s",buff);
}
}else if(flag==1){
buff[0]='*';
buff[1]='*';
/*look at next line*/
pos = ftell(file);
fgets(line,sizeof(line),file);
trimLeading(line);
//line_length=strlen(line);
//printf("%d",line_length);
while((strlen(line)==0)){
fgets(line,sizeof(line),file);
trimLeading(line);
}
fseek( file,pos, SEEK_SET );
//printf("line==%s,flag=%d",line,flag);
//printf("line[0]=%c,line[1]=%c",line[0],line[1]);
if(!((line[0]=='/')&&(line[1]=='/') )){
strcat(buff,"*/ \n");
flag=0;
//printf("\nFLAG1==%d\n",flag);
}
/*write output to file output.txt*/
fp = fopen("output.txt", "a");
fseek( fp,0, SEEK_END);
fprintf(fp, "%s",buff);
fclose(fp);
/************/
printf("%s", buff);
}
} else{
/*write output to file output.txt*/
fp = fopen("output.txt", "a");
fseek( fp,0, SEEK_END);
fprintf(fp, "%s",buff);
fclose(fp);
/************/
printf("%s",buff);
flag=0;
//printf("\nFLAG2==%d\n",flag);
}
} else {
pos = ftell(file);
trimLeading(line);
line_length=strlen(line);
//printf("%d",line_length);
while((strlen(line)==0)){
fgets(line,sizeof(line),file);
trimLeading(line);
}
fseek( file,pos, SEEK_SET );
//printf("line==%s,flag=%d",line,flag);
/*write output to file output.txt*/
fp = fopen("output.txt", "a");
fseek( fp,0, SEEK_END);
fprintf(fp, "%s",buff);
fclose(fp);
/************/
printf("%s",buff);
flag=0;
//printf("\nFLAG3==%d\n",flag);
}
}
fclose(file);
return 0;
}
void trimLeading(char * string)
{
int lastSpaceIndex, i, j;
lastSpaceIndex = 0;
/* Finds the last index of whitespace character */
while(string[lastSpaceIndex] == ' ' || string[lastSpaceIndex] == '\t' || string[lastSpaceIndex] == '\n')
{
lastSpaceIndex++;
}
/* Shifts all trailing characters to its left */
i = 0;
while(string[i + lastSpaceIndex] != '\0')
{
string[i] = string[i + lastSpaceIndex];
i++;
}
string[i] = '\0'; //Make sure that string is NULL terminated
}
Sample.txt:
#include<stdio.h>
int main()
{
int a=10,b=20,c=0;
//samplea
//sampleb
//samplec
///////sampled
c=a+b;
//samplee
return 0;
}

Align itextsharp table

Does anyone know how to left align a iTextSharp table?
You can use the PdfPTable's HorizontalAlignment property.
Here's a C# test method you can use to experiment:
private void TestTableCreation() {
using (FileStream fs = new FileStream("TableTest.pdf", FileMode.Create)) {
Document doc = new Document(PageSize.A4);
PdfWriter.GetInstance(doc, fs);
doc.Open();
PdfPTable table = new PdfPTable(4);
table.WidthPercentage = 50.0f;
// Options: Element.ALIGN_LEFT (or 0), Element.ALIGN_CENTER (1), Element.ALIGN_RIGHT (2).
table.HorizontalAlignment = Element.ALIGN_LEFT;
for (int i = 1; i <= 20; i++) {
PdfPCell cell = new PdfPCell(new Phrase(String.Format("Cell # {0}", i)));
cell.FixedHeight = 30.0f;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cell);
}
doc.Add(table);
doc.Close();
}
}
table.HorizontalAlignment = 1;
1:center
0:left
2:right
There are two ways of doing it:
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.HorizontalAlignment = 0;