I am generating PDF file using Aspose.Cells. And I have noticed that right margin of the page is wider then left margin even if sheet.getPageSetup().getLeftMargin(); and sheet1.getPageSetup().getRightMargin(); return same values.
This is full java code which will recreate issue. I also attached java code in zip file
import com.aspose.cells.*;
public class Test {
private static boolean doneLicense;
public static void main(String[] args) throws Exception {
setLicense();
Workbook wb = new Workbook();
String[][] data = { { “88”, “44”, “12” }, { “23”, “77”, “77” }, { “55”, “78”, “80” }, };
String[] categoryData = { “one”, “two”, “three” };
String[] series = { “Some text here”, “Somer long text here 38838” , “Some another very long name 0032841399”};
Worksheet sheet2 = wb.getWorksheets().add(“sheet2”);
int index2 = sheet2.getCharts().add(ChartType.COLUMN, 0, 0, 20, 20);
Chart chart2 = sheet2.getCharts().get(index2);
buildGraph(chart2, data, categoryData, series, “Some Title 2”);
setChartWidth(chart2);
wb.save(“chart.pdf”, FileFormatType.PDF);
System.out.println(“Done!”);
}
public static void buildGraph(Chart chart, String[][] data, String[] categoryData, String[] series, String title) throws Exception {
// format graph
SeriesCollection nSeries = chart.getNSeries();
Legend legend = chart.getLegend();
legend.setPosition(LegendPositionType.BOTTOM);
legend.setAutomaticSize(true);
legend.setAutoScaleFont(true);
chart.getTitle().setText(title);
chart.getTitle().setShadow(true);
chart.getCategoryAxis().setTickLabelPosition(TickLabelPositionType.LOW);
chart.getCategoryAxis().getTickLabels().setRotationAngle(90);
// add data and collect categories information
for (int r = 0; r < data.length; r++) {
String[] rowData = data[r];
int index = nSeries.add(getSeriesValuesStringVersion(rowData), true);
nSeries.get(index).setName(series[r]);
}
nSeries.setCategoryData(getSeriesValuesStringVersion(categoryData));
chart.calculate();
}
public static String getSeriesValuesStringVersion(String[] data) {
StringBuilder builder = new StringBuilder("{");
boolean firstElement = true;
for (String d : data) {
if (firstElement) {
builder.append(d);
firstElement = false;
} else {
builder.append(", “);
builder.append(d);
}
}
builder.append(”}");
return builder.toString();
}
private static void setChartWidth(Chart chart) {
ChartShape shape = chart.getChartObject();
shape.setWidth(3000);
shape.setHeight(951);
}
/
<strong>* Loads the Aspose license.
*
* @throws Exception If we can’t load the license.
<em>/
private static void setLicense() throws Exception {</em></strong>
if (doneLicense) {
return; // Only need to do it once.
}
// Get the Aspose license file, and load it into Aspose.
License license = new License();
license.setLicense(“Aspose.Java.lic”);
doneLicense = true;
}
}import com.aspose.cells.;
public class Test {
private static boolean doneLicense;
public static void main(String[] args) throws Exception {
setLicense();
Workbook wb = new Workbook();
String[][] data = { { “88”, “44”, “12” }, { “23”, “77”, “77” }, { “55”, “78”, “80” }, };
String[] categoryData = { “one”, “two”, “three” };
String[] series = { “Some text here”, “Somer long text here 38838” , “Some another very long name 0032841399”};
Worksheet sheet2 = wb.getWorksheets().add(“sheet2”);
int index2 = sheet2.getCharts().add(ChartType.COLUMN, 0, 0, 20, 20);
Chart chart2 = sheet2.getCharts().get(index2);
buildGraph(chart2, data, categoryData, series, “Some Title 2”);
setChartWidth(chart2);
wb.save(“chart.pdf”, FileFormatType.PDF);
System.out.println(“Done!”);
}
public static void buildGraph(Chart chart, String[][] data, String[] categoryData, String[] series, String title) throws Exception {
// format graph
SeriesCollection nSeries = chart.getNSeries();
Legend legend = chart.getLegend();
legend.setPosition(LegendPositionType.BOTTOM);
legend.setAutomaticSize(true);
legend.setAutoScaleFont(true);
chart.getTitle().setText(title);
chart.getTitle().setShadow(true);
chart.getCategoryAxis().setTickLabelPosition(TickLabelPositionType.LOW);
chart.getCategoryAxis().getTickLabels().setRotationAngle(90);
// add data and collect categories information
for (int r = 0; r < data.length; r++) {
String[] rowData = data[r];
int index = nSeries.add(getSeriesValuesStringVersion(rowData), true);
nSeries.get(index).setName(series[r]);
}
nSeries.setCategoryData(getSeriesValuesStringVersion(categoryData));
chart.calculate();
}
public static String getSeriesValuesStringVersion(String[] data) {
StringBuilder builder = new StringBuilder("{");
boolean firstElement = true;
for (String d : data) {
if (firstElement) {
builder.append(d);
firstElement = false;
} else {
builder.append(", “);
builder.append(d);
}
}
builder.append(”}");
return builder.toString();
}
private static void setChartWidth(Chart chart) {
ChartShape shape = chart.getChartObject();
shape.setWidth(3000);
shape.setHeight(951);
}
/
* Loads the Aspose license.
*
* @throws Exception If we can’t load the license.
*/
private static void setLicense() throws Exception {
if (doneLicense) {
return; // Only need to do it once.
}
// Get the Aspose license file, and load it into Aspose.
License license = new License();
license.setLicense(“Aspose.Java.lic”);
doneLicense = true;
}
}