Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm using FuscionChart FCExporter class to export charts to Pdf, PNG, etc. The problem I'm facing is I want a page after the chart to show a Grid View print out of the data.

There a few options for implementing this:

1. Create chart PDF then gridview PDF and merge the two documents
-Problem: I have no idea where to start with this. I'm unsure where in the class to call
the other document and merge.

2. Update routine to allow a GridView to be added after the chart element is added to the
docuement.
Problem: The closest I came to it working was getting a second page to print in the document but the Grid View would never show and I'm unsure why.


Code For adding elements to PDF:

private byte[] getPDFObjects(bool isCompressed)
{
MemoryStream PDFBytes = new MemoryStream();

//Store all PDF objects in this temporary string to be written to ByteArray
string strTmpObj = "";


//start xref array
ArrayList xRefList = new ArrayList();
xRefList.Add("xref\n0 ");
xRefList.Add("0000000000 65535 f \n"); //Address Refenrece to obj 0

//Build PDF objects sequentially
//version and header
strTmpObj = "%PDF-1.3\n%{FC}\n";
PDFBytes.Write(stringToBytes(strTmpObj), 0, strTmpObj.Length);

//OBJECT 1 : info (optional)
strTmpObj = "1 0 obj<<\n/Author (FusionCharts)\n/Title (FusionCharts)\n/Creator (FusionCharts)\n>>\nendobj\n";
xRefList.Add(calculateXPos((int)PDFBytes.Length)); //refenrece to obj 1
PDFBytes.Write(stringToBytes(strTmpObj), 0, strTmpObj.Length);

//OBJECT 2 : Starts with Pages Catalogue
strTmpObj = "2 0 obj\n<< /Type /Catalog /Pages 3 0 R >>\nendobj\n";
xRefList.Add(calculateXPos((int)PDFBytes.Length)); //refenrece to obj 2
PDFBytes.Write(stringToBytes(strTmpObj), 0, strTmpObj.Length);

//OBJECT 3 : Page Tree (reference to pages of the catalogue)
strTmpObj = "3 0 obj\n<< /Type /Pages /Kids [";
for (int i = 0; i < numPages; i++)
{
strTmpObj += (((i + 1) * 3) + 1) + " 0 R\n";
}
strTmpObj += "] /Count " + numPages + " >>\nendobj\n";

xRefList.Add(calculateXPos((int)PDFBytes.Length)); //refenrece to obj 3
PDFBytes.Write(stringToBytes(strTmpObj), 0, strTmpObj.Length);


//Each image page
for (int itr = 0; itr < numPages; itr++)
{
string iWidth = getMeta("width", itr);
string iHeight = getMeta("height", itr);
//OBJECT 4..7..10..n : Page config
strTmpObj = (((itr + 2) * 3) - 2) + " 0 obj\n<<\n/Type /Page /Parent 3 0 R \n/MediaBox [ 0 0 " + iWidth + " " + iHeight + " ]\n/Resources <<\n/ProcSet [ /PDF ]\n/XObject <</R" + (itr + 1) + " " + ((itr + 2) * 3) + " 0 R>>\n>>\n/Contents [ " + (((itr + 2) * 3) - 1) + " 0 R ]\n>>\nendobj\n";
xRefList.Add(calculateXPos((int)PDFBytes.Length)); //refenrece to obj 4,7,10,13,16...
PDFBytes.Write(stringToBytes(strTmpObj), 0, strTmpObj.Length);


//OBJECT 5...8...11...n : Page resource object (xobject resource that transforms the image)
xRefList.Add(calculateXPos((int)PDFBytes.Length)); //refenrece to obj 5,8,11,14,17...
string xObjR = getXObjResource(itr);
PDFBytes.Write(stringToBytes(xObjR), 0, xObjR.Length);

//OBJECT 6...9...12...n : Binary xobject of the page (image)
byte[] imgBA = addImageToPDF(itr, isCompressed);
xRefList.Add(calculateXPos((int)PDFBytes.Length));//refenrece to obj 6,9,12,15,18...
PDFBytes.Write(imgBA, 0, imgBA.Length);
}

//xrefs compilation
xRefList[0] += ((xRefList.Count - 1) + "\n");

//get trailer
string trailer = getTrailer((int)PDFBytes.Length, xRefList.Count - 1);

//write xref and trailer to PDF
string strXRefs = string.Join("", (string[])xRefList.ToArray(typeof(string)));
PDFBytes.Write(stringToBytes(strXRefs), 0, strXRefs.Length);
//
PDFBytes.Write(stringToBytes(trailer), 0, trailer.Length);

//write EOF
string strEOF = "%%EOF\n";
PDFBytes.Write(stringToBytes(strEOF), 0, strEOF.Length);

PDFBytes.Close();
return PDFBytes.ToArray();

}

Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900