iText incorrectly renders custom lato font - java

To register my custom lato font I use this method: PdfFontFactory.register. Afterwards I print out all fonts to verify it gets registered.
Then I use the font like so
setFont(PdfFontFactory.createRegisteredFont("lato-regular"))
However there are very subtle differences in the display using the same ttf file on my website vs my pdf.
For example, the dot above the "i" is not circular but more of a rectangle with rounded edges when using iText. Any ideas?

Related

Change font color in StaticNote of PDFClown

Referring to Build text callout with PDF Clown - Is there a possibility to change the font color of the text within the callout note?
I haven't found a suitable method yet, can someone please give me a hint?
There is no explicit PDF Clown method to set the text color. This might be related to the fact that there is no explicit entry in the PDF annotation dictionary for it either.
There are two options, though:
There is a default appearance (DA) entry for variable text in annotations in general. As PDF Clown does not hide generic object methods, you can extend the original callout sample like this:
// Callout.
composer.showText("Callout note annotation:", new Point(35, 85));
new StaticNote(
page,
new Rectangle(250, 90, 150, 70),
"Text of the Callout note annotation"
).withLine(
new StaticNote.CalloutLine(
page,
new Point(250,125),
new Point(150,125),
new Point(100,100)
)
)
.withLineEndStyle(LineEndStyleEnum.OpenArrow)
.withBorder(new Border(1))
.withColor(DeviceRGBColor.get(Color.YELLOW))
.getBaseDataObject().put(PdfName.DA, new PdfString("1 0 1 rg /Ti 12 Tf"));
You have to use plain PDF instructions there, though, rg sets a RGB color defined by the three preceding values, and Tf sets font and size according to the preceding two values. The result of the above is:
As you see, the text now is purple (red 100%, green 0%, blue 100%). A side effect is, though, that the callout line and the frame around the callout box also are purple.
Alternatively a PDF can bring along an own appearance stream defining the whole appearance of the annotation in question. This means, though, that you really have to draw everything yourself including lines, frames, backgrounds, and text.
PDF Clown allows you to set the appearance of an annotation using the setAppearance and withAppearance methods.

Creating a PDF with itext, embedding an animation with buttons

I'm trying to create a PDF using iText library. The PDF has to embed an animation, which is a set of bitmaps. And there are buttons to control the animation. To understand it, see the following file:
http://www.texample.net/media/tikz/examples/PDF/wankel-motor.pdf
How can I create such a file from iText?
I know that I can embed a video file with this code:
http://itextpdf.com/examples/iia.php?id=188
But here I don't want to embed a video file, but a set of bitmaps and to add the control buttons.
Thanks in advance,
V. Henley
The document doesn't have any images. Instead it has a large series of Widget annotations inside a rectangle of which the lower-left and upper-right corners have the following coordinates:
llx = 4.981
lly = 287.238
urx = 322.053
ury = 542.754
These widget annotations are buttons that overlap each other and of which the appearance is defined using PDF syntax (paths consisting of straight lines and Bézier curves).
There are also a number of smaller buttons with arrows and other symbols. When clicking them, some JavaScript is executed:
The animations is actually JavaScript alternating the visibility of the different buttons. If you want to know more about the JavaScript that is used, you have to dig into the document using iText RUPS (which is what I did to create the above screen shot).
The principle that is used to create this PDF is identical to the principle that was used in the Calculator example, which is an example that was distributed with the same book you refer to.
Finally, I've been able to create such a PDF using latex code:
This is the latex code:
\documentclass[10pt]{article}
\usepackage{animate}
\usepackage{graphicx}
\usepackage{media9}
\pagestyle{empty}
\begin{document}
\AtEndDocument{%
\label{lastpage}%
}
\animategraphics[width=9.54cm,height=6.36cm,controls]{2}{C:/Users/casa/Documents/programacion/tex/construc_}{0}{3}
\end{document}
So after compiling such code with a latex compiler, it produces a pdf similar to the one I posted.
Kind Regards

Transparent images are showing up as black boxes after xfa.fillXfaForm. Are transparent images supported for the xfa fill?

Here's the current problem:
I have an XFA Form created by a 3rd party and I would like to use it as is.
I was able generate the PDF with filled fields by:
a) Extracting the XML via Acrobat Pro
b) filling the fields within the XML and calling
XfaForm xfa = form.getXfa();
xfa.fillXfaForm(new FileInputStream(XML));
What I'm trying to do is just stamp an image/watermark over the 2nd page which has a form w/multiple fields. The "DRAFT" png image I'm stamping has a transparent background so if the overlay works, the image background should make the underlay appear and look like that the image text is sitting on top of the pdf page.
What I wanted to accomplish would have been trivial if this was not an XFA form. I would just use iText's pdfStamper and stamp this transparent PNG over the 2nd page, but since I'm now confined to use Adobe LiveCycle Designer, I noticed that this once trivial task in the non XFA document isn't so trivial within XFA.
From a previous post, I learned that I couldn't mix technologies together. I had to choose between nonXFA (AcroForms) vs XFA (built by Adobe LiveCycle Designer). Basically, I couldn't do a fillXFA then use the stamper, so I had to figure out how to do this using XFA.
I've tried the following steps as a static PDF and a dynamic PDF....it didn't make a difference what type the PDF was.
1) Within Adobe LiveCycle Designer, I went to the second page of the source PDF and defined 2 image fields.
overlay1 - this will span the top portion width of the page which has text
content underneath
overlay2 - this will span the lower portion width of the page which has text
content underneath
2) As a test...I selected an image for overlay1 which has a transparent background and it's
foreground background as DRAFT
At design time...the DRAFT transparency image worked and it was laid on top of the content correctly
for the imageField: overlay1.
I saved the modified XFA-based PDF, opened it up in Acrobat Pro, and exported the XFA XML structure.
I verified that overlay1 had the DRAFT image as a base64 encoded string.
<overlay1 xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:contentType="image/png"
>iVBORw0KGgoAAAANSUhEUgAACWAAAAJYCAYAAADmY91UAAAACXBIWXMAAC4jAAAuIwF4pT92AABH
.......
.......
3) When I took the same base 64 string and only entered it's content within overlay2 and rendered it through the fillXFA method...the image was a black box instead.
I also opened the file in Acrobat Pro, then double clicked on the imageField area, selected the transparent image, and it still showed up as a black box.
I repeated the previous step with an image w/no transparency and it's rectangular white background
overlayed everything underneath it.
4) I went ahead and made another image...one that didn't have any transparency.
DRAFT with no transparency and it's background is white.
I had it encoded in base64 format.
I was able to place it within both overlay1 & overlay2 image fields without any problems.
The new problem is that the white background of the DRAFT images covered everything behind it.
Why did the initial transparent png work during the Adobe LifeCycle Design (design time) and after
a fillXFA call it shows up as a black box? But if I change the image to not use transparency at
all...everything works?
Does XFA not support transparent images for image fields during an xfa fill? Remember, it worked during
design time when I told Adobe LiveCycle designer to use this transparent png for this field.
I'm basically trying to create 2 image watermarks over a specific page within an XFA pdf.
My current backup plan is to flatten the PDF (take off the XFA) and putting back all the fields back on the form using Acrobat Pro and filling it using the standard PDF itext calls and using a stamper (this is going to be tedious since there's a bunch of fields). But I'd like to know if anyone ever had to do the same w/an XFA PDF form before I look at option B.
So I replaced the same PNG transparent image with a GIF transparent image. The GIF image encoded in base64 worked. I can create a new GIF file w/transparency, encode it in base64, and replace the previous one & it still worked. Looks like a bug with PNG rendering within the XFA form

Create image from text with unknown number of lines

I would like to convert a string of text into an image. The issue is, I want the text to wrap if it is wider than the length of the image, and the height of the image to be dynamically sized to perfectly fit the text, so that I know how much space the text takes up.
I'm working in Java and there are several things I have tried:
Rendering HTML in a JPanel and saving as a BufferedImage. The problem here was that most of the css I used was ignored by the JPanel and the image was unusable.
Using ImageMagick and img4Java. The two big failures with this solution was that I needed the command-line tool installed, which I can't do on our server. The second was that I couldn't easily convert the image to buffered image for use in the rest of the app.
Does anyone know a way to do this in Java?
Thanks!
In this example, an arbitrary panel is rendered into a BufferedImage and displayed in an adjacent panel at half-scale. The example uses a grid of labels, but you can use the wrap feature of JTextArea or the geometry supplied by TextLayout, examined here.
You might use a label containing HTML for the line-wrap, as shown here.
To get an image of that, see LabelRenderTest.

Preserving Embedded Fonts in iText

I have a java application which splits a pdf into sections using itext, then stitches a selection of these up together again. The original pdf has many embedded fonts varying in type (all non-system fonts). When I stitch the pdf's up again, some of the embedded fonts are missing.
For example, this is a clipping from the original fonts list:
This is a clipping from the generated pdf font list:
I am using PdfWriter and PdfReader to copy the pages into the new document, with PdfContent and addTemplate().
Finally found the answer! The problem was the level of Pdf was set too low:
writer.setPdfVersion(PdfWriter.VERSION_1_2);
I changed this to:
writer.setPdfVersion(PdfWriter.VERSION_1_7);
and now all fonts are embedded correctly.
I actually forgot that piece of code was in there - I had borrowed it from a project I had done in the past.
Lesson learned ;)
I would love to know why this is the case though.

Categories