Tutorial 1:Hello World!
Tutorial 2:Change Page Size
Tutorial 3:Change Object's Color
Tutorial 4:Draw Elements On Different Pages
Tutorial 5:Basic Bookmarks
Tutorial 6:Advanced Bookmarks
Tutorial 7:Basic Tables


Tutorial 1:Hello World!

This is a basic sample that shows how to create a simple "Hello World" PDF.

pdfDocument myDoc = new pdfDocument("TUTORIAL","ME");
pdfPage myPage = myDoc.addPage();
myPage.addText("Hello World!",200,450,predefinedFont.csHelvetica,20);
myDoc.createPDF(@"c:\test.pdf");
myPage = null;
myDoc = null;


Tutorial 2:Change Page Size

This is a basic sample that shows how to create a page with non-standard size.

pdfDocument myDoc = new pdfDocument("TUTORIAL","ME");
/*At This point you put your own dimensions*/
pdfPage myPage = myDoc.addPage(100,100);
myPage.addText("Hello World!",200,450,predefinedFont.csHelvetica,10);
myDoc.createPDF(@"c:\test.pdf");
myPage = null;
myDoc = null;


Tutorial 3:Change Object's Color

This is a basic sample that shows how to change the color of a PDF objects.

pdfDocument myDoc = new pdfDocument("TUTORIAL","ME");
pdfPage myPage = myDoc.addPage(100,100);
/*Use the predefined Colors*/
myPage.addText("Hello World!",70,140,predefinedFont.csHelvetica,10,new pdfColor(predefinedColor.csCyan));
/*Use the RGB Colors*/
myPage.addText("Hello World!",70,100,predefinedFont.csHelvetica,10,new pdfColor(112,27,184));
/*Use the Hex Colors*/
myPage.addText("Hello World!",70,60,predefinedFont.csHelvetica,10,new pdfColor("B81C74"));
myDoc.createPDF(@"c:\test.pdf");
myPage = null;
myDoc = null;

OR

pdfDocument myDoc = new pdfDocument("TUTORIAL","ME");
pdfPage myPage = myDoc.addPage(100,100);
/*Use the directly predefined Colors[Deprecated]*/
myPage.addText("Hello World!",70,140,predefinedFont.csHelvetica,10,predefinedColor.csCyan);
myDoc.createPDF(@"c:\test.pdf");
myPage = null;
myDoc = null;


Tutorial 4:Draw Elements On Different Pages

This is a basic sample that shows how to draw different objects on different pages.

pdfDocument myDoc = new pdfDocument("TUTORIAL","ME");
/*Creation of the first page*/
pdfPage myFirstPage = myDoc.addPage();
/*Draw the line on the first page*/
myFirstPage.drawLine(100,100,200,200,predefinedLineStyle.csNormal,new pdfColor(predefinedColor.csBlue),10);
/*Creation of the second page*/
pdfPage mySecondPage = myDoc.addPage();
/*Draw the rectangle on the second page*/
mySecondPage.drawRectangle(100,100,300,200,new pdfColor(predefinedColor.csBlue),new pdfColor(predefinedColor.csYellow),1,predefinedLineStyle.csNormal);
/*Creation of the third page*/
pdfPage myThirdPage = myDoc.addPage();
/*Draw the circle on the third page-*/
myThirdPage.drawCircle(200,200,50,new pdfColor(predefinedColor.csBlue), new pdfColor(predefinedColor.csYellow),predefinedLineStyle.csNormal,1);
myDoc.createPDF(@"c:\test.pdf");
myFirstPage = null;
mySecondPage = null;
myThirdPage = null;
myDoc = null;


Tutorial 5:Basic Bookmarks

This is a basic sample that shows how to use sample bookmarks. Bookmarks are links on the left side of the page that have a destination. When you create the bookmark you choose the page (pdfPage object) and a destination type. You can obtain destination type with a pdfDetinationFactory that returns different pdfDesyination objects that implement a generic IPdfDestination Interface.

/*If the last parameter is true, the links are visible when you open the document. Otherwise you have to open the bookmarks manually*/
pdfDocument myDoc = new pdfDocument("Sample Application","Me", true);
pdfPage myPage = myDoc.addPage();
myPage.addText("sharpPDF 1.2.2",100,660,predefinedFont.csHelveticaOblique,30,new pdfColor(predefinedColor.csCyan));
/*Bookmark on the first page with destinationType = Fit (See object reference and pdf specification)*/
myDoc.addBookmark(new pdfBookmarkNode("FIRST PAGE", myPage, false, pdfDestinationFactory.createPdfDestinationFit()));
myDoc.createPDF(txtOutput.Text + @"\" + txtDoc.Text + ".pdf");


Tutorial 6:Advanced Bookmarks

This is an advanced sample that shows how to use related bookmarks. You can create a structure like a tree and you can link all pages in your document.

pdfDocument myDoc = new pdfDocument("Sample Application","Me", true);
pdfPage myFirstPage = myDoc.addPage();
myFirstPage.addText("sharpPDF 1.2.2",100,660,predefinedFont.csHelveticaOblique,30,new pdfColor(predefinedColor.csCyan));
/*First Bookmark*/
pdfBookmarkNode firstBook = new pdfBookmarkNode("FIRST PAGE", myFirstPage, false, pdfDestinationFactory.createPdfDestinationFit());
pdfPage mySecondPage = myDoc.addPage();
/*Second Bookmark*/
pdfBookmarkNode secondBook = new pdfBookmarkNode("SECOND PAGE", mySecondPage, false, pdfDestinationFactory.createPdfDestinationFit());
firstBook.addChildNode(secondBook);
myDoc.addBookmark(firstBook);
myDoc.createPDF(txtOutput.Text + @"\" + txtDoc.Text + ".pdf");


Tutorial 7:Basic Tables

This is a basic sample that shows how to create tables and to congifure them.

pdfDocument myDoc = new pdfDocument("Sample Application","Me", false);
pdfPage myFirstPage = myDoc.addPage();
myFirstPage.addText("sharpPDF 1.3 - 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 = "Andrew Red";
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 = "Andrew Green";
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 = "Andrew White";
myRow[2].columnValue = "24-5510943";
myRow[3].columnValue = "Andrew.white@sharppdf.net";
/*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;
myDoc.createPDF(txtOutput.Text + @"\" + txtDoc.Text + ".pdf");