You are not logged in.
i need to create a pdf file from the emf files with simple chinese fonts, but the error in "setfont" function occured.
i use SynPdf 1.8.1, and here is my simple code:
var
PDF: TPDFDocument;
m:TMetafile;
i:integer;
begin
PDF:= TPDFDocument.Create;
pdf.DefaultPaperSize := psA4;
m := TMetafile.Create;
m.LoadFromFile('c:\1\1.emf');
with pdf do
try
// pdf.EmbeddedTTF := true;
// PDF.EmbeddedWholeTTF := true;
PDF.UseUniscribe := true;
StandardFontsReplace := true;
AddPage;
// Canvas.SetFont('宋体',12,[fsItalic,fsBold]);
Canvas.RenderMetaFile(m,1);
SaveToFile('c:\1.pdf');
finally
Free;
end;
m.free;
end.
i wonder how to upload the emf file.
thanks and best regards!
Offline
Note that calling SetFont() before RenderMetaFile won't do nothing: the RenderMetaFile will override the SetFont parameters.
Font names are expected to be win-ansi encoded, i.e. in enligsh characters... no equivalency of this font does exists?
Offline
thanks for your reply!
i print the ms word file with simple chinese font into emf files, so the font should be "simple chinese font".
Could you give me your email address, i will email you the emf file?
thanks again!
Offline
thank you.
i sent you an email with the emf file attached.
Offline
hi,ab:
i am still not able to transform my emf file to pdf file.
did you receive my email with the emf file which i used?
thanks!
Offline
with the latest html2pdf,i also got an error message.
i sent you an email with the screenshot.
Best Regards!
Offline
thanks.
it was the same message when i convert my emf file to the pdf file.
Offline
I've made some upload in SynCommons.pas and SynPdf.pas, after having found a bug in font name comparison.
Please check in from http://synopse.info/fossil and try to run it.
Otherwise, as I said in my mail:
Can you make a little debugging on your computer?
Such a message indicates that the 'Arial' font is not found.
Is suspect the name is invalid.
Can you put a breakpoint in TPdfCanvas.SetFont() then check what's wrong?
The breakpoint must be made in line:raise EPdfInvalidValue.CreateFmt('SetFont %s',[AName]); // error
Can you give me also the fDoc.FTrueTypeFonts.Text content in this content?
Offline
i sent u an email with attached files.
thanks.
Offline
i used the latest synpdf from http://synopse.info/fossil in the debug mediafile.
Offline
setFont times New Roman.
Offline
can't SameText()
so FontIndex always equal -1, then Error occurs.
Offline
it seems that the content of fDoc.FTrueTypeFonts list is different from which in my windows fonts directory.
my computer system is windows XP with service pack 2
Offline
it seems that the content of fDoc.FTrueTypeFonts list is different from which in my windows fonts directory.
my computer system is windows XP with service pack 2
PDF uses Embeded font,mostly don't support Chinese Font. In order to show Chinese Fonts ,it's necessary to translate it.
Offline
They must be an error with chinese code page and such... I'll check.
i have sent you an Email ,please Check it.
Offline
In order to show Chinese Fonts ,it's necessary to translate it.
how to translate it,any idea?
thanks.
Offline
It was definitively a "charset" problem...
In TPdfDocument.Create, it enumerates fonts only for the current CharSet: therefore, it enumerated only fonts with chinese characters if the current CharSet was Chinese.
I just changed the corresponding line to:
LFont.lfCharset := DEFAULT_CHARSET; // FCharSet will avoid Arial or Times New Roman
Here is the new callback code:
function EnumFontsProc(var LogFont: TLogFont; var TextMetric: TTextMetric;
FontType: Integer; Doc: TPdfDocument): Integer; stdcall;
// we enumerate all available fonts, whatever the charset is, because
// we may won't enumerate Arial if current FCharSet is chinese e.g.
var Temp: string;
begin
with LogFont do
if (FontType=TRUETYPE_FONTTYPE) and (lfFaceName[0]<>'@') then begin
Temp := lfFaceName;
with Doc.FTrueTypeFonts do
if (Count=0) or not SysUtils.SameText(Strings[Count-1],Temp) then
Add(Temp);
end;
Result := 1;
end;
This new 1.8.5 version uploaded to our source code repository should correct your problems.
Offline
many thanks,but two problems are remained:
1. the text position is not exactly right.
2. part of content did not also appeared.
i sent you an email,please check.
Offline
now ,it can create PDF file ,but can't show chinese fonts, all are Error code.
Offline
Exception class EAccessViolation with message 'Access violation at address 004C021A
Which line source code is it? Hexa address are pointless, because it depends on your compiler and libraries...
I suspect you didn't get all modifications from our source code repository, but modified the code by hand, according to my comment in my previous post, which is not enough.
Offline
longge007 wrote:Exception class EAccessViolation with message 'Access violation at address 004C021A
Which line source code is it? Hexa address are pointless, because it depends on your compiler and libraries...
I suspect you didn't get all modifications from our source code repository, but modified the code by hand, according to my comment in my previous post, which is not enough.
yeah, it's right, i only change some.
Offline
test html codes
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>无标题文档</title>
</head>
<body>
<strong><font size="+5">20100716测试中文字体,中国北京</font></strong><br>
Test chinese Font
</body>
</html>
Offline
you can install asian fonts in you pc, and then test it
Offline
my computer system is windows XP with service pack2 and simple chinese fonts.
Offline
Problem about html comes not from SynPdf here...
i think the problem is from synpdf , or Thtmlview code.
for i test the Example5 ,i write some chinese words in the Text, it also shows wrong fonts.
Offline
I've updated the SynPdf unit in the Source Code Repository:
Version 1.8.6
- system font enumeration is now stored using UTF-8, and any non ASCII font name will used in the PDF content the official Postscript name extracted from its TrueType font content;
- optional charset parameter is now available in TPdfCanvas.SetFont: this was needed in case of TMetaFile rendering to fix some encoding problems.
It should fix some problems about chinese fonts. But THtmlView is not able to read UTF-8 content by now.
Offline
many thanks,but two problems are remained:
1. the text position is not exactly right.
2. part of content did not also appeared.
I've updated the SynPdf unit in the Source Code Repository:
Version 1.8.6
- system font enumeration is now stored using UTF-8, and any non ASCII font name will used in the PDF content the official Postscript name extracted from its TrueType font content;
- optional charset parameter is now available in TPdfCanvas.SetFont: this was needed in case of TMetaFile rendering to fix some encoding problems.
It should fix some problems about fonts with name encoded in Chinese (I hope).
Offline
many many thanks,ab
update the source code,two problems are still remained:
1. the text position is not exactly right, all arranged on the upper left corner.
2. many more text does appear, but a few part of content is still not appeared.
Offline
i just try it,the chinese words of emf file are all generated into pdf file,but they can not display properly in pdf file.
during generate pdf file,some exceptions are fired near the following code of synpdf.pas:
constructor TPdfTTF.Create(aUnicodeTTF: TPdfFontTrueType);
......
for i := 0 to aUnicodeTTF.fUsedWideChar.Count-1 do
with aUnicodeTTF.fUsedWide[i] do
if Glyph<>0 then
Width := (cardinal(fhmtx[Glyph*2])*1000) shr fUnitsPerEmShr;
Offline
yes, a big vague ,because i can not past picture or file here.
the exception line is:
Width := (cardinal(fhmtx[Glyph*2])*1000) shr fUnitsPerEmShr;
exception msg:
'Access violation at address 004626A7 in module 'Project1.exe'. Read of address 004B4000'
Are you sure the TTF file is a true outline font?
i m not sure,indeed.
Offline
I've modified the TTF reading, in order to had a check for the size of the fhmtx[] array.
See http://synopse.info/fossil/info/87a1242747
Offline
i really appreciate.
with my own rtf and emf files, no exception raised any more,but:
1. in pdf file,no chinese word appears,if i switch to view this pdf document as text file,then all chinese words appear.
2. position of numeric word in the pdf is not exactally correct.
i send pdf files to you,pls check it: abouchez@magic.fr
Offline
i sent an email including emf and pdf files to you last night,please check it.
Offline
procedure TForm1.Button3Click(Sender: TObject);
var
Gdip:TGDIPlusFull;
emf:TMetaFile;
begin
Gdip := TGDIPlusFull.Create;
emf := TMetaFile.Create;
try
emf.LoadFromFile('c:\emf\1.emf');
gdip.DrawAntiAliased(emf,PaintBox1.Canvas.Handle,Rect(0,0,300,500));
finally
emf.Free;
Gdip.Free;
end;
end;
PaintBox1 can display all of the emf file including chinese words and bitmap.
if i change above code as the following, the produced pdf file just contains bitmap,but no chinese words at all.
procedure TForm1.Button2Click(Sender: TObject);
const
OutputFileName = 'c:\emf\1.pdf';
InputFileName = 'c:\emf\1.emf';
var
PdfDoc: TPDFDocumentGDI;
PdfPage: TPdfpage;
Emf: TMetafile;
begin
Emf := TMetafile.Create();
Emf.LoadFromFile(InputFileName);
PdfDoc := TPdfDocumentGDI.Create;
PdfDoc.UseFontFallBack := true;
PdfDoc.CompressionMethod := cmFlateDecode;
PdfDoc.DefaultPaperSize := psUserDefined;
PdfPage := PdfDoc.AddPage();
PdfPage.PageWidth := Round(72 * Emf.MMWidth / 2540);
PdfPage.PageHeight := Round(72 * Emf.MMHeight / 2540);
gdip.DrawAntiAliased(emf,PdfDoc.VCLCanvas.Handle,Rect(0, 0,
//gdip.DrawAntiAliased(emf,PaintBox1.Canvas.Handle,Rect(0, 0,
Round(Screen.PixelsPerInch * Emf.MMWidth / 2540),
Round(Screen.PixelsPerInch * Emf.MMHeight / 2540)));
PdfDoc.SaveToFile(OutputFileName);
PdfDoc.Free();
FreeAndNil(Emf);
end;
Offline
i download ARIALUNI.TTF from http://anonym.to/?http://sourceforge.ne … nts/files/, and then set FontFallBackName like this:
PdfDoc.FontFallBackName := 'Arial Unicode MS';
the chinese words are still missing.
i also download synpdfunicode_test.rar from https://cdn.anonfiles.com/1363978013590.rar , and it works as expected.
BTW,i am using the latest code.
Last edited by profh (2013-04-08 09:35:48)
Offline
DrawAntiAliased in SynGdiPlus.pas is like this:
procedure TGDIPlus.DrawAntiAliased(Source: TMetafile; Dest: HDC; R: TRect;
aSmoothing: TSmoothingMode; aTextRendering: TTextRenderingHint);
begin
dec(R.Right);
dec(R.Bottom); // Metafile rect includes right and bottom coords
PlayEnhMetaFile(Dest,Source.Handle,R); // use GDI drawing by default
end;
but PlayEnhMetaFile is a windows function, i can not step in it.
Offline
I just checked your code.
It does not make sense at all to call DrawAntiAliaised() over a PDF canvas.
GDI+ targets bitmap content, not vectorial content.
Just draw the emf content to the PDF canvas, as stated by all sample code around.
Offline
i use htm2pdf in the latest package from http://synopse.info/fossil/wiki/Synopse+OpenSource, and open a html file with chinese words, then save html file to pdf file, the chinese words are still missing in the output pdf file, but the metafile produced by htmlview contains all things in the html file.
could you give me a sample, many thanks.
Offline
i change line 5827 of synpdf.pas
from:
RawUnicodeToUtf8(ALogFont.lfFaceName,StrLenW(ALogFont.lfFaceName));
to:
AName := ALogFont.lfFaceName;
then the following code can render emf file including all chinese words into pdf file:
procedure TForm1.Button6Click(Sender: TObject);
var
emf : TMetafile;
Pdf: TPdfDocument;
begin
emf := TMetafile.Create;
Pdf := TPdfDocument.Create;
try
emf.LoadFromFile('c:\emf\21.emf');
Pdf.EmbeddedTTF := True;
pdf.StandardFontsReplace := true;
pdf.PDFA1 := true;
Pdf.UseFontFallBack := true;
Pdf.FontFallBackName := 'Arial Unicode MS';
Pdf.DefaultPageWidth := MulDiv(emf.Width,72,Pdf.ScreenLogPixels);
Pdf.DefaultPageHeight := MulDiv(emf.Height,72,Pdf.ScreenLogPixels);
Pdf.AddPage;
Pdf.Canvas.RenderMetaFile(emf);
pdf.SaveToFile('c:\emf\test.pdf');
finally
FreeAndNil(emf);
FreeAndNil(pdf);
end;
end;
but the position and size of some words are unusual.
i sent an email with "pdf from emf.jpg" and "emf21.emf" to webcontact01 at synopse.info, please check it.
Offline
i use delphi7 and the latest great mORMot.
thanks.
Offline
I just checked the code.
With Delphi 7, it indicates that the internal true type font list is not encoded in UTF-8, but in Ansi.
Weird... I'm not able to reproduce it here.
We use TLogFontW in each API call, i.e. the Unicode version of it, not the Ansi version..
What is the font name?
What is the exact ALogFont.lfFaceName buffer content?
What is the value stored by EnumFontsProcW() into FTrueTypeFonts[] ?
Offline