Use of HTML rendering tag in Jboss Seam PDF

Asked

Viewed 269 times

0

I need to present texts with changed background color and in different fonts within an html rendering tag, but the correct value is not shown.

Tag used:

<p:document
    xmlns:p="http://jboss.com/products/seam/pdf"
    creator="#{messages['report.creator']}"
    margins="0 0 0 0">
    <p:html value="#{relatorioAction.textoEmHtml}"/>
</p:document>

Text for rendering:

<p style="text-align: center;">
 <span style="font-family: &quot;comic sans ms&quot;, sans-serif; color: #ff0000;">
  <span style="background-color: #99cc00;">
   <strong>
    <em>
     <u>Texto em cor vermelho sublinhado com cor de fundo verde oliva</u>
    </em>
   </strong>
  </span>
 </span>
</p>
<p style="text-align: center;">
 <strong>
  <em>
   <u>
    <span style="color: #ffa500;">
     <span style="background-color: #000000;">
      Texto em cor laranja com cor de fundo preto
     </span>
    </span>
   </u>
  </em>
 </strong>
</p>

Trying to print this, the pdf will be the two lines in Arial and without background color.

inserir a descrição da imagem aqui

Is there any setting that I’m leaving aside and that acts on that impression?

  • 1

    Hello Dear, I don’t know if it’s your case because you’re talking about pdf, but I’ve seen a problem like this in HTML, and the solution was to change the css color-adjust something like: *{ color-adjust: exact; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  • Thanks @Icaromartins, I will add the style in my text. Once I have results, I will return.

  • 1

    It didn’t work, @Icaromartins

  • 1

    The component you are using to generate the PDF is the iText? If I’m not mistaken the color adjustment of a paragraph should be done within the environment Java for the iText does not support background setting in paragraph from HTML/CSS/Javascript.

  • No, it’s Jboss Seam.

  • Is that https://docs.jboss.org/seam/2.3.1.Final/reference/html/itext.html ? If it is, the component used is iText.

  • It seems to be the same, but I have no way to make any configuration in code, because the background-color should be interpreted inside p:html. As far as I knew it had no relation to the framework you talked about, I’ve always seen iText working the pdf within the code.

  • I get your point. Well, this solves the situation, knowing that it is a problem of the framework itself. Thank you very much Augusto. Please create an answer with this information, as if the correction suggested by hugocsl does not work, I will accept your.

  • 1

    I’m not gonna give you an answer because I haven’t used it for a long time Java and many things I no longer remember, but if I am not mistaken this limitation can be circumvented by placing the paragraph within a <div> or inside a cell of a table, instead of trying to color the background of the paragraph <div> or <td> depending on which approach to use. Test as not sure.

Show 5 more comments

1 answer

7


I was going to write as a comment for not having a test environment, but it’s getting great so it goes as a response even without being able to test...

First on the fonts, there’s something called Web Safe Font, in summary your user needs to have the source installed in the Operating System to see the source correctly. See the image below to better understand. A reference source https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals#Web_safe_fonts

inserir a descrição da imagem aqui

Then there are variations of the name for the same font-family, so save yourself and include the two variations for example as below:

font-family: "Comic Sans MS", "Comic Sans", cursive;

Then I noticed that you didn’t put the Quote character " " in the font name and this is not within the correct CSS writing format, so do not use &quot; and use double quotes only " or single quotes '. In the case how you are using style right in the tag the ideal would be to leave so " ' ' " or the other way around ' " " '

style="font-family: 'Comic Sans MS', 'Comic Sans', cursive;"

inserir a descrição da imagem aqui


About the background img and color

In print you can see in these two answers that I gave some alternatives to do this! But basically for image you can use inside the @print one display:block on the tag <img>, for img as background-image does not work, and for color you can use box-shadow with the attribute inset to play the "inside" color of the element.

Follow the other answers I’ve done about color and image at the time of printing. I recommend that you read the full answers, here is only the summary...

For image:

Apply watermark without affecting text

Print page with Background

.imagem {
    display: none;
}

@media print {
    .imagem {
        display: block;
    }
}

<div class="imagem">
    <img src="cancelado.png" alt="">
</div>

Color

Print HTML page keeping the page CSS

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

table thead tr th {
    background: greenyellow; /* cor antes da impressão */
}

@media print{
  table thead tr th{
    box-shadow: 0 0 0 1000px red inset;  /* cor para impressão */
  }
}
<div class="container">
    <table border="1">
        <thead>
            <tr>
                <th>Item 1</th>
                <th>Item 2</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Texto 1</td>
                <td>Texto2</td>
            </tr>
        </tbody>
    </table>
</div>


A tip

Check the documentation of Jboss Seam Pdf if it has like you automatically embedar to font-family, here on the Adobe website has information about this: https://helpx.adobe.com/acrobat/using/pdf-fonts.html

About the background color/image you can see in the documentation if you can print the PDF as an image https://helpx.adobe.com/acrobat/kb/quick-fix-print-pdf-image.html or if you have the option to bring by default the option of "Background Graphics" as mentioned in the comment.

  • Thank you for your reply, Hugo. I will try to implement your ideas. But you keep in mind that I didn’t ask you about HTML or CSS but rather about generating both within a pdf generated by Jboss Seam, don’t you? Not putting your ideas as incorrect, just that I see no mention of the functionality, and I believe I made it clear in the question, but if I transcribe what I gave as an example in an HTML page, the operation is as expected. Only inside the PDF generated by Jboss Seam that does not work.

  • Maybe I need to clarify the need in the question, what you tell me Hugo?

  • 1

    @Gustavocinque I understood yes, the code I put is example and tips for you try to use in your environment, as I said I have no way to test this here. But as said if you will use quotes inside the quotes do so: " ' ' " or the other way around ' " " '. About the font-family is the same, the user has to have the font, unless you have a way to make one embed font in PDF, but then you have to see the documentation of this system that you use there. And on the background is the same, look at the documentation to bring by default Gráficos de segundo plano marked to catch the colors and imgs of bg

  • The solution for the quotes was taken advantage, on the background color unfortunately I did not find any correction, it seems that is framework problem

  • 1

    @Gustavocinque What a pity that not everything worked out, now is to wait to see if they release some update fixing these problems. I’m sorry I couldn’t help much more, it was worth the force ;) [s

Browser other questions tagged

You are not signed in. Login or sign up in order to post.