I am using following code for jasper pdf report to display character M SQUARED (\u33a1)
<?xml version="1.0" encoding="UTF-8"?>
...
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="609" height="20" uuid="df8665ef-2226-4aaa-bd04-09805582eaef"/>
<textElement verticalAlignment="Middle">
<font fontName="SomeCustFont" size="20" pdfEncoding="Cp1252" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA["Squared M : \u33a1"]]></textFieldExpression>
</textField>
For this code, I am not able to see the unicode character in PDF. It is simply blank. But in XLSX, I am able to see the character.
I tried following:
Remove pdfEncoding
Set isPdfEmbedded="false"
But no luck
Update: It seems, the custom font I am using is not supporting squared m character. I cannot add a new font or update existing custom font. But I can use any or in-built fonts for that particular character. How can I achieve this using in-built font?
I tried:
fontName="Courier" pdfFontName="Courier"
This in-built font for jasper supported that character but I am getting error as font cannot be located.
The main problem here was \u33a1 is an extended ASCII unicode. Most of the free fonts don't support this. So instead of this squared m, I used english 'm' character followed by superscript 2 unicode \u00b2 which is available in almost all fonts.
\u33a1 -> m\u00b2
Related
From what I understand SF Pro is now the default font used in iOS mobile. I'm unclear as to how to use the different font weights of this font and even how to find out what is available.
Does anyone know how I can specify for example two different font resources NormalFont and BoldFont and have the app use the correct SF Pro fonts for the iOS?
<ResourceDictionary>
<OnPlatform x:TypeArguments="x:String" x:Key="NormalFont">
<On Platform="iOS" ???
<On Platform="Android" Value="Roboto-Regular.ttf#Roboto-Regular" />
</OnPlatform>
<OnPlatform x:TypeArguments="x:String" x:Key="BoldFont">
<On Platform="iOS" ???
<On Platform="Android" Value="Roboto-Bold.ttf#Roboto-Bold" />
</OnPlatform>
</ResourceDictionary>
To answer your question, we need to dug into several aspects of fonts & their mechanisms.
Let's start with how to get all weights for a specific font family. Referring to the official Apple docs, we can log all weights for all system fonts like this (in the iOS project):
foreach (var family in UIFont.FamilyNames)
{
var names = UIFont.FontNamesForFamilyName(family);
var namesAsString = string.Join(", ", names);
Debug.WriteLine($"Family: {family} Font names: {namesAsString}");
}
You can refer to system fonts by their name. System fonts are known to start with a dot (.) - e.g. San Francisco fonts can be .SFUIText-Bold, .SFUI-Regular, etc. Due to the nature of these fonts, being system ones, it was strongly discouraged for the developers to reference them by their name. One reason was that their name could change frequently.
The problem is that as of iOS 13, we're not supposed to load system fonts by name anymore. (Technically it's been advised against for a while, but iOS 13 actually enforces it by just giving you back Times New Roman when you ask for a system font.)
Here' a screenshot from WWDC 2019, regarding Font instantiation (by name):
Having said that, you can still refer to system fonts by name. After iOS 13 got released, this immediately broke everything in Xamarin. You can see in this GitHub issue. For now, they have implemented a workaround and system fonts (starting with a dot) are still possible to use. You can specify in your xaml something like this:
<OnPlatform x:TypeArguments="x:String" x:Key="NormalFont">
<On Platform="iOS" Value=".SFUI-Regular" />
<On Platform="Android" Value="Roboto-Regular.ttf#Roboto-Regular" />
</OnPlatform>
However, I would strongly suggest you to restrain from using the system fonts like this.
To sum up, you have 2 preferable options here:
Simply download & import the San Francisco font. The font can be downloaded for free form Apple's website. (link). After that, just refer to Xamarin's official docs (Use a custom font)
Stay with the default system font and add weight attributes in xaml (bold, italic, etc).
Personally, I would go with the first approach. That way, you will always be sure that you have the font files and no update would change the font. Going with the second approach, will always refer to the system font. This font may (and will surely) change at some point.
If we want to see what the default system font is, we can do it like so:
var systemFont = UIFont.SystemFontOfSize(17);
Debug.WriteLine($"System: {systemFont.FamilyName}");
I am trying to export jasper as pdf but It does not show the cyrillic values. When I export it as excel it does show and the output is fine, but when I try to export is as PDF it does not export the cyrillic values. The cyrillic values are not written in cyrillic font, they are written as cyrillic keyboard.
The code I use to export is:
JRExporter e = new JRPdfExporter();
e.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
e.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, outStream);
e.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, NAME);
I even tried to specift the parameter below:
e.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");
but did not succeed. Any suggestions?
Jasper report uses iText and always when a char is not rendered in pdf this should be the checklist:
Is my actual .tff supported (OpenType) and can the font actually render the character. Not all fonts render
all characters in UTF-8, see How can I test if my font is rendered correctly in pdf?
Do I pass correct encoding to iText. In doubts (or in general) use the encoding Identity-H this is recommend for newer PDF standards and gives you the ability to mix different encoding.
Is my font embedded so that if I share the pdf also computers not having this font can display the content?
How can I ensure this is JasperReport?
The deprecated method was to set attributes on the textElement
<textElement>
<font pdfFontName="Helvetica" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single"/>
</textElement>
The current non deprecated method v 3-6, is to add Font Extensions and this is easily achieved by using tools like iReport or JasperSoft Studio that can generate a .jar of your font extension so that you can include it in your classpath directly.
How to generate font extension .jar using iReport or JasperSoft Studio.
EDIT: The problem of OP was 1 on checklist (.ttf font could not render), but surely he should consider both 2 and 3 using non deprecated method.
I use a command line application to create QR images from a given input text. I create enough of these and do some image editing, namely:
resize the QR image,
place on an office document
type an index number next to the image
repeat the above steps by adding more QR images next and below this image
print an A4 page on the printer full of QR images.
The whole process is very repetitive and can be automated. But I don't know where to start from with this. I see gimp has "script-fu" based on the scripting "scheme" language but I can't find (or think of) some relevant function that can do the above. Sure the resize is easy, but adding text and creating a restricted image tile surface seems not as straight forward.
Is there some application that I could use that edits the image according to some script and places the result in an A4 image which will later be printed?
Or am I plainly asking for too much? If it integrates weel with bash / python scripts then that is even better!
thank you
IMO this will require some work; one way to accomplish this is doing the following:
Create a svg template file with A4 size, layout it in a way that fits a page with several of the desired QR images. Something like the following:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- A4 size -->
<svg width="210mm" height="297mm" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image xlink:href="_qr_image_here_1_" x="0" y="0" height="50px" width="50px"/>
<image xlink:href="_qr_image_here_2_" x="60" y="0" height="50px" width="50px"/>
... <!-- More Images --> ...
</svg>
Code a shell script that calls sed to replace the xlink:href="_qr_image_here_N_" attributes with the path to the QR images you want to fit in (the svg file tools would take care of the resizing process for you).
Generate several of these svg documents from your script, these files will represent the pages of your doc.
Convert all the svg files to pdf, you can use rsvg-convert for this, more info here.
Merge all the pdf generated pages into one pdf file, you can use pdftk for this, also you can find info on how to do this step here.
For a symfony project, i am using the snappy bundle, that used wkhtmltopdf to convert the webpage into a pdf. I am using google fonts to use different font faces. The font shows up fine on the web page, but after converting to a pdf, any sections that use font faces have bad spacing between letters. Is there any way to fix the spacing on the letters?
Image of PDF: (using google font, EB Garamond)
pdf example image
html code:
<link href='http://fonts.googleapis.com/css?family=EB+Garamond' rel='stylesheet' type='text/css'>
Normal Text: qwertyuiopasdfghjklzxcvbnm<br>
<div style="font-family: 'EB Garamond', serif;">
google EB Garamond: qwertyuiopasdfghjklzxcvbnm<br>
google EB Garamond: workstation ergonomic evaluations.</div><br>
Normal Text: workstation ergonomic evaluations.
I have also tried using other fonts from other soruces, like adobe typekit and still have the same problem.
Try adding the '--dpi 96' switch to the wkhtmltopdf command line.
I had an issue with letters getting joined together and using --dpi 96 in combination with letter-spacing:0.09em; solved it
We faced the same problem. As setting the DPI to only 96 (print usually uses at least 300) resulted in blurry images, we tried to use SVG font files, which did the trick.
I'm using ABCpdf to extract the text content of some PDF files, in particular by calling Doc.GetText("Text"). (You call it in a loop, once per page.) This usually works well, but for some PDF files the resulting text consists of text with a dearth of space characters, e.g.
Thissentencedoesn'thaveanyspacesbetweenwords.
What's interesting is if I try to extract text from the exact same PDFs using Apache Tika (powered under the hood by PDFBox), I tend to get all the spaces I'd expect between words. That is, the above sentence would be rendered by Tika as
This sentence doesn't have any spaces between words.
Overall, the two tools act like they're afraid of committing different mistakes -- ABCpdf acts like the worst thing in the world would be to insert a space where one doesn't belong, while Tika acts like the worst thing in the world would be to fail to insert a space where one does belong.
Are there any settings to make ABCpdf act more like Tika in this regard?
Short Answer: You can get individual tokens of text via Doc.GetText("SVG"), parsing the XML for TEXT and TSPAN elements, and determining if there is layout spacing that should be treated as actual spaces. The behavior you're seeing from PDFBox is probably their attempt to make that assumption. Also, even Adobe Acrobat can return spaced text via the clipboard as PDFBox does.
Long Answer: This may cause more problems, as this may not be the original intent of the text in the PDF.
ABCpdf is doing the correct thing here, as the PDF spec only describes where things should be placed in the output medium. One can construct a PDF file that ABCpdf interprets in both styles, even though the original sentence looks nearly the same.
To demonstrate this, here is a snapshot of a document from Adobe InDesign that shows a text layout matching both cases for your sample sentence.
Note that the first row was not constructed with actual spaces, instead, the words were placed by hand in individual text regions and lined up to look approximately like a properly spaced sentence. The second row has a single sentence that has actual text spaces between the words, in a single text region.
When exported to PDF and then read in by ABCpdf, Doc.GetText("TEXT") will return the following:
ThisSentenceDoesn'tHaveAnySpacesBetweenWords.
This Sentence Doesn't Have Any Spaces Between Words.
Thus if you wish to detect layout spaces, you must use SVG output and step through the tokens of text manually. Doc.GetText("SVG") returns text and other drawing entities as ABCpdf sees them on the page, and you can decide how you want to handle the case of layout based spacing.
You'll receive output similar to this:
<?xml version="1.0" standalone="no"?>
<svg width="612" height="792" x="0" y="0" version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<text xml:space="preserve" x="36" y="46.1924" font-size="14" font-family="ArialMT" textLength="26.446" transform="translate(36, 46.1924) translate(-36, -46.1924)">This</text>
<text xml:space="preserve" x="66.002" y="46.1924" font-size="14" font-family="ArialMT" textLength="59.15" transform="translate(66.002, 46.1924) translate(-66.002, -46.1924)">Sentence</text>
<text xml:space="preserve" x="129.604" y="46.1924" font-size="14" font-family="ArialMT" textLength="47.46" transform="translate(129.604, 46.1924) translate(-129.604, -46.1924)">Doesn’t</text>
<text xml:space="preserve" x="181.208" y="46.1924" font-size="14" font-family="ArialMT" textLength="32.676" transform="translate(181.208, 46.1924) translate(-181.208, -46.1924)">Have</text>
<text xml:space="preserve" x="219.61" y="46.1924" font-size="14" font-family="ArialMT" textLength="24.122" transform="translate(219.61, 46.1924) translate(-219.61, -46.1924)">Any</text>
<text xml:space="preserve" x="249.612" y="46.1924" font-size="14" font-family="ArialMT" textLength="46.69" transform="translate(249.612, 46.1924) translate(-249.612, -46.1924)">Spaces</text>
<text xml:space="preserve" x="301.216" y="46.1924" font-size="14" font-family="ArialMT" textLength="54.474" transform="translate(301.216, 46.1924) translate(-301.216, -46.1924)">Between</text>
<text xml:space="preserve" x="360.016" y="46.1924" font-size="14" font-family="ArialMT" transform="translate(360.016, 46.1924) translate(-360.016, -46.1924)"><tspan textLength="13.216">W</tspan><tspan dx="-0.252" textLength="31.122">ords.</tspan></text>
<text xml:space="preserve" x="36.014" y="141.9944" font-size="14" font-family="ArialMT" transform="translate(36.014, 141.9944) translate(-36.014, -141.9944)">
<tspan textLength="181.3">This Sentence Doesn’t Have </tspan><tspan dx="-0.756" textLength="150.178">Any Spaces Between W</tspan><tspan dx="-0.252" textLength="31.122">ords.</tspan></text>
</svg>
And note that the basic structure reveals the original intent that gave you problems. (xml:space and attributes removed, whitespace modifications for the sake of example)
<?xml version="1.0" standalone="no"?>
<svg>
<text>This</text>
<text>Sentence</text>
<text>Doesn’t</text>
<text>Have</text>
<text>Any</text>
<text>Spaces</text>
<text>Between</text>
<text><tspan>W</tspan><tspan>ords.</tspan></text>
<text>
<tspan>This Sentence Doesn’t Have </tspan>
<tspan>Any Spaces Between W</tspan>
<tspan>ords.</tspan>
</text>
</svg>
This question and answer are based around old releases of ABCpdf.
ABCpdf Version 9 will do this all automatically for you.
I work on the ABCpdf .NET software component so my replies may feature concepts based around ABCpdf. It's just what I know. :-)