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:

    <div id="boxAddress" style="position: absolute; top: 3cm; left: 10cm;">
    VALERIO ROSSI
    AVENUE V. HUGO 80
    31100 CROWLEY  UK
    </div>
    
    <div id="mailTextAddress" style="position: absolute; top: 13cm;">
    TextTextTextTextTextTextTextTextTextTextTextText
    TextTextTextTextTextTextTextTextTextTextTextText
    </div>

    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

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

    #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();
    }
    
    }

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