#29611

Hi,
I’ll post another error example.
I’m trying to print a pdf with 100 lines, a header and a footer.
Some lines (n 33, 85) are not printed and the text overwrite header and footer.
Any idea??

import it.solarisistemi.base.ErroreApplicativo;
import it.solarisistemi.base.logs.LogEntry;

import java.awt.Insets;
import java.awt.Rectangle;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.security.InvalidParameterException;
import java.util.ArrayList;

import org.zefer.pd4ml.PD4Constants;
import org.zefer.pd4ml.PD4ML;
import org.zefer.pd4ml.PD4PageMark;

public class ProvaPD4ML {

public static void main(String[] args) throws ErroreApplicativo {
PD4ML pd4ml = new PD4ML();

pd4ml.setPageInsetsMM(new Insets(15, 0, 15, 0));

pd4ml.setPageSize(PD4Constants.A4); // landscape page orientation
pd4ml.protectPhysicalUnitDimensions();
pd4ml.setHtmlWidth(780);

/*
<hr class="bbcode_rule" />
Header
<hr class="bbcode_rule" />
*/
PD4PageMark header = new PD4PageMark();
header.setAreaHeight(-1);
header.setFontSize(20);
header.setPagesToSkip(1);
String dir = getFileHttpProtocol(getImgTempPath(), true);
header.setWatermark(dir, new Rectangle(10, 10, 200, 100), 255);

/*
<hr class="bbcode_rule" />
Footer
<hr class="bbcode_rule" />
*/
PD4PageMark footer = new PD4PageMark();
footer.setAreaHeight(-1);
footer.setFontSize(20);
footer.setPagesToSkip(1);
footer.setWatermark(dir, new Rectangle(10, 700, 200, 100), 255);

pd4ml.setPageHeader(header);
pd4ml.setPageFooter(footer);

ArrayList<String> styles = new ArrayList<String>();

StringBuffer pageStyle = new StringBuffer("span.indirizzo {");
pageStyle.append("position: absolute; top: 50mm; left: 120mm;");
pageStyle.append("border: 1px solid red;");
pageStyle.append("}");
styles.add(pageStyle.toString());

pageStyle = new StringBuffer("span.lettera {");
pageStyle.append("position: absolute; top: 90mm; left: 15mm;");
pageStyle.append("border: 1px solid blue;");
pageStyle.append("}");
styles.add(pageStyle.toString());

if (styles != null) {

for (int i = 0; i < styles.size(); i++) {
if (styles.get(i) != null) {
pd4ml.addStyle(styles.get(i), true);
}
}
}

StringBuffer letteraHtml = new StringBuffer("");
letteraHtml.append("<span class='indirizzo'>");
letteraHtml.append("SOLARI SISTEMI");
letteraHtml.append(" VIA CREMONA, 10");
letteraHtml.append(" 25025 BRESCIA BS");
letteraHtml.append("</span>");

letteraHtml.append("<span class='lettera'>");
for (int i = 0; i < 100; i++) {
letteraHtml.append(" LoremIposum " + i);
}
letteraHtml.append("</span>");

InputStream is = new ByteArrayInputStream(letteraHtml.toString().getBytes());
InputStreamReader isr = new InputStreamReader(is);

FileOutputStream outs = null;
PrintStream ps = null;
ByteArrayOutputStream outs1 = new ByteArrayOutputStream(16000);

try {
File myfile = new File("C:\tmp\pd4ml.pdf");
if (myfile.exists()) {
myfile.delete();
myfile = new File("C:\tmp\pd4ml.pdf");
}

outs = new FileOutputStream(myfile);
ps = new PrintStream(outs);

pd4ml.render(isr, outs1);
ps = new PrintStream(outs);
ps.write(outs1.toByteArray());
outs.flush();
System.out.println("Fine");

} catch (InvalidParameterException e) {
e.printStackTrace();
throw new ErroreApplicativo(e);
} catch (IOException e) {
e.printStackTrace();
throw new ErroreApplicativo(e);
} finally {
if (outs != null) {
try {
outs.close();
} catch (IOException e) {
;
}
}
if (ps != null) {
ps.close();
}
}

}

public static String getFileHttpProtocol(String path, boolean utfUrlEncode) {
String url = path.replace(':', '|').replaceAll("/", File.separator).replaceAll("\\", "\\\\");
url = "file:///" + url;
return url.trim();
}

public static String getImgTempPath() {
String path = "";

String tempDir = System.getProperty("java.io.tmpdir");
LogEntry.debug("PDFI - System temp directory :: " + tempDir);
File fileTemp = new File(tempDir + File.separatorChar + "solari.png");
if (fileTemp.exists()) {
path = fileTemp.getAbsolutePath();
}
return path.trim();
}

}