I want to use Verdana as a font while stamping a PDF file with iText PDF. The original file uses Verdana, which isn't an option in the class Basefont.
Here is the function to create my font right now:
def standardStampFont() {
return BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false)
}
I'd like to change that to the Verdana Font, but simply exchanging the Part BaseFont.HELVETICA with "Verdana" doesn't work.
Any idea? Thanks in advance!
As documented, iText supports the Standard Type 1 fonts, because iText ships with AFM file (Adobe Font Metrics files). iText has no idea about the font metrics of other fonts (Verdana isn't a Standard Type 1 font). You need to provide the path to the Verdana font file.
BaseFont.createFont("c:/windows/fonts/verdana.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED)
Note that I change false to BaseFont.EMBEDDED because the same problem you have on your side, will also occur on the side of the person who looks at your file: his PDF viewer can render Standard Type 1 fonts, but may not be able to render other fonts such as Verdana.
Caveat: The hard coded path "c:/windows/fonts/verdana.ttf" works for me on my local machine because the font file can be found using that path on my local machine. This code won't work on the server where I host the iText site, though (which is a Linux server that doesn't even have a c:/windows/fonts directory). I am using this hard coded path by way of example. You should make sure that the font is present and available when you deploy your application.
Adding this line makes sure the FontFactory actually registers the fonts in the operating systems' default fonts directories:
FontFactory.RegisterDirectories();
After that all the installed fonts can be found using something like
var myfont = FontFactory.GetFont("Verdana", 10f, iTextSharp.text.Font.NORMAL);
I get that this post is old, but it's still relevant I guess.
Related
I have a PDF template document given by my client as a reference. My application has to create it. When i compared the PDF generated by my application and the template given by the client i could see the look and feel are slightly different.I opened it in Adobe acrobat pro dc, i could still see the font properties are same. Please see the link below to see the PDFs header i created which has the above mentioned issue.
Please see the image:
I have the font properties defined in xml as below.This will be unmarshalled later.
<font name="Arial Narrow" id="blackBold" fsize="12" type="bold" rgb="0,0,0"/>
I have the different font type defined in a map like below,
fontAndAlignmentMap.put("bold", 1);
//Internally this will be resolved to-->com.itextpdf.text.Font.BOLD = 1;
The itext Font will be created from an unmarshalled xml font object as below:
FontFactory.registerDirectories();
com.itextpdf.text.Font itextFont =
FontFactory.getFont(sbcFont.getName(), sbcFont.getFsize(), fontAndAlignmentMap.get(sbcFont.getType()), new BaseColor(r,g,b));
The 10 page pdf document have different fonts and formatting.The Statically defined fonts are unmarshalled and loaded into the itextFontMap as shown below.
itextFontMap.put(sbcFont.getId(), itextFont);
sbcFont.getId() are "blackBold","blackRegular" etc.Depends on the use the appropriate font will be pulled from this map.
Phrase pSbc = new Phrase("Summary of Benefits and Coverage:",
SBCMappingSingletonBuilder.itextFontMap.get("blackBold"));`
Phrase pSbcDesc = new Phrase(
" What this Plan Covers & What You Pay For Covered Services",
SBCMappingSingletonBuilder.itextFontMap.get("blackRegular"));
When i printed the family name of the com.itextpdf.text.Font object.
blackBold.getFamilyname() :Arial Narrow
blackRegular.getFamilyname() :Arial Narrow
This is what printed from the code.
sbcFont.getName() :Arial Narrow Bold
sbcFont.getName() :Arial Narrow
Phrases added to a PdfPCell; PdfPCell added to PdfPTable and then to the document.
Can any one please throw some light here.I am using java 1.6 and itextpdf-5.3.4
The sample template which i am referring please click
here
The one i am tring to create similar to the template,please click
here
I opened the pdf in Adobe Acrobat Pro.The bold font look like narrow even though the font properties are showing as bold in Adobe Acrobat Pro.But when i opened the pdf in a browser,it looks good.
Using Prestashop 1.6 - and on the PDF's (Invoice & delivery) the Russian Ruble symbol won't render properly, converts to a "square". It is working without problem on all other areas of our site. Does anyone know how I can fix this? Thank you
It is linked to the font include in TCPDF, i think the font use for your iso code not include this symbole.
The font folder for TCPDF is :
https://github.com/PrestaShop/PrestaShop/tree/1.6.1.6/tools/tcpdf/fonts
How to found the font use by TCPDF?
https://github.com/PrestaShop/PrestaShop/blob/1.6.1.6/classes/pdf/PDFGenerator.php
In this file you can know what font use for your country iso code
The font use depend to country iso code, so for RU the font is freeserif.
So the font freeserif not include Rouble.
Solution?
Solution 1
The easy solution is to change in the https://github.com/PrestaShop/PrestaShop/blob/1.6.1.6/classes/pdf/PDFGenerator.php the font for your iso code by (dejavusans, cid0jp, ..) depending font in the folder tools/tcpdf/fonts.
Solution 2
The second solution, is to download TTF file who include the symbol(example you can search/download a font in http://www.dafont.com/) and generate a valid file with online converter
http://fonts.snm-portal.com/ (it is a first result for my search in google)
After you upload the file(s) generated in folder tools/tcpdf/fonts and edit the file PDFGenerator.php to point to your new font.
BIRT is unable to render Hindi language characters in generated PDF file. The same design file, when rendered as Word document or HTML or any other format, I am able to see the unicode characters.
I have set Arial Unicode MS as the font type in the design file and tried with few samples from google translate. Please let me know if I'm missing anything.
Thank you.
The most probable BIRT can't find correct font files.
You have to configure pdf fonts correctly (see. file fontsconfig.xml).
I've similar issue with Cyrillic and Chinese fonts.
What I fixed in the file:
...
<font-paths>
<path path="fonts" />
<!--path path="C:/windows/fonts" />
<path path="d:/windows/fonts" />
...
<path path="/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType" /-->
</font-paths>
Create fonts folder and put all necessary fonts (a bit tricky question is where fonts folder must be. It depends how you're using BIRT).
Optionally you can put correct font files in JRE/lib/fonts folder you're using.
If you are working on JavaFx Desktop App.It will work.
If you are using BIRT viewer deployment using fontsConfig.xml because all configs are bundled in org.eclipse.birt.runtime_VERSION-XXX.jar
So you can use this way just override fontConfig_Pdf.xml file and add your Font in this file
<composite-font>
<font font-family="mangal" catalog="Western"/>
</composite-font>
and after that add this line code in your BIRTserviceImpl Class where you are setting the RuntimeEngine
EngineConfig conf = null;
conf.setFontConfig(new File("fontsConfig_pdf_win.xml").toURL());
conf.setEngineHome("{dir}/birt-runtime-4_4_1/ReportEngine");
eng = new ReportEngine(conf);
this line will help to change runtime fonts config and
copy your hindi fonts and paste into jre/lib/Fonts and C:/windows/Fonts also
I am trying to install a custom font into my iPhone application. When I add the 'Fonts provided by application’ key into my info.plist file I get the following error ': FT_Open_Face failed: error 85.’
I am not sure what the problem is as I have successfully been able to use custom fonts in the past.
Any help will be appreciated.
If you leave the first element in your font array in the plist (index 0) blank, you will get this error.
PostScript fonts cannot be used with UIFont directly. You can use them only with CoreText or CATextLayer.
This can occur if the font in question is a Font Suitcase format. Open your application package, and if the font .ttf file shows a size of "Zero bytes", it's probably a font suitcase.
Files of this type can be converted using Fondu.
When running Fondu, I had to specify not just the suitcase file, but the resource fork inside it:
fondu mysuitcasefont.ttf/..namedfork/rsrc
This will extract any fonts in the suitcase to the current directory. It is these extracted files you will want to include in your iOS project and reference from the .plist.
I received this error when using a .ttf font. I was able to correct it by removing the file extension from the filename in (a) the resource in xcode and (b) the "Fonts provided by application" array in the .plist file.
Hopefully this will help.
I was trying to use Google Signika font on my App, and got the exact issue.
I solve the issue by using the .otf version of the font
Accepted answer is totally wrong and unnecessary. Probably you made a mistake when writing your font name.
Thats rules for that.
First Step : Write font name before .ttf extension. Example: For FFFTusj.ttf => FFFTusj
Second Step : Write - and after font style. Example: Bold or Medium etc. Example: #"FFFTusj-Bold"
And also dont forget add your font file to your project.
Check this link:
http://www.bycoder.com/post/2013/03/28/XCode-Custom-font-doesnt-work
If your font is REGULAR dont write -Regular at end of font name.
Adobe Flex 3: can I get TTF/OTF system fonts and embed at runtime?
Hi,
I'm a Stack Overflow noob so please go easy on me.
I've searched all day and found dozens of tutorial/examples on how to use [Embed] metadata or
Flash SWF files but they all tell me to either use a path in the source attrib or a text string in the systemFont attrib. What I want to do is; at runtime get all installed fonts on a given machine, determine which are TTF/OTF, embed them all and offer them in a comboBox. Something along these lines;
public function embedFonts():void{
try{
//get all device and embedded fonts
availableFonts = Font.enumerateFonts(true);
availableFonts.sortOn("fontName", Array.CASEINSENSITIVE);
for each(var thisFont:Font in availableFonts)
{
[Embed(systemFont=thisFont.fontName,
fontName=thisFont.fontName,
mimeType='application/x-font')]
//this bit need to create a unique variable name on each loop
var thisfont:Class;
}
}
catch(error:Error){
//if cant embed it's likely not to be TTF or OTF
//so move on to the next font.
}
}
Does anyone know a way?
Many, many thanks
You can't embed fonts at runtime.
And what would be the point?
Your swf runs on my machine, enumerates fonts on my machine, then embeds them
and offer them back to me? They are installed, use them directly, no need to embed.
So not only that is it not possible, but probably nobody will ever implement such a feature.