Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82288

TableTools Turkish Character Fix (May help UTF-8 Problems)

$
0
0
Hello all,

Today I managed to fix Turkish character problems for tabletools Excel and PDF export feature.

The main problem is starting from AlivePDF's source code.
1- Download AlivePDF 0.1.5 RC.zip from https://code.google.com/p/alivepdf/downloads/list . Extract the src folder to c:\AlivePDF>src folder

2- Than browse to the C:\AlivePDF\src\org\alivepdf\pdf. You will see PDF.as file there. Open it with text editor and find this line.
buffer.writeMultiByte( content+"\n", "windows-1252" );
3- So every char becomes windows-1252 chacters which doesn't have UTF8 characters. To fix this problem locally, I had replaced the line with:
buffer.writeMultiByte( content+"\n", "windows-1254" ); windows-1254 can be used for Turkish Character encodings. (You can change it to your local language's charset)

4- After replacing the code, you need to generate swc file to use with tabletools. For generating swc file, you need flex SDK. You can download it from here: http://www.adobe.com/devnet/flex/flex-sdk-download.html

5- Extract the SDK to the C:\flex_sdk_4.6

5- Open the cmd as administrator and write this command:

c:\flex_sdk_4.6\bin\compc -source-path c:\alivepdf\src -include-sources C:\AlivePDF\src\org\alivepdf\pdf -optimize -output C:\AlivePDF\AlivePDF.swc
You will have new generated swc file under c:\AlivePDF\AlivePDF.swc

6- Now copy the AlivePDF.swc file to C:\flex_sdk_4.6\frameworks\libs folder.

7- Find a suitable font that supports your characters. I tried Times New Roman but it was 800 kB~ so the SWF file became 500 kB+ I used Arial Narrow. Copy the font file to C:\flex_sdk_4.6\bin
For example I copied arial.ttf from Windows\Fonts folder.

8- Convert ttf file to afm with this website: http://everythingfonts.com/ttf-to-afm
Download the afm file to C:\flex_sdk_4.6\bin as arial.afm

9- We will embed this new font to use it with datatables. So we will have new character support.
Download https://github.com/DataTables/TableTools/blob/master/media/as3/ZeroClipboardPdf.as file and rename it to ZeroClipboard.as and copy this file to C:\flex_sdk_4.6\bin again.

9- Open the as file with text editor and add this code block under new variable definitions.


import org.alivepdf.fonts.CodePage; import org.alivepdf.fonts.EmbeddedFont; [Embed( source="/arial.ttf", mimeType="application/octet-stream" )] private var fontStream:Class; [Embed( source="/arial.afm", mimeType="application/octet-stream" )] private var afmStream:Class;
It should be like:
/* PDF imports */ import org.alivepdf.pdf.PDF; import org.alivepdf.data.Grid; import org.alivepdf.data.GridColumn; import org.alivepdf.layout.Orientation; import org.alivepdf.layout.Size; import org.alivepdf.layout.Unit; import org.alivepdf.display.Display; import org.alivepdf.saving.Method; import org.alivepdf.fonts.FontFamily; import org.alivepdf.fonts.CoreFont; import org.alivepdf.fonts.CodePage; import org.alivepdf.fonts.EmbeddedFont; import org.alivepdf.colors.RGBColor; public class ZeroClipboard extends Sprite { private var domId:String = ''; private var button:Sprite; private var clipText:String = 'blank'; private var fileName:String = ''; private var action:String = 'copy'; private var incBom:Boolean = true; private var charSet:String = 'utf8'; [Embed( source="/arial.ttf", mimeType="application/octet-stream" )] private var fontStream:Class; [Embed( source="/arial.afm", mimeType="application/octet-stream" )] private var afmStream:Class;
10- Find /* Create the PDF */ section.
Add this line upper side of it.
var ef:EmbeddedFont = new EmbeddedFont( new fontStream(), new afmStream(), CodePage.CP1254 );
You can change the CodePage to your local language charset.

Under the comment add this line also.
pdf.setFont( ef, 13 );
It should be like:
var ef:EmbeddedFont = new EmbeddedFont( new fontStream(), new afmStream(), CodePage.CP1254 ); /* Create the PDF */ pdf = new PDF( Orientation[orientation.toUpperCase()], Unit.MM, Size[size.toUpperCase()] ); pdf.setFont( ef, 13 ); pdf.setDisplayMode( Display.FULL_WIDTH ); pdf.addPage(); iPageWidth = pdf.getCurrentPage().w-20; pdf.textStyle( new RGBColor(0), 1 );
11- In my case,
import org.alivepdf.fonts.Style; was not identified by the compiler. So I removed it.

/* Add the title / message if there is one */ pdf.setFont( new CoreFont(FontFamily.HELVETICA), 14 ); if ( title != "" ) { pdf.writeText(11, title+"\n"); } pdf.setFont( new CoreFont(FontFamily.HELVETICA), 11 ); if ( message != "" ) { pdf.writeText(11, message+"\n"); }

replaced the part with:

/* Add the title / message if there is one */ pdf.setFont( ef, 13 ); if ( title != "" ) { pdf.writeText(11, title+"\n"); } pdf.setFont( ef, 11 ); if ( message != "" ) { pdf.writeText(11, message+"\n"); }


__________________________________________________
Here is my updated files:
http://www.mediafire.com/download/9cp1xbcead1i3j6/arial.afm
http://www.mediafire.com/download/m7h2brh40ken247/arial.ttf
http://www.mediafire.com/download/mycsygt356eg5up/AlivePDF.swc
http://www.mediafire.com/view/bm6e605wqq5zwh5/ZeroClipboard.as
http://www.mediafire.com/download/9g1s27ppd779jbx/copy_csv_xls_pdf.swf

Now use this command to produce new swf file:

c:\flex_sdk_4.6\bin\mxmlc -static-link-runtime-shared-libraries=true -library-path=C:\flex_sdk_4.6\frameworks\libs ZeroClipboard.as
It will export ZeroClipboard.swf file to c:\flex_sdk_4.6\bin rename it to copy_csv_xls_pdf.swf and put the file to your website content.

__________________________________________________

I know it looks hard but it goes easy if everything works. If you have more questions, I will try to help.

Regards,
Ali

Viewing all articles
Browse latest Browse all 82288

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>