Open GoogleCodeExporter opened 9 years ago
Hi Thibault
The following is my code:
private function exportTest(event:MouseEvent):void
{
var myPDF:PDF=new UnicodePDF(Orientation.PORTRAIT, Unit.MM, Size.A4);
myPDF.addPage();
myPDF.textStyle(new RGBColor(0xce0000));
myPDF.addText(”American”, 55, 50);
myPDF.textStyle(new RGBColor(0×000000));
myPDF.setFont(new ArialUnicodeMS(), 16);
myPDF.addText(”我是中国人!”, 55, 70);
var myFileRef:FileReference=new FileReference();
myFileRef.save(myPDF.save(Method.LOCAL),”generate.pdf”);
}
Thanks!
Will
P.S: I am using Adobe Reader version is 9.2.0 Simplified Chinese
Original comment by shrekwhoosah
on 2 Dec 2009 at 11:20
Hi guys:
In the unicodePDF.as file, I found the following code:
bytes.push(char >> 0×08);
bytes.push(char & 0xFF);
outStr += String.fromCharCode(char >> 0×08);
outStr += String.fromCharCode(char & 0xFF);
If the file is generated English words, then export the document to open with
adobe
reader error prompt. So I changed the code:
bytes.push(char >> 0×08);
bytes.push(char & 0xFF);
if(char < 0xFF)
{
outStr+=String.fromCharCode(char & 0xFF);
}else
{
outStr += String.fromCharCode(char >> 0×08);
outStr += String.fromCharCode(char & 0xFF);
}
it works!
The generated file, I can use adobe reader to open. However, new problems have
come
out, there are some characters actually become the other. Such as “不” to
“上”。
Anybody have solution, please let me know.
I appreciate your help!
Will
Original comment by shrekwhoosah
on 4 Dec 2009 at 1:49
Hi Will,
i am also struggling with the same problem
i replaced the same 2 lines with:
tmp = char >> 0x08;
if(tmp != 0) outStr += String.fromCharCode(tmp);
tmp = char & 0xFF;
if(tmp != 0) outStr += String.fromCharCode(tmp);
i can open the PDF file in Adobe Reader 9.0.0 but i can't see the text (it is
not
visible).
I also tried your solution and after i set the ArialUnicodeMS font the text just
doesn't show up.
If you find a solution, please post it. I will do the same....
Original comment by zol...@gmail.com
on 4 Dec 2009 at 2:23
Hi Zollor:
1. Please provide your current operation of language.
2. C: \ Program Files \ Adobe \ Reader 9.0 \ Resource \ CIDFont, this is the
directory I installed adobe reader, in this directory, you can use to replace
some
of the font name of the ArialUnicodeMS.as in the protected var _name: String
= 'xxxxx';
May be able to help you!
Original comment by shrekwhoosah
on 4 Dec 2009 at 3:30
Hi Will,
thanks for your suggestion. I am using Windows 7 English.
My problem was that the Asian fonts were not downloaded by the AdobeReader.
After i let it to download the fonts, everything is working well. I am now
seeing the
characters.
I also found the problem why are the characters changed.
Example: “不” to “上”
The problem is that the carriage return character, is not treated correctly by
AlivePDF.
How to reproduce:
try to add the following text: "我是中国人不"
This should produce in the pdf: Td (bf/N-VýNşN\r) Tj
please observer the \r at the end
Alive PDF produces without the \r (instead it just inserts the 0x0D character.
I try to fix this now. If i found the solution i will post it...
Original comment by zol...@gmail.com
on 4 Dec 2009 at 3:39
Ok,
here is a quick solution, please let me know if it helped: You should replace
the
escapeIt function from the UnicodePDF.
protected override function escapeIt(content:String):String
{
var bytes:ByteArray = new ByteArray;
bytes.writeUTFBytes(content);
bytes.position = 0;
content = this.arrUTF8ToUTF16BE(UTF8StringToArray(content, bytes));
content =
findAndReplace(')','\\)',findAndReplace('(','\\(',findAndReplace('\\','\\\\',con
tent)));
content = content.replace('\r', "\\r");
return content;
}
Original comment by zol...@gmail.com
on 4 Dec 2009 at 4:16
Hi Zollor:
Great,it works!
I appreciate your help!
But I found that there are still problems, I tried to test this code,
myPDF.addText ( "我的姓名: Will 1982", 55, 70);
Display Asian fonts is correct, but behind the symbols, in English, as well as
the
figures are wrong.
Original comment by shrekwhoosah
on 4 Dec 2009 at 4:35
:),
i know, i am working on that.... however that one is a litle more
complicated....
It has to do with the NULL values.. in strings..
Also i think that the escapeIt function is more correct in this way:
protected override function escapeIt(content:String):String
{
var bytes:ByteArray = new ByteArray;
bytes.writeUTFBytes(content);
bytes.position = 0;
content = this.arrUTF8ToUTF16BE(UTF8StringToArray(content, bytes));
content =
findAndReplace(')','\\)',findAndReplace('(','\\(',findAndReplace('\\','\\\\',con
tent)));
content = findAndReplace('\n', "\\n",content);
content = findAndReplace('\r', "\\r",content);
content = findAndReplace('\t', "\\t",content);
content = findAndReplace('\b', "\\b",content);
content = findAndReplace('\f', "\\f",content);
return content;
}
PDF 1.5 Reference (page 30) enlists all the escape sequences in literal
strings, i
took the list from there.
Original comment by zol...@gmail.com
on 4 Dec 2009 at 5:09
Hi zollor:
You solved me a lot of trouble, Thank you very much for the help.
Will
Original comment by shrekwhoosah
on 4 Dec 2009 at 5:26
[deleted comment]
Hi Zollor:
I use the following code instead:
myPDF.setFont(new ArialUnicodeMS(), 16);
myPDF.addText("我的姓名w", 55, 70);
myPDF.setFont(new CoreFont(FontFamily.TIMES_BOLD), 12);
myPDF.addText(":Will1982", 100, 70);
But this method is very stupid.If you find a better solution, please post it. I
will
do the same...
Thanks!
Will
Original comment by shrekwhoosah
on 5 Dec 2009 at 1:12
I have to re-modify the code, adding a temporary variable, can deal with Asian,
English, symbols, numbers, the problem with garbled. Code is as follows:
var charTmp:uint=charTmp = unicode[0];
bytes.push(char >> 0x08);
bytes.push(char & 0xFF);
if(char < 0xFF && charTmp<0xFF)
{
outStr+=String.fromCharCode(char & 0xFF);
}else
{
outStr += String.fromCharCode(char >> 0x08);
outStr += String.fromCharCode(char & 0xFF);
}
Original comment by shrekwhoosah
on 6 Dec 2009 at 4:14
I just saw that i can attach a file..... here....
Anyway there is a patch for AlivePDFBeta rev 222, which makes Unicode
characters to work.
Let me know if it works.
Zoltan.
Original comment by zol...@gmail.com
on 6 Dec 2009 at 11:20
Attachments:
Hi Zoltan:
Thank you for your help.
I have based on your patch fixes the code...it works...
Then I used the following code to test:
var myPDF:PDF=new UnicodePDF(Orientation.PORTRAIT, Unit.MM, Size.A4);
myPDF.addPage();
myPDF.textStyle(new RGBColor(0xce0000));
myPDF.setFont(new CoreFont(FontFamily.TIMES_BOLD), 50);
myPDF.addText("American", 35, 50);
myPDF.textStyle(new RGBColor(0x000000));
myPDF.setFont(new ArialUnicodeMS(), 16);
myPDF.addText("我的姓名:", 55, 70);
myPDF.addText("Will 1982(&#%)", 50, 90);
myPDF.addText("我是中国人!", 50, 100);
When I used the Adobe Reader is open, you can open, and also the normal display
the
contents. But it will pop-up dialog box: There is an error on this page.
Acrobat may
not display correctly page. Please contact the creator of PDF documents to
correct
the error.
Thanks!
Will
Original comment by shrekwhoosah
on 6 Dec 2009 at 12:05
I manage to have it with no more error when opening the file by checking out the
trunk and doing 2 modifications.
What I used for testing (Japanese instead of Chinese, but it should work for
Chinese).
var myPDF:PDF=new UnicodePDF(Orientation.PORTRAIT, Unit.MM, Size.LETTER);
//var myPDF:PDF= new PDF(Orientation.PORTRAIT, Unit.MM, Size.LETTER);
myPDF.setFont(new ArialUnicodeMS( CidInfo.JAPANESE ), 16);
var page:Page = new Page ( Orientation.PORTRAIT, Unit.MM, Size.LETTER, 0 );
myPDF.addPage ( page );
myPDF.textStyle(new RGBColor(0xce0000));
myPDF.addText("American", 55, 50);
myPDF.textStyle(new RGBColor(0x000000));
myPDF.addText("ショッピング", 55, 70);
var myFileRef:FileReference=new FileReference();
myFileRef.save(myPDF.save(Method.LOCAL),"generate.pdf");
At 1st I removed the Japanese 'addText' and the reference to the Japanese font
from
my text program and I compared both generated PDF using UnicodePDF and PDF and I
trace all calls to 'escapeString'.
I notice that the method insertOCG() was using for:
//write('<</Type /OCG /Name '+escapeString('print'));
write('<</Type /OCG /Name '+'(print)');
and
// write('<</Type /OCG /Name '+escapeString('view'));
write('<</Type /OCG /Name '+'(view)');
In the 'normal' pdf file the 'print' and the 'view' were not saved as UTF16BE
but
they were when using UnicodePDF. I hardcoded it with '()' and tested it with
both the
PDF and UnicodePDF and it removes the error when I open the file.
Can someone confirm that it was wrong to encode both 'print' and 'view' as
UTF16BE ?
Original comment by martin.m...@gmail.com
on 8 Dec 2009 at 5:37
I searched in PDF.as for 'escapeString' :
PDF.as(1966): if ( link is HTTPLink ) currentPage.annotations += "/A <</S /URI
/URI
"+escapeString((link as HTTPLink).link)+">>>>";
PDF.as(4300): write('/JS '+escapeString(js));
PDF.as(4326): // write('<</Type /OCG /Name '+escapeString('print'));
PDF.as(4332): // write('<</Type /OCG /Name '+escapeString('view'));
PDF.as(4381): write('<</Title '+escapeString(p.text));
PDF.as(4403): write ('/Producer '+escapeString('AlivePDF
'+PDF.ALIVEPDF_VERSION));
PDF.as(4404): if ((documentTitle != null)) write('/Title
'+escapeString(documentTitle));
PDF.as(4405): if ((documentSubject != null)) write('/Subject
'+escapeString(documentSubject));
PDF.as(4406): if ((documentAuthor != null)) write('/Author
'+escapeString(documentAuthor));
PDF.as(4407): if ((documentKeywords != null)) write('/Keywords
'+escapeString(documentKeywords));
PDF.as(4408): if ((documentCreator != null)) write('/Creator
'+escapeString(documentCreator));
PDF.as(4409): write('/CreationDate '+escapeString('D:'+getCurrentDate()));
I did not test it, but I checked the file and as an example the line:
PDF.as(4403):
write ('/Producer '+escapeString('AlivePDF '+PDF.ALIVEPDF_VERSION)); seem to be
producing the wrong result in UnicodePDF:
/Producer (/CreationDate (>>
but ok in PDF:
/Producer (AlivePDF 0.1.5)
/CreationDate (D:20091280013)
Which is confirmed when you do 'file/properties' the unicode version will
generate an
error message, but not once you modify the code for:
//write ('/Producer '+escapeString('AlivePDF '+PDF.ALIVEPDF_VERSION));
write ('/Producer '+'(AlivePDF '+PDF.ALIVEPDF_VERSION+')');
and:
//write('/CreationDate '+escapeString('D:'+getCurrentDate()));
write('/CreationDate '+'(D:'+getCurrentDate() + ')');
Original comment by martin.m...@gmail.com
on 8 Dec 2009 at 6:01
I think the fix for escapeIt should be in PDF.as, as both should have encoded
them:
protected function escapeIt(content:String):String
{
return
findAndReplace(')','\\)',findAndReplace('(','\\(',findAndReplace('\\','\\\\',con
tent)));
content = findAndReplace('\n', "\\n",content);
content = findAndReplace('\r', "\\r",content);
content = findAndReplace('\t', "\\t",content);
content = findAndReplace('\b', "\\b",content);
content = findAndReplace('\f', "\\f",content);
}
and UnicodePDF.as should invoke its super instead at the end of the method:
protected override function escapeIt(content:String):String
{
var bytes:ByteArray = new ByteArray;
bytes.writeUTFBytes(content);
bytes.position = 0;
content = this.arrUTF8ToUTF16BE(UTF8StringToArray(content, bytes));
return super.escapeIt(content); }
}
Original comment by martin.m...@gmail.com
on 8 Dec 2009 at 1:08
Hi All,
I' unable to generate a PDF with Greel Characters kindly help me out in fixing
this issue
Original comment by ramkumar...@gmail.com
on 13 Dec 2009 at 1:24
Hi Zoltan, can you please explain to inexperienced programmers how to implement
your
patch 222.... thanks, I couldn't figure it out...
Original comment by yosi...@gmail.com
on 22 Feb 2010 at 1:29
I had fixed the pach.Chinese charactor can display but english charactors
cant't...
when i addgrid,the grid head is chinese ,bu grid contents is number.the
contents
Garbled
Original comment by lihaigr...@gmail.com
on 1 Apr 2010 at 1:17
private function cnExport(event:MouseEvent):void
{
var myPDF:UnicodePDF=new UnicodePDF(Orientation.PORTRAIT, Unit.MM, Size.A4);
myPDF.addEventListener(ProcessingEvent.STARTED, generationStarted);
myPDF.addEventListener(ProcessingEvent.PAGE_TREE, pageTreeGeneration);
myPDF.addEventListener(ProcessingEvent.RESOURCES, resourcesEmbedding);
//myPDF.addEventListener(ProcessingEvent.COMPLETE, generationComplete);
myPDF.addPage();
//top
myPDF.addImageStream(new topBytes()as ByteArray, ColorSpace.DEVICE_RGB,
null, 0, 0, 45, 20);
myPDF.addImageStream(new top1Bytes()as ByteArray, ColorSpace.DEVICE_RGB,
null, 220, 0, 110, 20);
//Line
myPDF.lineStyle(new RGBColor(0x000000), .3, 0, 1);
myPDF.moveTo(10, 32);
myPDF.lineTo(200, 32);
myPDF.end();
myPDF.textStyle(new RGBColor(0xce0000));
myPDF.setFont(new CoreFont(FontFamily.TIMES_BOLD), 50);
myPDF.addText("AmericanAirFilter", 35, 60);
myPDF.textStyle(new RGBColor(0x000000));
myPDF.setFont(new ArialUnicodeMS(), 22);
myPDF.addText("过 滤 器 运 行 费 用 分 析", 65, 100);
//
myPDF.lineStyle(new RGBColor(0x000000), 1, 0, 1);
myPDF.beginFill(new RGBColor(0xffffff));
myPDF.drawRoundRect(new Rectangle(60, 120, 100, 80), 5);
myPDF.endFill();
myPDF.setFont(new ArialUnicodeMS(), 12);
myPDF.addText("项目名称: ", 80, 130);
//customer name
isChinese(DealRequest.analysis.customer, myPDF, new CoreFont
(FontFamily.ARIAL), 14);
}
//判断中文还是英文,
private function isChinese(content:String, pdf:UnicodePDF, fs:CoreFont,
size:int):void
{
var bytes:ByteArray=new
ByteArray;
bytes.writeUTFBytes
(content);
bytes.position=0;
var unicode:Array=pdf.UTF8StringToArray(content,
bytes);
var char:uint=unicode
[0];
if (char <
0xFF)
{
pdf.setFont(fs,
size);
}
else
{
pdf.setFont(new ArialUnicodeMS(),
size);
}
}
Hope to help you.
Original comment by shrekwhoosah
on 3 Apr 2010 at 4:03
I am new to AlivePDF and I am working on a FLEX project that required unicode
support to display characters such as Chinese, Japanese, etc.
I am using 0.1.5RC and hit into the same problem of Adobe Reader not able to
open my generated PDF file.
I read this thread and was delight that there is a patch to solve this problem.
However as I am new to Actionscript and AlivePDF, I need advice on how to do
the patching.
Thanks in advance.
Original comment by tony...@gmail.com
on 10 Apr 2011 at 4:26
Hi,
Does the issue fixed finally? I also encounter it now.
UnicodePDF + ArialUnicodeMS + AlivePDF_rev222_Unicode_Fix.patch
Thanks in advance.
Original comment by freehove...@gmail.com
on 24 Jun 2011 at 1:32
yes
Original comment by shrekwhoosah
on 28 Jun 2011 at 2:21
[deleted comment]
Has anyone able to solve the issue with mixing of Asian character + English?
I'm stuck with my project because of this. I have no options of breaking them
into seperate addText(), they need to be one addText(). Thanks so much.
"myPDF.addText ( "我的姓名: Will 1982", 55, 70);
Display Asian fonts is correct, but behind the symbols, in English, as well as
the figures are wrong."
Original comment by BenZho...@gmail.com
on 3 Oct 2011 at 9:48
I'm having issues as well when mixing Asian characters (japanese to be exact)
and something as simple as numbers. This happens when I'm adding a multicell,
e.g.
unicodePDF.addMultiCell(180, 10, "日付: 月日年(10/12/2011) 賛成:
12 反対: 0", 0, "L");
The PDF prints the string as: 日付: 杜瓿屢10/12/2011|琀
0
While debugging the code, when I set the breakpoint right before adding the
multiCell, the string is correct all the way up to this line in UnicodePDF.as:
content = this.arrUTF8ToUTF16BE(UTF8StringToArray(content, bytes));
From there, my flash builder debugger craps out when it converts it to an array
and I can't see what the value of content is after that function call. But I
think there may be a bug within the code where it's doing the bit operation.
I'm not sure if it's happening within the UTF8StringToArray or arrUTF8ToUTF16BE
method, though.
Original comment by sor...@gmail.com
on 12 Oct 2011 at 4:56
//判断中文还是英文,
private function isChinese(content:String, pdf:UnicodePDF, fs:CoreFont, size:int):void
{
var bytes:ByteArray=new ByteArray;
bytes.writeUTFBytes(content);
bytes.position=0;
var unicode:Array=pdf.UTF8StringToArray(content, bytes);
var char:uint=unicode[0];
if (char < 0xFF)
{
pdf.setFont(fs, size);
}
else
{
pdf.setFont(new ArialUnicodeMS(), size);
}
}
Original comment by shrekwhoosah
on 13 Oct 2011 at 5:43
Hi Will,
Thanks for the help, my main issue of mixing different languages are resolved
now after I used the latest code from trunk
(http://alivepdf.googlecode.com/svn/trunk/), I would save a lot of time if I
read more carefully of your earlier post. :). Couple questions, I still get an
error when I open the result pdf, some alignments are off but the text are
showing. Do you know why I'm getting the errors? I've attached the screen
grab. Secondly, I'm still not very clear with your isChinese() method, does it
only apply the font for last edited cell? Again, thanks so much for all your
work.
Original comment by BenZho...@gmail.com
on 24 Oct 2011 at 9:32
Attachments:
On the first question, I do not know your practice, can you post your code? On
the second question, as my projects are needed in the PDF document displayed in
Chinese and English, although in AlivePDF in Unicode solves the most, but I
found will be garbled, so I will first determine when to display Chinese, when
is the time to Chinese, I will set the font to use " new ArialUnicodeMS ".
Original comment by shrekwhoosah
on 27 Oct 2011 at 6:20
Hi Will,
For problem #1 with getting error popup in pdf, I used code below
var myPDF:UnicodePDF = new UnicodePDF(Orientation.PORTRAIT, Unit.INCHES,
Size.LETTER);
myPDF.setDisplayMode(Display.FULL_PAGE);
myPDF.setFont(new ArialUnicodeMS(CidInfo.JAPANESE),14);
myPDF.addPage();
//I start getting the error whenever I add following two line into my code
myPDF.addText("ダミー履歴書ABCDEFG",0, 1.8);
myPDF.addText("abcdef",0, 7.8);
var fileRef:FileReference = new FileReference();
fileRef.save( myPDF.save ( Method.LOCAL ), "履歴書.pdf" );
Thanks!
Original comment by BenZho...@gmail.com
on 1 Nov 2011 at 4:28
The second problem that I have is that some characters always gets garbled,
like "名" and "希望"
var myPDF:UnicodePDF = new UnicodePDF(Orientation.PORTRAIT, Unit.INCHES,
Size.LETTER);
myPDF.setDisplayMode(Display.FULL_PAGE);
myPDF.setFont(new ArialUnicodeMS(CidInfo.JAPANESE),14);
myPDF.addPage();
myPDF.addText("名前:",0, 2.8);
myPDF.addText("電話番号:",0, 3.8);
myPDF.addText("希望",0, 4.8);
myPDF.addText("販売店情報:",0, 5.8);
myPDF.addText("販売店名:",0, 6.8);
var fileRef:FileReference = new FileReference();
fileRef.save( myPDF.save ( Method.LOCAL ), "履歴書.pdf" );
Thanks
Original comment by BenZho...@gmail.com
on 1 Nov 2011 at 4:37
Any updates to this? I'd love to see the garbled character issue resolved.
Thanks.
Original comment by sor...@gmail.com
on 15 Nov 2011 at 5:06
Original issue reported on code.google.com by
shrekwhoosah
on 2 Dec 2009 at 11:19