Examples

Here are some examples apps built using sharpPDF-SL.

Text and Table Example

This example is lifted straight from the classic sharpPDF samples and adapted for sharpPDF-SL. It demonstrates some of the classic features available in sharpPDF.

pdfDocument myDoc = new pdfDocument("Sample Application", 
"Me", false);

pdfPage myFirstPage = myDoc.addPage();

myFirstPage.addText("sharpPDF-SL 1.0 - Table Sample", 
100, 660, predefinedFont.csHelveticaOblique, 
30, new pdfColor(predefinedColor.csCyan));

/*Table's creation*/
pdfTable myTable = new pdfTable();

//Set table's border
myTable.borderSize = 1;
myTable.borderColor = new pdfColor(predefinedColor.csDarkBlue);

/*Create table's header*/
myTable.tableHeader.addColumn(new pdfTableColumn("id", 
predefinedAlignment.csRight, 50));

myTable.tableHeader.addColumn(new pdfTableColumn("user", 
predefinedAlignment.csCenter, 150));

myTable.tableHeader.addColumn(new pdfTableColumn("tel", 
predefinedAlignment.csLeft, 80));

myTable.tableHeader.addColumn(new pdfTableColumn("email", 
predefinedAlignment.csLeft, 150));

/*Create table's rows*/
pdfTableRow myRow = myTable.createRow();

myRow[0].columnValue = "1";
myRow[1].columnValue = "Test 1";

myRow[2].columnValue = "898-0210989";
myRow[3].columnValue = "Andrew.red@sharppdf.net";

myTable.addRow(myRow);
myRow = myTable.createRow();

myRow[0].columnValue = "2";
myRow[1].columnValue = "Test 2";

myRow[2].columnValue = "298-55109";
myRow[3].columnValue = "Andrew.green@sharppdf.net";

myTable.addRow(myRow);
myRow = myTable.createRow();

myRow[0].columnValue = "3";
myRow[1].columnValue = "Test 3";

myRow[2].columnValue = "24-5510943";
myRow[3].columnValue = "Andrew.white@sharppdf.net";

myTable.addRow(myRow);

/*Set Header's Style*/
myTable.tableHeaderStyle = 
new pdfTableRowStyle(predefinedFont.csCourierBoldOblique, 
12, new pdfColor(predefinedColor.csBlack), 
new pdfColor(predefinedColor.csLightCyan));

/*Set Row's Style*/
myTable.rowStyle = 
new pdfTableRowStyle(predefinedFont.csCourier, 
8, new pdfColor(predefinedColor.csBlack), 
new pdfColor(predefinedColor.csWhite));

/*Set Alternate Row's Style*/
myTable.alternateRowStyle =
 new pdfTableRowStyle(predefinedFont.csCourier, 
8, new pdfColor(predefinedColor.csBlack), 
new pdfColor(predefinedColor.csLightYellow));

/*Set Cellpadding*/
myTable.cellpadding = 20;
/*Put the table on the page object*/
myFirstPage.addTable(myTable, 100, 600);

myTable = null;
return myDoc;			


Static Image Example

This example shows how to add a static image to a PDF using sharpPDF-SL. The image can be loaded from any number of static resources such as an embedded resource, URL, or from Isolated Storage.

Get Microsoft Silverlight
pdfDocument myDoc = new pdfDocument("Sample Application", 
"Me", false);

pdfPage myFirstPage = myDoc.addPage();
myFirstPage.addImage(
new System.Windows.Media.Imaging.WriteableBitmap(
(System.Windows.Media.Imaging.BitmapImage)SLLogo.Source), 5, 150);

return myDoc;


Dynamic Image Example

This example shows how to add a dynamic images to a PDF using sharpPDF-SL using a PNG or JPEG. JPEG images can be loaded as streams and passed directly to sharpPDF using the classic API.

Get Microsoft Silverlight
pdfDocument myDoc = new pdfDocument("Sample Application", "Me", false);

pdfPage myFirstPage = myDoc.addPage();
System.Windows.Media.Imaging.BitmapImage bi = 
new System.Windows.Media.Imaging.BitmapImage();

bi.SetSource(FS);
myFirstPage.addImage(
new System.Windows.Media.Imaging.WriteableBitmap(bi), 5, 100);

//if the image is a JPEG, add a second page, 
//passing the JPEG stream directly to the PDF.
if (filename.ToLower().Substring(filename.Length - 3, 3) == "jpg")
{
	pdfPage mySecondPage = myDoc.addPage();
	mySecondPage.addImage(FS, 5, 100);
}

return myDoc;


UIElement Example

This example shows how to use a Silverlight UIElement object for creation of a PDF. The UIElement and its child objects are converted to a bitmap and written to the PDF. The UIElement can also be passed with a Transform object. This can be used to rotate, crop, and resize UIElements and/or images inside the PDF.

Get Microsoft Silverlight
pdfDocument myDoc = new pdfDocument(
"Sample Application", "Me", false);

//Pass without Transform;
pdfPage myFirstPage = myDoc.addPage();
myFirstPage.addImage(
SLStackPanel, null, 5, 100);

//Pass with Transform
pdfPage mySecondPage = myDoc.addPage();
ScaleTransform Scaler = new ScaleTransform();

Scaler.ScaleX = .5;
mySecondPage.addImage(
SLStackPanel, Scaler, 5, 100);

return myDoc;