Open GoogleCodeExporter opened 8 years ago
I tried to overcome this above issue by extending the PDF class and overriding
the
addMulticell method.
The addMulticell method currently takes a string object alone. If this method
is
generalized to get all objects including the image or bytearray the above issue
will
be resolved.
currently i am overriding the addMulticell to achieve the above functionality.
Below is the sample code.
override public function addMultiCell ( width:Number, height:Number,
text:String,
border:*=0, align:String='J', filled:int=0):void
{
this.width=width;
this.height=height;
cw = currentFont.cw;
var imageType:String="";
if(text.indexOf("Image:")!=-1)
{
imageType=text.substr(text.indexOf(":"));
addImageStream
(Application.application.bytes,currentX,currentY,0, 0, 1);
}
else
{
if ( width==0 ) width = currentPage.w-rMargin - currentX;
var wmax:Number = (width-2*cMargin)*1000/fontSize;
var s:String = findAndReplace ("\r",'',text);
var nb:int = s.length;
if( nb > 0 && s.charAt(nb-1) == "\n" ) nb--;
var b:* = 0;
if( border )
{
if( border == 1 )
{
border='LTRB';
b='LRT';
b2='LR';
}
else
{
b2='';
if(border.indexOf('L')!= -1) b2+='L';
if(border.indexOf('R')!= -1) b2+='R';
b = (border.indexOf('T')!= -1) ? b2+'T' : b2;
}
}
var sep:int = -1;
var i:int = 0;
var j:int = 0;
var l:int = 0;
var ns:int = 0;
var nl:int = 1;
var c:String;
var cwAux:int = 0;
while (i<nb)
{
c = s.charAt(i);
if (c=="\n")
{
if (ws>0)
{
ws=0;
write('0 Tw');
}
addCell(width,height,s.substr(j,i-j),b,2,align,filled);
i++;
sep=-1;
j=i;
l=0;
ns=0;
nl++;
if(border && nl==2) b=b2;
continue;
}
if(c==' ')
{
sep=i;
var ls:int = l;
ns++;
}
// TBO
cwAux = cw[c] as int;
if (cwAux == 0) cwAux = 580;
l += cwAux;
if (l>wmax)
{
if(sep==-1)
{
if(i==j) i++;
if(ws>0)
{
ws=0;
write('0 Tw');
}
addCell(width,height,s.substr(j,i-j),b,2,align,filled);
}
else
{
if(align==Align.JUSTIFIED)
{
ws=(ns>1) ? (wmax-ls)/1000*fontSize/(ns-1) : 0;
write(sprintf('%.3f Tw',ws*k));
}
addCell(width,height,s.substr(j,sep-j),b,2,align,filled);
i=sep+1;
}
sep=-1;
j=i;
l=0;
ns=0;
nl++;
if ( border && nl == 2 ) b = b2;
}
else i++;
}
//Last chunk
if(ws>0)
{
ws=0;
write('0 Tw');
}
if ( border && border.indexOf ('B')!= -1 ) b += 'B';
addCell ( width,height,s.substr(j,i-j),b,2,align,filled );
currentX = lMargin;
}
}
Original comment by umarfaro...@gmail.com
on 6 Jul 2009 at 4:18
Attachments:
Hi Thiabult,
I believe you would have a better solution for acheiving the above
functionality.
If possible try to incorporate the above functionality in the next 1.5 release.
Original comment by umarfaro...@gmail.com
on 6 Jul 2009 at 4:20
Hi Thiabult,
I believe you would have a better solution for acheiving the above
functionality.
If possible try to incorporate the above functionality in the next 1.5 release.
Original comment by umarfaro...@gmail.com
on 6 Jul 2009 at 4:20
Hello,
I've been trying to resolve the issue mentioned above, adding an image to a
dataGrid
cell and have been trying to incorporate the solution with no luck.
How do I need to modify the current library to achieve that functionality? Any
help
would be awesome.
--
Austin
Original comment by dagger...@gmail.com
on 15 Oct 2009 at 3:03
Did you ever had any luck with this issue?, I'm trying to add images to columns
in the grid...
Original comment by robg...@gmail.com
on 16 Jun 2010 at 5:46
You have to extend the PDF class and override the addMultiCell() method as
shown below.
1. First you have to store the images which you have to add to the grid in an
hashMap as (imageName, imageBytes);
2. Then pass the imageNames as data in a column to the grid.
3. Whenever the imageName comes then replace it with the imageBytes taken from
the hashMap which is stored above.
public class myPDF extends PDF
{
// The imageArray is used to store the imageName and the imageBytes. This
should be done during initialization.
public var imageArray:HashMap=new HashMap();
public function myPDF(orientation:String='Portrait', unit:String='Mm',
pageSize:Size=null, rotation:int=0)
{
super(orientation, unit, pageSize, rotation);
}
override public function addMultiCell ( width:Number, height:Number,
text:String, border:*=0, align:String='J', filled:int=0):void
{
charactersWidth = currentFont.charactersWidth;
if ( width == 0 )
width = currentPage.w - rightMargin - currentX;
// Whenever the text has any imageName , get the imageBytes from hashmap and add it to the grid. The image size should be modified according to the size of the grid row.
if (imageArray.containsKey(text))
{
var xPos:Number=(currentX + (width/2)-4);
addImage(imageArray.find(text), null, xPos, currentY-1.5, 4, 4, 0, 1, true, ImageFormat.PNG, 100);
}
else
{
var wmax:Number = (width-2*currentMargin)*I1000/fontSize;
var s:String = findAndReplace ("\r",'',text);
var nb:int = s.length;
if( nb > 0 && s.charAt(nb-1) == "\n" )
nb--;
var b:* = 0;
if( border )
{
if( border == 1 )
{
border = 'LTRB';
b = 'LRT';
b2 = 'LR';
}
else
{
b2 = '';
if (border.indexOf(Align.LEFT)!= -1)
b2+= Align.LEFT;
if (border.indexOf(Align.RIGHT)!= -1)
b2+= Align.RIGHT;
b = (border.indexOf(Align.TOP)!= -1) ?
b2+Align.TOP : b2;
}
}
var sep:int = -1;
var i:int = 0;
var j:int = 0;
var l:int = 0;
var ns:int = 0;
var nl:int = 1;
var c:String;
var cwAux:int = 0;
while (i<nb)
{
c = s.charAt(i);
if (c=="\n")
{
if (ws>0)
{
ws=0;
write('0 Tw');
}
addCell(width, height, s.substr(j,i-j), b, 2, align, filled);
i++;
sep = -1;
j = i;
l = 0;
ns = 0;
nl++;
if (border && nl==2)
b = b2;
continue;
}
if(c==' ')
{
sep = i;
var ls:int = l;
ns++;
}
cwAux = charactersWidth[c] as int;
if (cwAux == 0)
cwAux = FontMetrics.DEFAULT_WIDTH;
l += cwAux;
if (l>wmax)
{
if (sep==-1)
{
if (i==j)
i++;
if (ws>0)
{
ws=0;
write('0 Tw');
}
addCell(width,height,s.substr(j,i-j),b,2,align,filled);
}
else
{
if (align == Align.JUSTIFIED)
{
ws = (ns>1) ? ((wmax-ls)*.001)*fontSize/(ns-1) : 0;
write(sprintf('%.3f Tw',ws*k));
}
addCell(width,height,s.substr(j,sep-j),b,2,align,filled);
i=sep+1;
}
sep = -1;
j = i;
l = 0;
ns = 0;
nl++;
if ( border && nl == 2 )
b = b2;
}
else i++;
}
if ( ws>0 )
{
ws = 0;
write('0 Tw');
}
if ( border && border.indexOf ('B')!= -1 )
b += 'B';
addCell ( width, height, s.substr(j,i-j), b, 2, align, filled );
currentX = leftMargin;
}
}
Original comment by umarfaro...@gmail.com
on 23 Jun 2010 at 5:09
hi ,
Could be explain clearly , how i need to implement for creating the image in data grid ..
Thanks ...
Original comment by 3skm...@gmail.com
on 23 Jul 2010 at 2:35
[deleted comment]
Hi,
How to use UafPDF class to add image grid?
I work on flash CS4 (AS3)
my .fla generate PDF grid.
but I want to add image on my grid.
Thanks evrybody
this is my code :
import flash.utils.describeType;
import mx.collections.ArrayCollection;
import org.alivepdf.colors.RGBColor;
import org.alivepdf.data.Grid;
import org.alivepdf.data.GridColumn;
import org.alivepdf.display.Display;
import org.alivepdf.drawing.Joint;
import org.alivepdf.fonts.FontFamily;
import org.alivepdf.fonts.Style;
import org.alivepdf.layout.Align;
import org.alivepdf.layout.Layout;
import org.alivepdf.layout.Orientation;
import org.alivepdf.layout.Size;
import org.alivepdf.layout.Unit;
import org.alivepdf.pdf.PDF;
import org.alivepdf.saving.Method;
var _myPDF:PDF;
var gBytes:ByteArray = new ByteArray();
var _arrColl:Array = new Array();
var _statusColl:ArrayCollection = new ArrayCollection([
{Nom:"Mohammed",Age:"12"},
{Nom:"Tayeb",Age:"23"},
{Nom:"Sofiane",Age:"20"},
]);
///
init();
function init():void {
// create a columns Array
// it determines the order shown in the PDF
var gridColumnTip:GridColumn=new GridColumn("Nom","Nom",30,Align.LEFT,Align.LEFT);
_arrColl.push(gridColumnTip);
var gridColumnIcon:GridColumn=new GridColumn("Age","Age",40,Align.LEFT,Align.LEFT);
_arrColl.push(gridColumnIcon);
//
_myPDF=new PDF(Orientation.LANDSCAPE,Unit.MM,Size.A4);
// DisplayMode takes care of the general layout of the PDF in the PDF reader
_myPDF.setDisplayMode( Display.REAL, Layout.SINGLE_PAGE );
// create a Grid object as usual
var grid:Grid=new Grid(_statusColl.toArray(),600,600,new RGBColor(0x666666),new RGBColor(0xCCCCCC),new RGBColor(0),true,new RGBColor(0x0),1,Joint.MITER);
grid.columns=_arrColl;
//add the page , Set the text style and the font
_myPDF.addPage();
_myPDF.textStyle( new RGBColor(0), 1 );
_myPDF.setFont( FontFamily.ARIAL, Style.BOLD, 8 );
//Adds a dynamic table to the current page. This can be useful if you need to render
//large amount of data coming from an existing DataGrid or any data collection.
_myPDF.addGrid( grid, 5, 5 );
//_myPDF.save(Method.REMOTE,"http://www.okba.fr/create.php",Download.INLINE,"GeneratedPdf.pdf");
generer_btn.addEventListener(MouseEvent.CLICK, onSelectSave );
}
function onSelectSave( event:Event ):void {
_myPDF.save(Method.REMOTE, "http://www.okba.fr/create.php", "generated.pdf");
}
Original comment by mebarkia...@laposte.net
on 21 Oct 2010 at 11:15
Original issue reported on code.google.com by
umarfaro...@gmail.com
on 3 Jul 2009 at 7:04