tFPDF unicode characters in Arial bold - unicode

I'm trying to create PDF by FPDF (tFPDF) but I still can't create output with correct charset.
Problem is in czech letters: ě,š,č,ř,ž,ů etc...
Source:
<?php
require_once('../tfpdf/tfpdf.php');
define("_SYSTEM_TTFONTS", "C:/Windows/Fonts/");
$pdf = new tFPDF('P','mm','A5');
$pdf->SetMargins(8,5,8);
$pdf->AddPage();
// Pracoviště
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25,12,'Pracoviště:','L',0);
$pdf->Output();
?>
I need to write "Pracoviště:" but output is "PracoviÅ¡tÄ›:".
For regular Arial I solved it by:
$pdf->AddFont('Arial','','arial.ttf',true);
but it doesen't work for bold.
I tried:
$pdf->AddFont('Arial','','arial.ttf',true); // Arial
$pdf->AddFont('Arial','B','arialbd.ttf',true); // Arial Bold
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25,12,'Pracoviště:'); // output: Pracoviště:
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(25,12,'Pracoviště:'); // output: PracoviÅ¡tÄ›:
Interestingly if I use Arial Black file, it works, but it's not font what I need.
$pdf->AddFont('Arial','','arial.ttf',true); // Arial
$pdf->AddFont('Arial','B','ariblk.ttf',true); // Arial Black
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(25,12,'Pracoviště:'); // output: Pracoviště:
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(25,12,'Pracoviště:'); // output: Pracoviště: - but Arial Black font, I need Arial Bold
Why Arial works, Arial Black works too and Arial Bold doesn't work? How to solve it?

Related

Write urdu in notepad file using matlab

I have a Urdu Optical character Recognition. When I convert my image text to Unicode and write it in notepad file it shows like "ÌÇ Ûã ˜Ç äíÇ ÝÑ " not in urdu language. Here is my code
disp(native2unicode(rst))
f = fopen('temp.txt', 'w', 'native', 'UTF-8');
s = char(native2unicode(rst));
fprintf(f, ' %s.\r\n', s);
fclose(f);
The following code runs fine on my system. Maybe the added 'UTF-8' parameter helped?
rst='اردو‎';
disp(native2unicode(rst,'UTF-8'))
s = char(native2unicode(rst,'UTF-8'));
f = fopen('temp.txt', 'w', 'native', 'UTF-8');
fprintf(f, ' %s.\r\n', s);
fclose(f);

Loading fonts in Python/Pillow on a Mac

The Pillow ImageFont documentation has a few examples of using different fonts, but they don't work "out of the box" on a Mac. It's probably not too hard to figure out where my system fonts are located, but I'm lazy and would like a simple example that I can just edit.
So: how can I use Pillow on a Mac to write some text in a different font and size from the default?
Ok, "Lazy One" ;-) Here is an example:
from PIL import Image, ImageFont, ImageDraw
# Make a red canvas and get a drawing context to it
img = Image.new(mode='RGB', size=(500, 200), color=(255,0,0))
draw = ImageDraw.Draw(img)
# Get a "Chalkduster" TTF
chalk = ImageFont.truetype("Chalkduster.ttf",16)
# Get a "Keyboard" TTF
kbd = ImageFont.truetype("Keyboard.ttf",26)
# Make example for Lazy One - showing how to colour cyan too
draw.text((40,40),"Keyboard",font=kbd, fill=(0,255,255))
# And another
draw.text((20,140),"Chalkduster",font=chalk)
img.save("test.png")
If you want a list of all the TTF fonts on your system, you can look in both:
/System/Library/Fonts, and
/Library/Fonts
And, if you are very lazy, you can check in both at the same time from Terminal:
find {/System,}/Library/Fonts -name \*ttf
Sample Output
/System/Library/Fonts/SFNSDisplay.ttf
/System/Library/Fonts/Symbol.ttf
/System/Library/Fonts/ZapfDingbats.ttf
/System/Library/Fonts/Apple Braille.ttf
/System/Library/Fonts/SFNSText.ttf
/System/Library/Fonts/Apple Braille Outline 6 Dot.ttf
/System/Library/Fonts/Apple Braille Pinpoint 6 Dot.ttf
/System/Library/Fonts/Apple Symbols.ttf
/System/Library/Fonts/SFNSTextItalic.ttf
/System/Library/Fonts/SFNSRounded.ttf
/System/Library/Fonts/Apple Braille Pinpoint 8 Dot.ttf
/System/Library/Fonts/Keyboard.ttf
/System/Library/Fonts/Apple Braille Outline 8 Dot.ttf
/Library/Fonts/Webdings.ttf
/Library/Fonts/Zapfino.ttf
/Library/Fonts/Trebuchet MS Italic.ttf
/Library/Fonts/Georgia.ttf
/Library/Fonts/Verdana Bold.ttf
/Library/Fonts/Bodoni 72 Smallcaps Book.ttf
/Library/Fonts/Times New Roman Bold Italic.ttf
/Library/Fonts/Silom.ttf
/Library/Fonts/Verdana Italic.ttf
/Library/Fonts/Times New Roman Italic.ttf
/Library/Fonts/Bradley Hand Bold.ttf
/Library/Fonts/Arial Narrow Italic.ttf
/Library/Fonts/AppleGothic.ttf
/Library/Fonts/DIN Condensed Bold.ttf
/Library/Fonts/Farisi.ttf
/Library/Fonts/Arial Bold.ttf
/Library/Fonts/Trebuchet MS.ttf
/Library/Fonts/Mishafi.ttf
/Library/Fonts/Trattatello.ttf
/Library/Fonts/BigCaslon.ttf
/Library/Fonts/Courier New Bold.ttf
/Library/Fonts/NISC18030.ttf
/Library/Fonts/Lao Sangam MN.ttf
/Library/Fonts/Luminari.ttf
/Library/Fonts/Times New Roman.ttf
/Library/Fonts/Brush Script.ttf
/Library/Fonts/Georgia Italic.ttf
/Library/Fonts/Courier New Italic.ttf
/Library/Fonts/Arial Unicode.ttf
/Library/Fonts/Chalkduster.ttf
/Library/Fonts/Apple Chancery.ttf
/Library/Fonts/AppleMyungjo.ttf
/Library/Fonts/Arial Narrow Bold Italic.ttf
/Library/Fonts/Arial Narrow.ttf
/Library/Fonts/Courier New.ttf
/Library/Fonts/Wingdings 3.ttf
/Library/Fonts/Wingdings 2.ttf
/Library/Fonts/Hoefler Text Ornaments.ttf
/Library/Fonts/Bodoni Ornaments.ttf
/Library/Fonts/Skia.ttf
/Library/Fonts/Trebuchet MS Bold Italic.ttf
/Library/Fonts/Impact.ttf
/Library/Fonts/Kokonor.ttf
/Library/Fonts/Tahoma Bold.ttf
/Library/Fonts/Arial.ttf
/Library/Fonts/Diwan Thuluth.ttf
/Library/Fonts/Ayuthaya.ttf
/Library/Fonts/Khmer Sangam MN.ttf
/Library/Fonts/Trebuchet MS Bold.ttf
/Library/Fonts/Arial Black.ttf
/Library/Fonts/Courier New Bold Italic.ttf
/Library/Fonts/Comic Sans MS.ttf
/Library/Fonts/DIN Alternate Bold.ttf
/Library/Fonts/Wingdings.ttf
/Library/Fonts/Sathu.ttf
/Library/Fonts/Arial Bold Italic.ttf
/Library/Fonts/Tahoma.ttf
/Library/Fonts/PlantagenetCherokee.ttf
/Library/Fonts/Georgia Bold.ttf
/Library/Fonts/Verdana Bold Italic.ttf
/Library/Fonts/Microsoft Sans Serif.ttf
/Library/Fonts/Georgia Bold Italic.ttf
/Library/Fonts/Arial Rounded Bold.ttf
/Library/Fonts/Times New Roman Bold.ttf
/Library/Fonts/Krungthep.ttf
/Library/Fonts/Gurmukhi.ttf
/Library/Fonts/Andale Mono.ttf
/Library/Fonts/Mishafi Gold.ttf
/Library/Fonts/Herculanum.ttf
/Library/Fonts/Comic Sans MS Bold.ttf
/Library/Fonts/Arial Italic.ttf
/Library/Fonts/Verdana.ttf
/Library/Fonts/Arial Narrow Bold.ttf

How to use different "dev.off()" with knitr (to auto-crop figures)

I would like to use my own pdf() plot device in an .Rnw document converted to a PDF with knitr. After the PDF of a figure is generated
it should call pdfCrop.off() instead of dev.off() (or whatever knitr calls); this would
perfectly crop the resulting figures. How can this be done?
The following MWE works (but without cropping) if (*) is commented out (and the line before properly closed).
\documentclass{article}
\begin{document}
<<knitr_options, echo = FALSE, results = "hide", purl = FALSE>>=
## Custom graphics device (for cropping .pdf):
pdfCrop <- function(file, width, height, ...)
{
f <- file
grDevices::pdf(f, width = width, height = height, onefile = FALSE)
assign(".pdfCrop.file", f, envir = globalenv())
}
pdfCrop.off <- function() # used automagically
{
grDevices::dev.off() # closing the pdf device
f <- get(".pdfCrop.file", envir = globalenv())
system(paste("pdfcrop --pdftexcmd pdftex", f, f, "1>/dev/null 2>&1"),
intern = FALSE) # crop the file (relies on PATH)
}
## knitr options
knitr::opts_chunk$set(fig.path = "./fig_", background = "#FFFFFF",
dev = "pdfCrop", fig.ext = "pdf") # (*) => how to use pdfCrop.off() instead of dev.off()?
#
<<MWE>>=
<<fig-MWE, eval = FALSE, echo = FALSE>>=
plot(1:10, 10:1)
#
\setkeys{Gin}{width=\textwidth}
\begin{figure}[htbp]
\centering
\framebox{
<<figMWE, echo = FALSE, fig.width=6, fig.height=6>>=
<<fig-MWE>>
#
}
\caption{Just some text to show the actual textwidth in order to see that the
figure is not perfectly horizontally aligned due to some white space which can
be avoided by properly crop the figure with an adequate pdf crop device.}
\end{figure}
\end{document}
knitr already provides a crop device based on pdfcrop, so we can use that via a hook:
\documentclass{article}
\begin{document}
<<knitr_options, echo = FALSE, results = "hide", purl = FALSE>>=
## knitr options
library(knitr)
knit_hooks$set(crop = hook_pdfcrop)
knitr::opts_chunk$set(fig.path = "./fig_", # all figures are saved as fig_*
background = "#FFFFFF", # avoid color
crop = TRUE) # always crop
#
<<MWE>>=
<<fig-MWE, eval = FALSE, echo = FALSE>>=
plot(1:10, 10:1)
#
\setkeys{Gin}{width=\textwidth}
\begin{figure}[htbp]
\centering
<<figMWE, echo = FALSE, fig.width=6, fig.height=6>>=
<<fig-MWE>>
#
\caption{Just some text to show the actual textwidth in order to see that the
figure is not perfectly horizontally aligned due to some white space which can
be avoided by properly crop the figure with an adequate pdf crop device.}
\end{figure}
\end{document}

Get email body by python 3.4

I want get email body. My email is html and save in part. Use this code:
print('charset =', part.get_content_charset())
html = part.get_payload(decode=True)
print ('type =', type(html))
print('text =', html)
result is:
charset = utf-8
type = <class 'bytes'>
text = b'...<font face="DejaVu Sans Mono">\\u044d\\u0442\\u043e html<br>\n...
I want have normal text, but no \u044d\u0442\u043e.
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Your data is a byte array. You have to decode the bytes to a string:
text.decode('utf-8')

Issues with setting some different font for UILabel

I would like to set the font size and familyname to the titleLabel. //Helvetica Neue UltraLight
[titleLabel setFont:[UIFont fontWithName:#"Helvetica Neue UltraLight" size:25.0f]];
This is not working.
Kindly tell me what could be wrong?
Any help will be appreciated?
the correct fontName is #"HelveticaNeue-UltraLight".
use something like this to get a nicely formatted list of available font names:
NSMutableString *str = [NSMutableString stringWithCapacity:1000];
for (NSString *familyName in [UIFont familyNames]) {
[str appendFormat:#"%#\n", familyName];
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
[str appendFormat:#" %#\n", fontName];
}
[str appendString:#"\n"];
}
NSLog(#"%#", str);
this is the current list for iOS5.1:
Thonburi
Thonburi-Bold
Thonburi
Snell Roundhand
SnellRoundhand-Bold
SnellRoundhand-Black
SnellRoundhand
Academy Engraved LET
AcademyEngravedLetPlain
Marker Felt
MarkerFelt-Wide
MarkerFelt-Thin
Geeza Pro
GeezaPro-Bold
GeezaPro
Arial Rounded MT Bold
ArialRoundedMTBold
Trebuchet MS
TrebuchetMS
TrebuchetMS-Bold
TrebuchetMS-Italic
Trebuchet-BoldItalic
Arial
Arial-BoldMT
ArialMT
Arial-ItalicMT
Arial-BoldItalicMT
Marion
Marion-Regular
Marion-Bold
Marion-Italic
Gurmukhi MN
GurmukhiMN
GurmukhiMN-Bold
Malayalam Sangam MN
MalayalamSangamMN-Bold
MalayalamSangamMN
Bradley Hand
BradleyHandITCTT-Bold
Kannada Sangam MN
KannadaSangamMN
KannadaSangamMN-Bold
Bodoni 72 Oldstyle
BodoniSvtyTwoOSITCTT-Book
BodoniSvtyTwoOSITCTT-Bold
BodoniSvtyTwoOSITCTT-BookIt
Cochin
Cochin
Cochin-BoldItalic
Cochin-Italic
Cochin-Bold
Sinhala Sangam MN
SinhalaSangamMN
SinhalaSangamMN-Bold
Hiragino Kaku Gothic ProN
HiraKakuProN-W6
HiraKakuProN-W3
Papyrus
Papyrus-Condensed
Papyrus
Verdana
Verdana
Verdana-Bold
Verdana-BoldItalic
Verdana-Italic
Zapf Dingbats
ZapfDingbatsITC
Courier
Courier-Bold
Courier
Courier-BoldOblique
Courier-Oblique
Hoefler Text
HoeflerText-Black
HoeflerText-Italic
HoeflerText-Regular
HoeflerText-BlackItalic
Euphemia UCAS
EuphemiaUCAS-Bold
EuphemiaUCAS
EuphemiaUCAS-Italic
Helvetica
Helvetica-LightOblique
Helvetica
Helvetica-Oblique
Helvetica-BoldOblique
Helvetica-Bold
Helvetica-Light
Hiragino Mincho ProN
HiraMinProN-W3
HiraMinProN-W6
Bodoni Ornaments
BodoniOrnamentsITCTT
Apple Color Emoji
AppleColorEmoji
Optima
Optima-ExtraBlack
Optima-Italic
Optima-Regular
Optima-BoldItalic
Optima-Bold
Gujarati Sangam MN
GujaratiSangamMN
GujaratiSangamMN-Bold
Devanagari Sangam MN
DevanagariSangamMN
DevanagariSangamMN-Bold
Times New Roman
TimesNewRomanPS-ItalicMT
TimesNewRomanPS-BoldMT
TimesNewRomanPSMT
TimesNewRomanPS-BoldItalicMT
Kailasa
Kailasa
Kailasa-Bold
Telugu Sangam MN
TeluguSangamMN-Bold
TeluguSangamMN
Heiti SC
STHeitiSC-Medium
STHeitiSC-Light
Apple SD Gothic Neo
AppleSDGothicNeo-Bold
AppleSDGothicNeo-Medium
Futura
Futura-Medium
Futura-CondensedExtraBold
Futura-CondensedMedium
Futura-MediumItalic
Bodoni 72
BodoniSvtyTwoITCTT-BookIta
BodoniSvtyTwoITCTT-Book
BodoniSvtyTwoITCTT-Bold
Baskerville
Baskerville-SemiBoldItalic
Baskerville-Bold
Baskerville-Italic
Baskerville-BoldItalic
Baskerville-SemiBold
Baskerville
Chalkboard SE
ChalkboardSE-Regular
ChalkboardSE-Bold
ChalkboardSE-Light
Heiti TC
STHeitiTC-Medium
STHeitiTC-Light
Copperplate
Copperplate
Copperplate-Light
Copperplate-Bold
Party LET
PartyLetPlain
American Typewriter
AmericanTypewriter-CondensedLight
AmericanTypewriter-Light
AmericanTypewriter-Bold
AmericanTypewriter
AmericanTypewriter-CondensedBold
AmericanTypewriter-Condensed
Bangla Sangam MN
BanglaSangamMN-Bold
BanglaSangamMN
Noteworthy
Noteworthy-Light
Noteworthy-Bold
Zapfino
Zapfino
Tamil Sangam MN
TamilSangamMN
TamilSangamMN-Bold
DB LCD Temp
DBLCDTempBlack
Arial Hebrew
ArialHebrew
ArialHebrew-Bold
Chalkduster
Chalkduster
Georgia
Georgia-Italic
Georgia-BoldItalic
Georgia-Bold
Georgia
Helvetica Neue
HelveticaNeue-Bold
HelveticaNeue-CondensedBlack
HelveticaNeue-Medium
HelveticaNeue
HelveticaNeue-Light
HelveticaNeue-CondensedBold
HelveticaNeue-LightItalic
HelveticaNeue-UltraLightItalic
HelveticaNeue-UltraLight
HelveticaNeue-BoldItalic
HelveticaNeue-Italic
Gill Sans
GillSans-LightItalic
GillSans-BoldItalic
GillSans-Italic
GillSans
GillSans-Bold
GillSans-Light
Palatino
Palatino-Roman
Palatino-Bold
Palatino-BoldItalic
Palatino-Italic
Courier New
CourierNewPSMT
CourierNewPS-BoldMT
CourierNewPS-BoldItalicMT
CourierNewPS-ItalicMT
Oriya Sangam MN
OriyaSangamMN-Bold
OriyaSangamMN
Didot
Didot-Italic
Didot
Didot-Bold
Bodoni 72 Smallcaps
BodoniSvtyTwoSCITCTT-Book
You use wrong font name, correct one will be:
[titleLabel setFont:[UIFont fontWithName:#"HelveticaNeue-UltraLight" size:25.0f]];
You can see the list of all available font names for a given font family using +fontNamesForFamilyName: method in UIFont, e.g.:
[UIFont fontNamesForFamilyName:#"Helvetica Neue"]
Edit: Also mind that some fonts may not be present on all versions of iOS as Apple gradually adds (and sometimes probably removes) fonts from standard OS set.
It appears that "HelveticaNeue-UltraLight" font present in OS starting 5.0 version. If you want to use it in older OS versions you'll need to embed it to you application - check for example this answer for details how to do that
Please see List of Fonts available in iOS
and use font names according this...