Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #26970

    Hi,
    I want to create a pdf like a classic paper mail starting with an html page with adress and text div box, like this:

    VALERIO ROSSI
    AVENUE V. HUGO 80
    31100 CROWLEY UK
    TextTextTextTextTextTextTextTextTextTextTextText
    TextTextTextTextTextTextTextTextTextTextTextText

    I set an pd4ml header and footer with Java code.
    When I try to convert this (with java), header and footer overwrite text (in a nutshell, pages don’t mantain margins).

    If I remove div, it works fine but I can’t position text correctly.

    What’s wrong?

    Thanks in advance

    [attachment=0:3hr621xw]Prova.png[/attachment:3hr621xw]

    #29609

    Could you please also publish a Java code snippet with your PD4ML API calls?

    #29610

    This is java code

    #29612

    //**************************************************<br /> // Get Pd4ml and rendering<br /> //***************************************************<br /> <br /> /*<br /> * Create Box styles<br /> */<br /> // [....]<br /> // Mail Text<br /> StringBuffer testoStyle = new StringBuffer("span.mailTextAddress {");<br /> testoStyle.append("position:absolute;");<br /> testoStyle.append("width: " + (width - testoMargineS - testoMargineD) + "mm;");<br /> testoStyle.append("top: " + testoMargineSup + "mm;");<br /> testoStyle.append("left: " + testoMargineS + "mm;");<br /> testoStyle.append("right: " + testoMargineD + "mm;");<br /> testoStyle.append("}");<br /> stili.add(testoStyle.toString());<br /> // Address Box<br /> StringBuffer boxAddressStyle = new StringBuffer("span.boxAddress {");<br /> boxAddressStyle.append(" width: " + pdfmlay.getPdfmIndDestiDimX().intValue() + "mm;");<br /> boxAddressStyle.append(" height: " + pdfmlay.getPdfmIndDestiDimY().intValue() + "mm;");<br /> boxAddressStyle.append("position: absolute;");<br /> boxAddressStyle.append("top:" + destMargineSup + "mm;");<br /> boxAddressStyle.append("left:" + destMargineSx + "mm;");<br /> boxAddressStyle.append("}");<br /> stili.add(boxAddressStyle.toString());<br /> <br /> // Create Pd4ml object<br /> PD4ML pd4ml = getPd4ml(sessionDo, PD4Constants.A4, stili.toArray(new String[stili.size()]), null, null);<br /> <br /> /*/*/<br /> InputStream is = new ByteArrayInputStream(input.getHTML().getBytes());<br /> InputStreamReader isr = new InputStreamReader(is);<br /> try {<br /> pd4ml.render(isr, outs1);<br /> ps = new PrintStream(outs);<br /> ps.write(outs1.toByteArray());<br /> outs.flush();<br /> } catch (InvalidParameterException e) {<br /> e.printStackTrace();<br /> throw new ErroreApplicativo(e);<br /> } catch (IOException e) {<br /> e.printStackTrace();<br /> throw new ErroreApplicativo(e);<br /> } finally {<br /> if (ps != null) {<br /> ps.close();<br /> }<br /> }<br /> <br /> <br /> <br /> <br /> //**************************************************<br /> // Build Pd4ml<br /> //***************************************************<br /> public static PD4ML getPd4ml(MainSessionDo sessionDo, java.awt.Dimension pageSize, String[] styles, Rectangle myHeader, Rectangle myFooter)<br /> throws ErroreApplicativo {<br /> PD4ML pd4ml = new PD4ML();<br /> pd4ml.setPageInsets(new Insets(80, 40, 80, 60));<br /> <br /> pd4ml.setPageSize(pageSize); // landscape page orientation<br /> pd4ml.protectPhysicalUnitDimensions();<br /> pd4ml.setHtmlWidth(780);<br /> <br /> <br /> /* <hr class="bbcode_rule" /> Header <hr class="bbcode_rule" /> */<br /> PD4PageMark header = new PD4PageMark();<br /> ImgInfo infoH = getTempImg(sessionDo, input, "H", letpar); // get img header<br /> String dir = infoH.getImgPath();<br /> if (dir.trim().length() > 0) {<br /> dir = getFileHttpProtocol(dir, false);<br /> header.setAreaHeight(-1);<br /> <br /> if (myHeader == null) {<br /> myHeader = new Rectangle(infoH.getPosX().intValue(), infoH.getPosY().intValue(), infoH.getWidth().intValue(), infoH.getHeight().intValue());<br /> } else {<br /> if (infoH.getWidth().intValue() <= myHeader.getWidth() && infoH.getHeight().intValue() <= myHeader.getHeight())<br /> myHeader.setSize(infoH.getWidth().intValue(), infoH.getHeight().intValue());<br /> }<br /> header.setWatermark(dir, myHeader, 255);<br /> }<br /> /* <hr class="bbcode_rule" /> Footer <hr class="bbcode_rule" /> */<br /> PD4PageMark footer = new PD4PageMark();<br /> ImgInfo infoF = getTempImg(sessionDo, input, "F", letpar); // get img footer<br /> footer.setAreaHeight(-1);<br /> footer.setFontSize(20);<br /> footer.setPagesToSkip(1);<br /> footer.setTitleAlignment(PD4PageMark.RIGHT_ALIGN);<br /> footer.setPageNumberAlignment(PD4PageMark.LEFT_ALIGN);<br /> dir = infoF.getImgPath();<br /> if (dir.trim().length() > 0) {<br /> dir = getFileHttpProtocol(dir, false);<br /> <br /> if (myFooter == null) {<br /> myFooter = new Rectangle(infoF.getPosX().intValue(), infoF.getPosY().intValue(), infoF.getWidth().intValue(), infoF.getHeight().intValue());<br /> } else {<br /> if (infoH.getWidth().intValue() <= myFooter.getWidth() && infoH.getHeight().intValue() <= myFooter.getHeight())<br /> myFooter.setSize(infoH.getWidth().intValue(), infoH.getHeight().intValue());<br /> }<br /> footer.setWatermark(dir, myFooter, 255);<br /> }<br /> <br /> pd4ml.setPageHeader(header);<br /> pd4ml.setPageFooter(footer);<br /> <br /> // Add styles<br /> if (styles != null) {<br /> for (int i = 0; i < styles.length; i++) {<br /> if (styles<i> != null) {<br /> pd4ml.addStyle(styles<i>, true);<br /> }<br /> }<br /> }<br /> <br /> return pd4ml;<br /> }<br /> <br /> <br /> <br />

    #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??

    <br /> import it.solarisistemi.base.ErroreApplicativo;<br /> import it.solarisistemi.base.logs.LogEntry;<br /> <br /> import java.awt.Insets;<br /> import java.awt.Rectangle;<br /> import java.io.ByteArrayInputStream;<br /> import java.io.ByteArrayOutputStream;<br /> import java.io.File;<br /> import java.io.FileOutputStream;<br /> import java.io.IOException;<br /> import java.io.InputStream;<br /> import java.io.InputStreamReader;<br /> import java.io.PrintStream;<br /> import java.security.InvalidParameterException;<br /> import java.util.ArrayList;<br /> <br /> import org.zefer.pd4ml.PD4Constants;<br /> import org.zefer.pd4ml.PD4ML;<br /> import org.zefer.pd4ml.PD4PageMark;<br /> <br /> public class ProvaPD4ML {<br /> <br /> public static void main(String[] args) throws ErroreApplicativo {<br /> PD4ML pd4ml = new PD4ML();<br /> <br /> pd4ml.setPageInsetsMM(new Insets(15, 0, 15, 0));<br /> <br /> pd4ml.setPageSize(PD4Constants.A4); // landscape page orientation<br /> pd4ml.protectPhysicalUnitDimensions();<br /> pd4ml.setHtmlWidth(780);<br /> <br /> /* <hr class="bbcode_rule" /> Header <hr class="bbcode_rule" /> */<br /> PD4PageMark header = new PD4PageMark();<br /> header.setAreaHeight(-1);<br /> header.setFontSize(20);<br /> header.setPagesToSkip(1);<br /> String dir = getFileHttpProtocol(getImgTempPath(), true);<br /> header.setWatermark(dir, new Rectangle(10, 10, 200, 100), 255);<br /> <br /> /* <hr class="bbcode_rule" /> Footer <hr class="bbcode_rule" /> */<br /> PD4PageMark footer = new PD4PageMark();<br /> footer.setAreaHeight(-1);<br /> footer.setFontSize(20);<br /> footer.setPagesToSkip(1);<br /> footer.setWatermark(dir, new Rectangle(10, 700, 200, 100), 255);<br /> <br /> pd4ml.setPageHeader(header);<br /> pd4ml.setPageFooter(footer);<br /> <br /> ArrayList<String> styles = new ArrayList<String>();<br /> <br /> StringBuffer pageStyle = new StringBuffer("span.indirizzo {");<br /> pageStyle.append("position: absolute; top: 50mm; left: 120mm;");<br /> pageStyle.append("border: 1px solid red;");<br /> pageStyle.append("}");<br /> styles.add(pageStyle.toString());<br /> <br /> pageStyle = new StringBuffer("span.lettera {");<br /> pageStyle.append("position: absolute; top: 90mm; left: 15mm;");<br /> pageStyle.append("border: 1px solid blue;");<br /> pageStyle.append("}");<br /> styles.add(pageStyle.toString());<br /> <br /> if (styles != null) {<br /> <br /> for (int i = 0; i < styles.size(); i++) {<br /> if (styles.get(i) != null) {<br /> pd4ml.addStyle(styles.get(i), true);<br /> }<br /> }<br /> }<br /> <br /> StringBuffer letteraHtml = new StringBuffer("");<br /> letteraHtml.append("<span class='indirizzo'>");<br /> letteraHtml.append("SOLARI SISTEMI");<br /> letteraHtml.append("<br /> VIA CREMONA, 10");<br /> letteraHtml.append("<br /> 25025 BRESCIA BS");<br /> letteraHtml.append("</span>");<br /> <br /> letteraHtml.append("<span class='lettera'>");<br /> for (int i = 0; i < 100; i++) {<br /> letteraHtml.append("<br /> LoremIposum " + i);<br /> }<br /> letteraHtml.append("</span>");<br /> <br /> InputStream is = new ByteArrayInputStream(letteraHtml.toString().getBytes());<br /> InputStreamReader isr = new InputStreamReader(is);<br /> <br /> FileOutputStream outs = null;<br /> PrintStream ps = null;<br /> ByteArrayOutputStream outs1 = new ByteArrayOutputStream(16000);<br /> <br /> try {<br /> File myfile = new File("C:\tmp\pd4ml.pdf");<br /> if (myfile.exists()) {<br /> myfile.delete();<br /> myfile = new File("C:\tmp\pd4ml.pdf");<br /> }<br /> <br /> outs = new FileOutputStream(myfile);<br /> ps = new PrintStream(outs);<br /> <br /> pd4ml.render(isr, outs1);<br /> ps = new PrintStream(outs);<br /> ps.write(outs1.toByteArray());<br /> outs.flush();<br /> System.out.println("Fine");<br /> <br /> } catch (InvalidParameterException e) {<br /> e.printStackTrace();<br /> throw new ErroreApplicativo(e);<br /> } catch (IOException e) {<br /> e.printStackTrace();<br /> throw new ErroreApplicativo(e);<br /> } finally {<br /> if (outs != null) {<br /> try {<br /> outs.close();<br /> } catch (IOException e) {<br /> ;<br /> }<br /> }<br /> if (ps != null) {<br /> ps.close();<br /> }<br /> }<br /> <br /> }<br /> <br /> public static String getFileHttpProtocol(String path, boolean utfUrlEncode) {<br /> String url = path.replace(':', '|').replaceAll("/", File.separator).replaceAll("\\", "\\\\");<br /> url = "file:///" + url;<br /> return url.trim();<br /> }<br /> <br /> public static String getImgTempPath() {<br /> String path = "";<br /> <br /> String tempDir = System.getProperty("java.io.tmpdir");<br /> LogEntry.debug("PDFI - System temp directory :: " + tempDir);<br /> File fileTemp = new File(tempDir + File.separatorChar + "solari.png");<br /> if (fileTemp.exists()) {<br /> path = fileTemp.getAbsolutePath();<br /> }<br /> return path.trim();<br /> }<br /> <br /> }<br /> <br />

    #29613

    For the document generation you used PD4ML v380fx3. Try the most recent version – most probably the issue is already resolved.

    #29614

    It doesn’t work even with the new version.
    Below the attachment, same java code.

Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘Troubleshooting’ is closed to new topics and replies.