How can I scale a background image using iText7 and pdfHtml? - itext7

I'm trying to upgrade to the latest version of iText and I'm running into some issues. Currently we use Apache Velocity templates, and then convert the resulting HTML into a pdf using iText.
We have a large image(2220 x 3248) that is included on the PDF as a background. I've cut down the template to a bare minimum test.
<html>
<head>
<style type="text/css">
#page {
margin-top:57px;
margin-bottom:50px;
margin-left: 110px;
margin-right: 40px;
padding-top:160px;
padding-bottom:5px;
background-image:url('templates/background.png');
background-size:100% 100%;
background-position:top left;
}
</style>
</head>
<body>
<h1>Background Image Test</h1>
</body>
</html>
I then use the following code to render out the PDF.
public void render(PdfRendererContext ctx) throws Exception {
ConverterProperties properties = new ConverterProperties();
PdfWriter writer = new PdfWriter((OutputStream) ctx.getOutput().getOutput());
PdfDocument pdf = new PdfDocument(writer);
properties.setBaseUri("path/to/files");
HtmlConverter.convertToPdf((String) ctx.getInput().getInput(), pdf, properties);
}
This converts the PDF and I do mostly get what I want, but the background image is no longer scaled. The image is supposed to be a border around the page with a logo in the middle, but as you can see the image is much larger than the total page.
I've tried changing Background-size a few different ways but with no success. Is there any way to scale a background image similar to what I need?

Unfortunately, pdfHTML does not support background-size CSS property just yet. There is a solution with post-processing that you can use to add background images to your PDF document with iText Core. So you won't have any background images defined in HTML and instead you will just add them on the post-processing stage. Here is how the code looks for the described approach:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Converting to a memory stream to process the document in memory afterwards before flushing to disk
HtmlConverter.convertToPdf(htmlStream, baos);
PdfDocument pdfDocument = new PdfDocument(new PdfReader(new ByteArrayInputStream(baos.toByteArray())),
new PdfWriter(new File("C:/path/to/out.pdf")));
ImageData imageData = ImageDataFactory.create("C:/path/to/background.png");
// Page size of the output HTML document
Rectangle pageSize = PageSize.A4;
Image image = new Image(imageData).scaleAbsolute(pageSize.getWidth(), pageSize.getHeight());
for (int i = 1; i <= pdfDocument.getNumberOfPages(); i++) {
PdfPage page = pdfDocument.getPage(i);
// newContentStreamBefore just adds some content on the back layer, to be shown behind other content
PdfCanvas pdfCanvas = new PdfCanvas(page.newContentStreamBefore(), page.getResources(), pdfDocument);
new Canvas(pdfCanvas, pdfDocument, pageSize).add(image);
}
pdfDocument.close();

Related

svg images are not inserted in pdf while generating a pdf from html using itex7 html2pdf plugin

I am generating a pdf from multiple htmls. if any of the html consists img tag which refers to svg file like <img src="assets/6.svg" /> then in generated pdf doesnt have image included. If I keep jpg or png, then its included as part of generated pdf. Its happening only if I use below code but if I use HtmlConverter.convertToPdf() then svg files are showing fine in generated pdf.
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new File(pdfFileName)));
pdfDocument.setDefaultPageSize(PageSize.A4);
Document document = new Document(pdfDocument);
document.setMargins(40, 40, 40, 40);
for (String html : htmlFileList) {
List<IElement> elements = HtmlConverter.convertToElements(new FileInputStream(html), converterProperties);
System.out.println(elements.size());
for (IElement element : elements) {
System.out.println(element.getClass().getName());
document.add((IBlockElement)element);
}
}
document.close();
I am seeing error like below when generating a pdf from html using above code.
Unable to retrieve image with given base URI
(file:/C:/Projects/pdf_conversion/download/) and
image source path
(file:/C:/Projects/pdf_conversion/download/assets/cpc/img/icons/x_dont_gray.svg)
I am using above code because page content should be flown from page to page (dont want to create one pdf for one html). Any workaround is highly appreciated on this.

iText7 - How do you prevent the font face from changing when using HtmlConverter?

In C# I'm trying to pass in a simple HTML string and have the string parsed and added to a PDF document. In the below examples, I'm adding the string to an iText7 Paragraph.
I read this article and managed to write the below code.
https://itextpdf.com/en/resources/books/itext-7-converting-html-pdf-pdfhtml/chapter-1-hello-html-pdf
The first paragraph (p1), Example 1, renders the correct font face, Helvetica. Of course, I'm using the SetAction method, which is completely a different approach than the article. This is for demo purposes only.
The second paragraph (p2), Example 2, converts the HTML just fine but the font for the word "link" is rendered differently than Helvetica. It seems that when HTML is rendered, it ignores the font face of the document.
Sample Screenshot
How can I get the font face of "link" to be Helvetica and use the approach in Example 2? I think I'm missing something minor here. Do I need to define a CSS class since we're in HTML land?
Thank you for any suggestions.
class Program
{
static void Main(string[] args)
{
var pdfWriter = new PdfWriter(#"c:\temp\test.pdf");
var pdfDocument = new PdfDocument(pdfWriter);
var document = new Document(pdfDocument);
// Example 1
var p1 = new Paragraph("p1: this is a test url")
.SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA))
.SetFontSize(12f)
.SetFontColor(new DeviceCmyk(1f, .31f, 0, 0))
.SetFixedPosition(35, 600, UnitValue.CreatePercentValue(100f))
.SetAction(PdfAction.CreateURI("www.google.com"));
document.Add(p1);
// Example 2
var html = #"p2: this is a test url";
var elements = HtmlConverter.ConvertToElements(html);
var p2 = new Paragraph()
.SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA))
.SetFontSize(12f)
.SetFontColor(new DeviceCmyk(1f, .31f, 0, 0))
.SetFixedPosition(35, 550, UnitValue.CreatePercentValue(100f));
foreach (var element in elements)
{
p2.Add((IBlockElement)element);
}
document.Add(p2);
document.Close();
pdfDocument.Close();
pdfWriter.Close();
}
}
The default font-family in pdfHTML is Times, and you are overriding it only for the top-level elements while (almost) all the elements at all nesting levels have their font family explicitly specified after ConvertToElements invocation. To change the font family the easiest solution is indeed apply some CSS to your initial HTML. You can set font-family in style declaration directly:
var html = #"<p style=""font-family: Helvetica"">p2: this is a test url</p>";
Then you don't even have to set font to your paragraph and the paragraph creation code simplifies to
var p2 = new Paragraph()
.SetFontSize(12f)
.SetFontColor(new DeviceCmyk(1f, .31f, 0, 0))
.SetFixedPosition(35, 550, UnitValue.CreatePercentValue(100f));
foreach (var element in elements)
{
p2.Add((IBlockElement)element);
}

How to embed SVG graphics properly in JSF application using OmniFaces

This is a follow-up to How can I embed an SVG image using JSF/OmniFaces/PrimeFaces?
In that question, I learned that the OmniFaces-2.1 snapshot supports utilizing InputStream/byte[] through it's o:graphicImage tag.
In Getting started with SVG graphics objects in JSF 2.0 pages I learned that the standard graphicImage tags simply renders an img tag and SVG's should be rendered as and object tag like this: <object type="image/svg+xml" data="#{bean.svgUrl}">.
My question is really directed directly at BalusC from the OmniFaces project:
Should not o:graphicImage render SVG's in this manner? All I'm getting is img-tags and they don't work in IE10+.
Update #2: It's a scaling problem! I set the height to 125 and started seeing the edge my graphic.
UPDATE #1: Example rendered img tags:
This one is just based on a static SVG file: <img height="25" alt="" src="/javax.faces.resource/images/Logo.svg.xhtml;jsessionid=cc0acf6def65ac5c127d09384977?ln=default">
This is based on a byte array:
<img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgoKPHN2ZwogICB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iCiAgIHhtbG5zOmNjPSJodHRwOi8vY3JlYXRpdmVjb21tb25zLm9yZy9ucyMiCiAgIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyIKICAgeG1sbnM6c3ZnPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxuczppbmtzY2FwZT0iaHR0cDovL3d3dy5pbmtzY2FwZS5vcmcvbmFtZXNwYWNlcy9pbmtzY2FwZSIKICAgdmVyc2lvbj0iMS4xIgogICB3aWR0aD0iMzE5LjEzNzUxIgogICBoZWlnaHQ9IjI3OS40NjI0OSIKICAgaWQ9InN2ZzIiCiAgIHhtbDpzcGFjZT0icHJlc2VydmUiPjxtZXRhZGF0YQogICAgIGlkPSJtZXRhZGF0YTgiPjxyZGY6UkRGPjxjYzpXb3JrCiAgICAgICAgIHJkZjphYm91dD0iIj48ZGM6Zm9ybWF0PmltYWdlL3N2Zyt4bWw8L2RjOmZvcm1hdD48ZGM6dHlwZQogICAgICAgICAgIHJkZjpy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LDEyMDcuNzkgLTI1NC44OCw2OS4xMiBjIC0wLjcyLDAgLTAuNzIsMCAtMS40NCwwIC0zLjU5LDAgLTYuNDgsLTIuODcgLTYuNDgsLTYuNDcgMCwtMS40NCAwLC0yLjE2IDAuNzIsLTIuODkgbCAzNy40NCwtNjQuMDYgLTE5MS41MSwtNzAuNTcgQyA5ODAuMjczLDEwNzkuNjQgODgzLjA3NCw5MzkuOTYxIDg4My4wNzQsNzg0LjQ0MSBsIDAsLTQzNC44ODIgMTYwLjU1NiwwIDAsNDM1LjYxMyBjIDAsODcuMTA5IDU0LjcyLDE2NS41OSAxMzYuOCwxOTUuODI4IGwgMTkyLjk2LDcxLjI4IDEyLjk2LC03Mi43MjEgYyAwLjczLC0yLjg3OSAzLjYxLC01LjAzOSA2LjQ4LC01LjAzOSAyLjE3LDAgMy42MSwwLjcxOCA1LjA1LDIuODcxIGwgMTQ5Ljc1LDIxNi43MjkgYyAwLjcyLDEuNDQgMS40NCwzLjYgMS40NCw1LjA0IDAsNC4zMyAtMi44OCw3LjkyIC02LjQ4LDguNjMgeiIKICAgICAgICAgaW5rc2NhcGU6Y29ubmVjdG9yLWN1cnZhdHVyZT0iMCIKICAgICAgICAgaWQ9InBhdGgyNCIKICAgICAgICAgc3R5bGU9ImZpbGw6bm9uZTtzdHJva2U6IzIzMWYyMDtzdHJva2Utd2lkdGg6Mi4xNTAwMDAxO3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1taXRlcmxpbWl0OjQ7c3Ryb2tlLW9wYWNpdHk6MTtzdHJva2UtZGFzaGFycmF5Om5vbmUiIC8+PC9nPjwvZz48L3N2Zz4=" alt="100.1 - Farlig sving" title="100.1 - Farlig sving" width="40" style="margin-left: 3px; pointer-events: none;" height="40">
Since I discovered this to be a SVG scaling problem and I seem not to be the only one who has encountered this I'll post my solution here.
In short, I
Retrieve the SVG.
Parse it using JDOM.
Inject a view box if it is missing based on the specified size
Here's the Java code without error handling:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = execute(builder.buildGet(), InputStream.class);
Document doc = new SAXBuilder().build(is);
Element root = doc.getRootElement();
if (root.getAttribute("viewBox") == null)
{
String width = root.getAttributeValue("width"), height = root.getAttributeValue("height");
root.setAttribute("viewBox", String.format("0 0 %s %s", width, height));
}
new XMLOutputter().output(doc, baos);
return baos.toByteArray();

Jscript image tag creation gives an error

function pushImage () {
var img = new Image();
img.src = '/waroot/chart/chart.png';
document.getElementById("test1").innerHTML = "<img src='/waroot/chart/chart.png'>";
document.getElementById("test2").innerHTML = img;
}
Test 1 works and shows the image, but test 2 doesn't. I am not sure how to solve it but i will need the way test 2 works further along my project since i'm going to have to circle through a large amount of images.
The images are created by JFreeCharts, saved to png and then have to be posted to a site. As a side question: is it possible to push the freecharts objects straight to the jscript instead of having to save them prior (i could throw them into the dictionary and then look them up later but i'm not sure if this works)
Use .appendChild(img) instead of .innerHTML:
function pushImage () {
var img = new Image();
img.src = '/waroot/chart/chart.png';
document.getElementById("test1").innerHTML = "<img src='/waroot/chart/chart.png'>";
document.getElementById("test2").appendChild(img);
}
Demo
This is because img is an image object, not an html string, so you have to append it to the DOM.
P.S., don't forget that the alt attribute is required in the img tag!

iTextSharp: Why when adding a image to a pdf page the text font is different?

I use Helvetica font and 14 px size for text. The problem is that if a page does not have any image on it the text is very clear, but in a page with at least 1 image the text is getting a little bold. You can see what I mean in images below:
* Without image on page
* With image on page
The correct font is the one that appear in picture #1. How to make all pages have the same font even if the page contains an image or not?
Thanks.
Sample code:
Document document = new Document(PageSize.LETTER);
document.SetMargins(docMargin, docMargin, docMargin, 25);
writer = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
document.Open();
Font defaultFont = FontFactory.GetFont("Helvetica", 7.8, Font.NORMAL, new Color(75, 75, 75));
document.Add(new Paragraph("Lorem ipsum lorem ipsum lorem ipsum", defaultFont));
document.Add(Chunk.NEWLINE);
Image img = Image.GetInstance("my png image path");
document.Add(img);
document.Close();
I was finally able to reproduce your problem. The first PNG that I tested with which didn't reproduce your problem I created from Photoshop and used the Save For Web command. The second PNG that I tested and was able to reproduce your problem I created from MSPAINT.EXE. I tried various combinations within Save For Web and none of them have the same problem as Paint.
According to this thread from the official iText mailing list it appears to be something about the color profile of the image.
What are you seeing is the impact of newly placed transparency into a
PDF that had not previously contained it, when consideration isn't
given for the blending colorspace of the final output document.
You have an RGB document that upon adding transparency is forced into
CMYK due to lack of explicit blending space. If you were to specify
RGB as your explicit blending space at the same time you added your
transparency, all would be well.
One thing they recommend is setting the following property on your PdfWriter before adding anything:
writer.RgbTransparencyBlending = true;
When I do it I still see a very minor shift but no where near as pronounced as without it.
This isn't an answer, I just need to be able to post code.
I'm unable to reproduce your results but if I were to guess it has something to do with your PDF renderer. You can confirm this by zooming in on the text, does it look the same when zoomed in? If so, that's your renderer trying to apply visual hints to a print document. If not, can you post a simplified version of your code that does this? Does this do this for all images or just one specific one? How are you creating your text, with Paragraphs, Tables, HTML parsing or something else? What version of iTextSharp are you using?
Below is a full working WinForms C# 2010 targeting iTextSharp 5.1.2.0 that creates a two page PDF. The first page has just text and the second page has text followed by an image loaded from the desktop. On my machine, using Adobe Acrobat Pro 9.1.3 I don't see any difference in fonts when I view it on screen.
using System;
using System.IO;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
string pdfFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf");
string imgFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.png");
using (FileStream fs = new FileStream(pdfFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
using (Document doc = new Document(PageSize.LETTER)) {
using (PdfWriter writer = PdfWriter.GetInstance(doc, fs)) {
doc.Open();
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font f = new iTextSharp.text.Font(bf, 14);
doc.NewPage();
doc.Add(new Paragraph("This is a test", f));
doc.NewPage();
doc.Add(new Paragraph("This is a test", f));
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(imgFile);
img.ScaleAbsolute(100, 100);
doc.Add(img);
doc.Close();
}
}
}
this.Close();
}
}
}

Resources