//////////////////////////////////////////////////////////////////// // Draw frame around example area //////////////////////////////////////////////////////////////////// private void DrawFrameAndBackgroundWaterMark() { // save graphics state Contents.SaveGraphicsState(); // Draw frame around the page // Set line width to 0.02" Contents.SetLineWidth(0.02); // set frame color dark blue Contents.SetColorStroking(Color.DarkBlue); // use water mark tiling pattern to fill the frame Contents.SetPatternNonStroking(WaterMark); // rectangle position: x=1.0", y=1.0", width=6.5", height=9.0" Contents.DrawRectangle(1.0, 1.0, 6.5, 9.0, PaintOp.CloseFillStroke); // restore graphics sate Contents.RestoreGraphicsState(); // draw article name under the frame // Note: the \u00a4 is character 164 that was substituted during Font resource definition // this character is a solid circle it is normally Unicode 9679 or \u25cf in the Arial family Contents.DrawText(ArialNormal, 9.0, 1.1, 0.85, "PdfFileWriter \u25cf PDF File Writer C# Class Library \u25cf Author: Uzi Granot"); // draw web link to the article Contents.DrawWebLink(Page, ArialNormal, 9.0, 7.4, 0.85, TextJustify.Right, DrawStyle.Underline, Color.Blue, "Click to view article", "http://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library-Version"); return; }
public void OnePage ( int Cols, int Rows ) { // Add new page PdfPage Page = new PdfPage(Document); // Add contents to page PdfContents Contents = new PdfContents(Page); double Left = CenterX - 0.5 * Cols; double Right = CenterX + 0.5 * Cols; double Top = CenterY + 0.5 * Rows; double Bottom = CenterY - 0.5 * Rows; Contents.DrawText(ArialFont, FontSize, CenterX, Top + Descent + 0.2, TextJustify.Center, Cols == Rows ? "Square" : "Rectangle"); // save state Contents.SaveGraphicsState(); Contents.SetLineWidth(0.1); Contents.SetColorStroking(Color.Black); Contents.SetColorNonStroking(Color.LightBlue); Contents.DrawRectangle(Left, Bottom, Cols, Rows, PaintOp.CloseFillStroke); Contents.RestoreGraphicsState(); Contents.SaveGraphicsState(); Contents.SetLineWidth(0.04); for (int Row = 0; Row <= Rows; Row++) { Contents.DrawLine(Left - 0.25, Bottom + Row, Right, Bottom + Row); Contents.DrawText(ArialFont, FontSize, Left - 0.35, Bottom + Row - Descent, TextJustify.Right, Row.ToString()); } for (int Col = 0; Col <= Cols; Col++) { Contents.DrawLine(Left + Col, Bottom - 0.25, Left + Col, Top); Contents.DrawText(ArialFont, FontSize, Left + Col, Bottom - 0.25 - FontHeight, TextJustify.Center, Col.ToString()); } for (int Index = 0; Index < Rows * Cols; Index++) { int Row = Index / Cols; int Col = Index % Cols; Contents.DrawText(ArialFont, FontSize, Left + 0.5 + Col, Top - 0.5 - Descent - Row, TextJustify.Center, (Index + 1).ToString()); } Contents.DrawText(ArialFont, FontSize, CenterX, Bottom - 1.0, TextJustify.Center, "Area"); Contents.DrawText(ArialFont, FontSize, CenterX, Bottom - 1.4, TextJustify.Center, string.Format("{0} X {1} = {2}", Rows, Cols, Rows * Cols)); // restore graphics state Contents.RestoreGraphicsState(); return; }
/* * private Color GetColorfromRGBString(string colorString) * { * var r = 0; * var g = 0; * var b = 0; * try * { * var cleanedString = colorString.Replace("RGB(", ""); * cleanedString = cleanedString.Replace(")", ""); * var splitStringArray = cleanedString.Split(','); * r = int.Parse(splitStringArray[0]); * g = int.Parse(splitStringArray[1]); * b = int.Parse(splitStringArray[2]); * } * catch (Exception e) * { * Console.WriteLine("{0}", e.Message); * } * * return Color.FromArgb(r, g, b); * } * */ private void DrawFrameAndBackgroundWaterMark() { // save graphics state Contents.SaveGraphicsState(); Contents.SetColorNonStroking(Color.FromArgb(pk.BackgroundColor.Red, pk.BackgroundColor.Green, pk.BackgroundColor.Blue)); Contents.DrawRectangle(0.0, 0.0, 8.5, 11, PaintOp.Fill); // restore graphics sate Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw image and clip it //////////////////////////////////////////////////////////////////// private static void DrawTitle() { // define local image resources as 200ppi and 100% quality PdfImageControl ImageControl = new PdfImageControl(); ImageControl.Resolution = 200; ImageControl.ImageQuality = 100; // Get image from embedded local resource Image BocTitle = Properties.Resources.BocTitleBitmap; PdfImage titleImage = new PdfImage(document, BocTitle, ImageControl); // save graphics state Contents.SaveGraphicsState(); // set coordinate Contents.Translate(1.3, 26.8); // set image size PdfRectangle size = titleImage.ImageSizePosition(18.39, 1.85, ContentAlignment.MiddleCenter); // clipping path Contents.DrawRectangle(size.Left, size.Bottom, size.Width, size.Height, PaintOp.ClipPathEor); // draw image Contents.DrawImage(titleImage, size.Left, size.Bottom, size.Width, size.Height); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw image of a flower and clip it //////////////////////////////////////////////////////////////////// private void DrawFlower ( PdfDocument Document, PdfContents Contents ) { // define local image resources PdfImage Image1 = new PdfImage(Document, "flower.jpg"); // image size will be limited to 1.4" by 1.4" SizeD ImageSize = Image1.ImageSize(1.4, 1.4); // save graphics state Contents.SaveGraphicsState(); // translate coordinate origin to the center of the picture Contents.Translate(3.36, 5.7); // clipping path Contents.DrawOval(-ImageSize.Width / 2, -ImageSize.Height / 2, ImageSize.Width, ImageSize.Height, PaintOp.ClipPathEor); // draw image Contents.DrawImage(Image1, -ImageSize.Width / 2, -ImageSize.Height / 2, ImageSize.Width, ImageSize.Height); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw rectangle with rounded corners and filled with brick pattern //////////////////////////////////////////////////////////////////// private void DrawBrickPattern ( PdfDocument Document, PdfContents Contents ) { // Define brick tilling pattern resource // Arguments: PdfDocument class, Scale factor (0.25), Stroking color (lines between bricks), Nonstroking color (brick) // Return value: tilling pattern resource PdfTilingPattern BrickPattern = PdfTilingPattern.SetBrickPattern(Document, 0.25, Color.LightYellow, Color.SandyBrown); // save graphics state Contents.SaveGraphicsState(); // set outline width 0.04" Contents.SetLineWidth(0.04); // set outline color to purple Contents.SetColorStroking(Color.Purple); // set fill pattern to brick Contents.SetPatternNonStroking(BrickPattern); // draw rounded rectangle filled with brick pattern Contents.DrawRoundedRectangle(1.13, 5.0, 1.4, 1.4, 0.2, PaintOp.CloseFillStroke); // restore graphics sate Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw heading //////////////////////////////////////////////////////////////////// private void DrawTwoLinesOfHeading ( PdfContents Contents ) { // page heading // Arguments: Font: ArialBold, size: 36 points, Position: X = 4.25", Y = 9.5" // Text Justify: Center (text center will be at X position) // Stoking color: R=128, G=0, B=255 (text outline) // Nonstroking color: R=255, G=0, B=128 (text body) Contents.DrawText(Comic, 40.0, 4.25, 9.25, TextJustify.Center, 0.02, Color.FromArgb(128, 0, 255), Color.FromArgb(255, 0, 128), "PDF FILE WRITER"); // save graphics state Contents.SaveGraphicsState(); // change nonstroking (fill) color to purple Contents.SetColorNonStroking(Color.Purple); // Draw second line of heading text // arguments: Handwriting font, Font size 30 point, Position X=4.25", Y=9.0" // Text Justify: Center (text center will be at X position) Contents.DrawText(Comic, 30.0, 4.25, 8.75, TextJustify.Center, "Example"); // Contents.TranslateScaleRotate(4.25, 8.75, 1.5, Math.PI / 6); // Contents.DrawText(Comic, 30.0, 0, 0, TextJustify.Center, "Example"); // restore graphics sate (non stroking color will be restored to default) Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw frame around example area //////////////////////////////////////////////////////////////////// private void DrawFrameAndBackgroundWaterMark ( PdfContents Contents ) { // save graphics state Contents.SaveGraphicsState(); // Draw frame around the page // Set line width to 0.02" Contents.SetLineWidth(0.02); // set frame color dark blue Contents.SetColorStroking(Color.DarkBlue); // use water mark tiling pattern to fill the frame Contents.SetPatternNonStroking(WaterMark); // rectangle position: x=1.0", y=1.0", width=6.5", height=9.0" Contents.DrawRectangle(1.0, 1.0, 6.5, 9.0, PaintOp.CloseFillStroke); // restore graphics sate Contents.RestoreGraphicsState(); // draw article name under the frame // Note: the \u00a4 is character 164 that was substituted during Font resource definition // this character is a solid circle it is normally unicode 9679 or \u25cf in the Arial family Contents.DrawText(ArialNormal, 9.0, 1.1, 0.85, "PdfFileWriter \u00a4 PDF File Writer C# Class Library \u00a4 Author: Uzi Granot"); return; }
//////////////////////////////////////////////////////////////////// // Add page to document and draw page number //////////////////////////////////////////////////////////////////// public PdfContents AddPageToDocument ( Int32 PageNo ) { // add new page with two contents objects Page = new PdfPage(Document); Page.AddContents(BaseContents); PdfContents Contents = new PdfContents(Page); // draw page number right justified Contents.SaveGraphicsState(); //Contents.DrawText(ArialNormal, 10, PageWidth - Margin, PageHeight - 0.75 - ArialNormal.CapHeight(10), TextJustify.Right, String.Format("Page {0}", PageNo)); Contents.RestoreGraphicsState(); return(Contents); }
//////////////////////////////////////////////////////////////////// // Draw heart //////////////////////////////////////////////////////////////////// private void DrawHeart ( PdfContents Contents ) { // save graphics state Contents.SaveGraphicsState(); // draw heart // The first argument are the coordinates of the centerline of the heart shape. // The DrawHeart is a special case of DrawDoubleBezierPath method. Contents.SetColorNonStroking(Color.HotPink); Contents.DrawHeart(new LineD(new PointD(5.14, 5.1), new PointD(5.14, 6.0)), PaintOp.CloseFillStroke); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw Happy Face //////////////////////////////////////////////////////////////////// private void DrawHappyFace ( PdfContents Contents ) { // save graphics state Contents.SaveGraphicsState(); // translate coordinate origin to the center of the happy face Contents.Translate(4.25, 7.5); // change nonstroking (fill) color to yellow Contents.SetColorNonStroking(Color.Yellow); // draw happy face yellow oval Contents.DrawOval(-1.5, -1.0, 3.0, 2.0, PaintOp.Fill); // set line width to 0.2" this is the black circle around the eye Contents.SetLineWidth(0.2); // eye color is white with black outline circle Contents.SetColorNonStroking(Color.White); Contents.SetColorStroking(Color.Black); // draw eyes Contents.DrawOval(-0.75, 0.0, 0.5, 0.5, PaintOp.CloseFillStroke); Contents.DrawOval(0.25, 0.0, 0.5, 0.5, PaintOp.CloseFillStroke); // mouth color is black Contents.SetColorNonStroking(Color.Black); // draw mouth by creating a path made of one line and one Bezier curve Contents.MoveTo(-0.6, -0.4); Contents.LineTo(0.6, -0.4); Contents.DrawBezier(0.0, -0.8, 0, -0.8, -0.6, -0.4); // fill the path with black color Contents.SetPaintOp(PaintOp.Fill); // restore graphics sate Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw six sided regular polygon //////////////////////////////////////////////////////////////////// private void DrawStar ( PdfContents Contents ) { // save graphics state Contents.SaveGraphicsState(); // Regular polygon // Coordinate of center point is PosX=6.67" PosY=5.7" // Radius of end points is 0.7" // First drawing point is at 30 degrees (in radians PI / 6). // Number of sides is 6 Contents.SetColorNonStroking(Color.Turquoise); Contents.DrawStar(6.67, 5.7, 0.7, Math.PI / 6, 6, PaintOp.CloseFillStroke); // restore graphics state Contents.RestoreGraphicsState(); return; }
private void button2_Click(object sender, EventArgs e) { if (folderDiag.SelectedPath != null && folderDiag.SelectedPath != "") { textBox1.Text = "Adding pages"; Image[] pages = System.IO.Directory.GetFiles(folderDiag.SelectedPath) .Select(file => System.Drawing.Image.FromFile(file)) .ToArray(); string title = titleBox.Text == "Title" ? "untitled" : titleBox.Text; PdfDocument book = new PdfDocument(title + ".pdf"); PdfPage page; PdfContents contents; PdfImage pic; foreach (Image i in pages) { double height = i.Height; double width = i.Width; page = new PdfPage(book, width, height); contents = new PdfContents(page); contents.SaveGraphicsState(); pic = new PdfImage(book, i); contents.DrawImage(pic, 0, 0, width, height); contents.RestoreGraphicsState(); contents.CommitToPdfFile(true); } book.CreateFile(); textBox1.Text = "Book created"; pages = null; book = null; page = null; contents = null; pic = null; } else { textBox1.Text = "No directory selected"; } }
void DrawSummary(PdfContents content, Offer offer) { content.SaveGraphicsState(); // Textbox für Nettopreishinweis, Zahlungs- und Lieferbedingungen var livingInABox = new TextBox(125); var nl = Environment.NewLine; string nettopreise = "Alle angegebenen Preise in Euro, zuzüglich der gesetzlich gültigen Mehrwertsteuer."; livingInABox.AddText(fontDefault, 8.0, nettopreise + nl); livingInABox.AddText(fontDefault, 8.0, this.myOffer.Zahlungsbedingungen + nl); livingInABox.AddText(fontDefault, 8.0, this.myOffer.Customer.FocText); double yPosition = lastPosition - 4; content.DrawText(10.5, ref yPosition, 0.0, 0, 0.0, 1.2, TextBoxJustify.Left, livingInABox); string betrag; // Nettosumme content.DrawText(fontDefault, 10D, xSummary, lastPosition - 5, DrawStyle.Normal, "Summe (netto):"); betrag = string.Format("{0:N2}", offer.NetAmount); content.DrawText(fontDefault, 10D, xRightMargin - 1, lastPosition - 5, TextJustify.Right, DrawStyle.Normal, System.Drawing.Color.Black, betrag); // USt. content.DrawText(fontDefault, 10D, xSummary, lastPosition - 9.2, DrawStyle.Normal, "USt. Betrag: (19%):"); betrag = string.Format("{0:N2}", offer.TaxAmount); content.DrawText(fontDefault, 10D, xRightMargin - 1, lastPosition - 9.2, TextJustify.Right, DrawStyle.Normal, System.Drawing.Color.Black, betrag); // Angebotsbetrag content.DrawText(fontDefault, 10D, xSummary, lastPosition - 13.4, DrawStyle.Normal, "Angebotsbetrag:"); betrag = string.Format("{0:N2}", offer.OfferTotal); content.DrawText(fontDefault, 10D, xRightMargin - 1, lastPosition - 13.4, TextJustify.Right, DrawStyle.Underline, System.Drawing.Color.Black, betrag); content.DrawText(fontDefault, 8D, xSummary, lastPosition - 17.6, TextJustify.Left, DrawStyle.Normal, System.Drawing.Color.DarkGray, "(Alle ausgewiesenen Beträge in Euro)"); content.RestoreGraphicsState(); }
public void Test ( Boolean Debug, String InputFileName ) { // fish artwork from your favorite wpf or svg editing software (AI, Blend, Expression Design) // for hand writing minipath strings please see SVG or WPF reference on it (for example, https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths) string FishPathText = "M 73.302,96.9831C 88.1275,96.9831 100.146,109.002 100.146,123.827C 100.146,138.653 88.1275,150.671 73.302,150.671" + "C 58.4764,150.671 46.458,138.653 46.458,123.827C 46.458,109.002 58.4764,96.9831 73.302,96.9831 Z M 80.3771,118.625" + "C 87.8473,118.625 93.9031,124.681 93.9031,132.151C 93.9031,139.621 87.8473,145.677 80.3771,145.677C 72.9068,145.677 66.851,139.621 66.851,132.151" + "C 66.851,124.681 72.9069,118.625 80.3771,118.625 Z M 124.936,229.489L 124.936,230.05C 142.757,230.05 157.205,187.542 157.205,135.105" + "C 157.205,82.6682 142.757,40.1597 124.936,40.1597L 124.936,40.7208C 140.016,40.7208 152.241,82.9781 152.241,135.105" + "C 152.241,187.232 140.016,229.489 124.936,229.489 Z M 155.904,33.5723C 168.593,40.8964 181.282,48.2205 184.749,59.0803" + "C 188.216,69.9401 182.461,84.3356 176.705,98.7312C 187.217,82.7698 197.73,66.8085 194.263,55.9487C 190.796,45.0889 173.35,39.3306 155.904,33.5723 Z " + "M 221.06,47.217C 231.336,54.9565 241.612,62.6958 243.473,72.5309C 245.334,82.366 238.779,94.2968 232.224,106.228" + "C 243.092,93.4406 253.96,80.6536 252.099,70.8185C 250.238,60.9834 235.649,54.1002 221.06,47.217 Z M 190.088,103.489" + "C 200.631,113.663 211.175,123.836 211.914,135.212C 212.654,146.588 203.591,159.166 194.527,171.744C 208.585,158.796 222.643,145.848 221.903,134.472" + "C 221.163,123.096 205.625,113.293 190.088,103.489 Z M 227.222,175.988C 233.667,185.231 240.112,194.474 238.981,203.168" + "C 237.849,211.862 229.142,220.007 220.434,228.153C 232.965,220.47 245.497,212.787 246.628,204.093C 247.759,195.399 237.49,185.693 227.222,175.988 Z " + "M 176.183,170.829C 182.085,184.24 187.987,197.65 184.36,208.457C 180.734,219.265 167.58,227.47 154.426,235.675C 172.342,229.02 190.258,222.366 193.884,211.558" + "C 197.511,200.75 186.847,185.79 176.183,170.829 Z M 253.24,114.388C 261.541,123.744 269.842,133.1 269.72,142.831" + "C 269.598,152.561 261.052,162.667 252.506,172.773C 265.327,162.683 278.148,152.592 278.27,142.861C 278.392,133.13 265.816,123.759 253.24,114.388 Z " + "M 19.3722,114.348C 33.8527,95.7363 61.0659,59.7511 97.8151,40.6822C 117.532,30.4513 139.994,25.0899 164.816,24.6372" + "C 165.876,24.1644 167.083,23.6525 168.454,23.0983C 181.841,17.6879 210.836,8.25439 232.2,4.09256C 253.564,-0.0693054 267.298,1.04053 273.749,4.99429" + "C 280.2,8.94803 279.368,15.7458 278.743,24.4856C 278.119,33.2255 277.703,43.9076 276.94,49.1099C 276.927,49.2001 276.913,49.2887 276.9,49.3756" + "C 318.05,66.1908 360.168,89.8268 395.044,112.964C 408.876,122.14 421.569,131.238 433.26,140.058C 439.423,134.13 445.322,128.267 450.904,122.587" + "C 478.22,94.7909 497.963,71.3744 513.5,56.0696C 529.037,40.7648 540.368,33.5717 541.331,39.3597C 542.295,45.1478 532.891,63.9171 528.998,87.7075" + "C 525.105,111.498 526.722,140.309 533.661,167.068C 540.599,193.827 552.858,218.532 549.803,224.507C 546.748,230.482 528.378,217.727 502.239,196.166" + "C 483.768,180.932 461.418,161.301 433.26,140.058C 409.264,163.142 381.252,187.219 352.261,205.363C 315.824,228.167 277.841,241.6 230.108,245.486" + "C 182.376,249.372 124.895,243.713 84.9205,225.782C 44.946,207.851 22.4781,177.648 11.4752,160.545C 0.472214,143.443 0.934143,139.44 2.03903,136.819" + "C 3.14392,134.199 4.89172,132.96 19.3722,114.348 Z "; // water artwork string WavePathOriginal = "M 0.000854492,723.999L 1106,723.999L 1106,616.629C 1025.42,656.405 941.978,687.324 846.084,679.721C 721.562,669.847 576.045,595.015 425.822,588.779" + "C 286.673,583.003 143.486,636.082 0.000854492,693.5L 0.000854492,723.999 Z M 423.35,26.0787C 573.573,32.3146 719.09,107.146 843.612,117.02C 940.487,124.701 1024.65,93.0672 1106,52.7042" + "L 1106,-1.90735e-005L 0.000854492,-1.90735e-005L 0.000854492,129.811C 142.658,72.7739 285,20.3355 423.35,26.0787 Z M 6.10352e-005,545.976C 143.485,488.558 286.672,435.478 425.822,441.255" + "C 576.045,447.491 721.562,522.322 846.084,532.196C 941.978,539.8 1025.42,508.88 1106,469.104L 1106,200.228C 1024.65,240.592 940.486,272.226 843.611,264.544" + "C 719.089,254.671 573.572,179.839 423.349,173.603C 284.999,167.86 142.657,220.298 6.10352e-005,277.335L 6.10352e-005,545.976 Z"; /* * string ItalianFish = "M73,302;96,9831C88,1275;96,9831 100,146;109,002 100,146;123,827 100,146;138,653 88,1275;150,671 73,302;150,671 58,4764;150,671 46,458;138,653 46,458;123,827 46,458;109,002 58,4764;96,9831 73,302;96,9831z M80,3771;118,625C87,8473;118,625 93,9031;124,681 93,9031;132,151 93,9031;139,621 87,8473;145,677 80,3771;145,677 72,9068;145,677 66,851;139,621 66,851;132,151 66,851;124,681 72,9069;118,625 80,3771;118,625z M124,936;229,489L124,936;230,05C142,757;230,05 157,205;187,542 157,205;135,105 157,205;82,6682 142,757;40,1597 124,936;40,1597L124,936;40,7208C140,016;40,7208 152,241;82,9781 152,241;135,105 152,241;187,232 140,016;229,489 124,936;229,489z M155,904;33,5723C168,593;40,8964 181,282;48,2205 184,749;59,0803 188,216;69,9401 182,461;84,3356 176,705;98,7312 187,217;82,7698 197,73;66,8085 194,263;55,9487 190,796;45,0889 173,35;39,3306 155,904;33,5723z M221,06;47,217C231,336;54,9565 241,612;62,6958 243,473;72,5309 245,334;82,366 238,779;94,2968 232,224;106,228 243,092;93,4406 253,96;80,6536 252,099;70,8185 250,238;60,9834 235,649;54,1002 221,06;47,217z M190,088;103,489C200,631;113,663 211,175;123,836 211,914;135,212 212,654;146,588 203,591;159,166 194,527;171,744 208,585;158,796 222,643;145,848 221,903;134,472 221,163;123,096 205,625;113,293 190,088;103,489z M227,222;175,988C233,667;185,231 240,112;194,474 238,981;203,168 237,849;211,862 229,142;220,007 220,434;228,153 232,965;220,47 245,497;212,787 246,628;204,093 247,759;195,399 237,49;185,693 227,222;175,988z M176,183;170,829C182,085;184,24 187,987;197,65 184,36;208,457 180,734;219,265 167,58;227,47 154,426;235,675 172,342;229,02 190,258;222,366 193,884;211,558 197,511;200,75 186,847;185,79 176,183;170,829z M253,24;114,388C261,541;123,744 269,842;133,1 269,72;142,831 269,598;152,561 261,052;162,667 252,506;172,773 265,327;162,683 278,148;152,592 278,27;142,861 278,392;133,13 265,816;123,759 253,24;114,388z M19,3722;114,348C33,8527;95,7363 61,0659;59,7511 97,8151;40,6822 117,532;30,4513 139,994;25,0899 164,816;24,6372 165,876;24,1644 167,083;23,6525 168,454;23,0983 181,841;17,6879 210,836;8,25439 232,2;4,09256 253,564;-0,0693054 267,298;1,04053 273,749;4,99429 280,2;8,94803 279,368;15,7458 278,743;24,4856 278,119;33,2255 277,703;43,9076 276,94;49,1099 276,927;49,2001 276,913;49,2887 276,9;49,3756 318,05;66,1908 360,168;89,8268 395,044;112,964 408,876;122,14 421,569;131,238 433,26;140,058 439,423;134,13 445,322;128,267 450,904;122,587 478,22;94,7909 497,963;71,3744 513,5;56,0696 529,037;40,7648 540,368;33,5717 541,331;39,3597 542,295;45,1478 532,891;63,9171 528,998;87,7075 525,105;111,498 526,722;140,309 533,661;167,068 540,599;193,827 552,858;218,532 549,803;224,507 546,748;230,482 528,378;217,727 502,239;196,166 483,768;180,932 461,418;161,301 433,26;140,058 409,264;163,142 381,252;187,219 352,261;205,363 315,824;228,167 277,841;241,6 230,108;245,486 182,376;249,372 124,895;243,713 84,9205;225,782 44,946;207,851 22,4781;177,648 " + * "11,4752;160,545 0,472214;143,443 0,934143;139,44 2,03903;136,819 3,14392;134,199 4,89172;132,96 19,3722;114,348z"; * * string ItalianWave = "M0,000854492;723,999L1106;723,999 1106;616,629C1025,42;656,405 941,978;687,324 846,084;679,721 721,562;669,847 576,045;595,015 425,822;588,779 286,673;583,003 143,486;636,082 0,000854492;693,5L0,000854492;723,999z M423,35;26,0787C573,573;32,3146 719,09;107,146 843,612;117,02 940,487;124,701 1024,65;93,0672 1106;52,7042L1106;-1,90735E-05 0,000854492;-1,90735E-05 0,000854492;129,811C142,658;72,7739;285;20,3355;423,35;26,0787z M6,10352E-05;545,976C143,485;488,558 286,672;435,478 425,822;441,255 576,045;447,491 721,562;522,322 846,084;532,196 941,978;539,8 1025,42;508,88 1106;469,104L1106;200,228C1024,65;240,592 940,486;272,226 843,611;264,544 719,089;254,671 573,572;179,839 423,349;173,603 284,999;167,86 142,657;220,298 6,10352E-05;277,335L6,10352E-05;545,976z"; * // water artwork * string WavePathText = "M 0,724L 1106,724L 1106,617C 1025,656 942,687 846,680C 722,670 576,595 426,589C 287,583 143,636 0,694L 0,724 Z " + * "M 423,26C 574,32 719,107 844,117C 940,125 1025,93 1106,53L 1106,0L 0,0L 0,130C 143,73 285,20 423,26 Z " + * "M 0,546C 143,489 287,435 426,441C 576,447 722,522 846,532C 942,540 1025,509 1106,469L 1106,200C 1025,241 940,272 844,265" + * "C 719,255 574,180 423,174C 285,168 143,220 0,277L 0,546 Z"; * string MyWavePathText = "M 0 0 L 1000 0 L 1000 100 C 550 550 550 -300 0 250 Z" + * "M 0 550 C 550 0 550 850 1000 400 L 1000 850 C 550 1300 550 450 0 1000 Z" + * "M 0 1400 L 0 1300 C 550 750 550 1600 1000 1150 L 1000 1400 Z"; */ // create document using (PdfDocument Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, InputFileName)) { // define font PdfFont ArialNormal = PdfFont.CreatePdfFont(Document, "Arial", FontStyle.Regular); // Add new page PdfPage Page = new PdfPage(Document); // Add contents to page PdfContents Contents = new PdfContents(Page); // translate origin Contents.SaveGraphicsState(); // test draw // string TestDraw1 = "M 0 0 L 1000 0"; string TestDraw1 = "M 0 0 L 100 200 L 200 0 Z M 0 200 L 100 0 L 200 200 Z"; // string TestDraw1 = "M 0 0 A 400 400 0 0 0 100 200 A 400 400 0 0 0 200 0 A 400 400 0 0 0 0 0 Z" + // "M 0 250 A 400 400 0 0 1 100 -50 A 400 400 0 0 1 250 250 A 400 400 0 0 1 0 250 Z"; //string TestDraw1 = "M 0 0 L 100 200 L 200 0"; DrawWPFPath TestPath1 = new DrawWPFPath(TestDraw1, YAxisDirection.Up); TestPath1.SetBrush(Color.DarkMagenta); SysMedia.Pen Pen = new SysMedia.Pen(new SysMedia.SolidColorBrush(SysMedia.Colors.DarkBlue), 2); Pen.StartLineCap = SysMedia.PenLineCap.Flat; Pen.LineJoin = SysMedia.PenLineJoin.Bevel; Pen.DashStyle = new SysMedia.DashStyle(new double[] { 1.0 }, 0.0); TestPath1.SetPen(Pen); Contents.DrawWPFPath(TestPath1, 1.0, 4.0, 5.0, 3.0); string TestDraw2 = "M 0 0 L 200 200 A 200 200 0 1 0 0 0 Z"; DrawWPFPath TestPath2 = new DrawWPFPath(TestDraw2, YAxisDirection.Up); // string TestDraw = "M 0 200 L 200 0 A 200 200 0 1 1 0 200"; // DrawWPFPath TestPath = new DrawWPFPath(TestDraw, YAxisDirection.Down); TestPath2.SetPenWidth(0.05); TestPath2.SetPen(Color.Chocolate); Contents.DrawWPFPath(TestPath2, 4.25, 4.0, 3.0, 3.0, ContentAlignment.BottomLeft); // load fish path DrawWPFPath FishPath = new DrawWPFPath(FishPathText, YAxisDirection.Down); // set pen for both fish FishPath.SetPen(Color.FromArgb(255, 255, 80, 0)); FishPath.SetPenWidth(0.02); // PdfTilingPattern BrickPattern = PdfTilingPattern.SetBrickPattern(Document, 0.25, Color.LightYellow, Color.SandyBrown); // FishPath.SetBrush(BrickPattern); // draw small fish FishPath.SetBrush(Color.FromArgb(255, 67, 211, 216)); Contents.DrawWPFPath(FishPath, 2.5, 5.75, 4.5, 3.0, ContentAlignment.TopRight); // big fish drawing area Color[] BigFishBrushColor = new Color[] { Color.FromArgb(0xff, 0xff, 0x50, 0), Color.FromArgb(0xff, 0x27, 0xda, 0xff) }; PdfRadialShading RadialShading = new PdfRadialShading(Document, new PdfShadingFunction(Document, BigFishBrushColor)); RadialShading.SetGradientDirection(0.15, 0.5, 0.0, 0.25, 0.5, 1.3, MappingMode.Relative); FishPath.SetBrush(RadialShading, 1.0); Contents.DrawWPFPath(FishPath, 1.5, 2.0, 5.5, 5.5, ContentAlignment.BottomLeft); // load wave DrawWPFPath WavePath = new DrawWPFPath(WavePathOriginal, YAxisDirection.Up); // draw wave Color[] WaveBrushColor = new Color[] { Color.Cyan, Color.DarkBlue }; PdfAxialShading AxialShading = new PdfAxialShading(Document, new PdfShadingFunction(Document, WaveBrushColor)); AxialShading.SetAxisDirection(0.0, 1.0, 1.0, 0.0, MappingMode.Relative); WavePath.SetBrush(AxialShading, 0.55); Contents.DrawWPFPath(WavePath, 1.0, 1.0, 6.5, 9.0); // restore graphics state Contents.RestoreGraphicsState(); // create pdf file Document.CreateFile(); // start default PDF reader and display the file Process Proc = new Process(); Proc.StartInfo = new ProcessStartInfo(InputFileName); Proc.Start(); } return; }
internal void Draw ( PdfContents Contents, double DrawRectX, double DrawRectY, double DrawRectWidth, double DrawRectHeight, ContentAlignment Alignment = (ContentAlignment)0 ) { // save drawing rectangle in user coordinates this.DrawRectX = DrawRectX; this.DrawRectY = DrawRectY; this.DrawRectWidth = DrawRectWidth; this.DrawRectHeight = DrawRectHeight; // test arguments if (DrawRectWidth == 0 && DrawRectHeight == 0 || DrawRectWidth == 0 && PathBBoxWidth != 0 || DrawRectHeight == 0 && PathBBoxHeight != 0) { throw new ApplicationException("DrawWPFPath: Drawing rectangle is empty"); } // set transformation matrix SetTransformation(Alignment); // clip if (Stroking == null && NonStroking == null) { // build clipping path BuildPath(Contents, FillRule == FillRule.EvenOdd ? PaintOp.ClipPathEor : PaintOp.ClipPathWnr); return; } // paint operator PaintOp PaintOperator; // brush is defined as shading if (NonStroking != null && (NonStroking.GetType() == typeof(SysMedia.LinearGradientBrush) || NonStroking.GetType() == typeof(SysMedia.RadialGradientBrush) || NonStroking.GetType() == typeof(PdfAxialShading) || NonStroking.GetType() == typeof(PdfRadialShading))) { // save graphics state Contents.SaveGraphicsState(); // build clipping path BuildPath(Contents, FillRule == FillRule.EvenOdd ? PaintOp.ClipPathEor : PaintOp.ClipPathWnr); // set bland mode if (BlendMode != BlendMode.Normal) { Contents.SetBlendMode(BlendMode); } // set opacity Contents.SetAlphaNonStroking(BrushOpacity); // draw linera gradient brush shading bounded by clip path if (NonStroking.GetType() == typeof(SysMedia.LinearGradientBrush)) { PdfAxialShading AxialShading = new PdfAxialShading(Contents.Document, (SysMedia.LinearGradientBrush)NonStroking); AxialShading.SetBoundingBox(DrawRectX, DrawRectY, DrawRectWidth, DrawRectHeight); Contents.DrawShading(AxialShading); } // draw axial shading bounded by clip path else if (NonStroking.GetType() == typeof(PdfAxialShading)) { ((PdfAxialShading)NonStroking).SetBoundingBox(DrawRectX, DrawRectY, DrawRectWidth, DrawRectHeight); Contents.DrawShading((PdfAxialShading)NonStroking); } // draw radial gradient brush shading bounded by clip path else if (NonStroking.GetType() == typeof(SysMedia.RadialGradientBrush)) { PdfRadialShading RadialShading = new PdfRadialShading(Contents.Document, (SysMedia.RadialGradientBrush)NonStroking); RadialShading.SetBoundingBox(DrawRectX, DrawRectY, DrawRectWidth, DrawRectHeight); Contents.DrawShading(RadialShading); } // draw radial shading bounded by clip path else { ((PdfRadialShading)NonStroking).SetBoundingBox(DrawRectX, DrawRectY, DrawRectWidth, DrawRectHeight); Contents.DrawShading((PdfRadialShading)NonStroking); } // remove clipping path Contents.RestoreGraphicsState(); // no pen defined if (Stroking == null) { return; } // pen is defined PaintOperator = PaintOp.Stroke; } // set paint operator for all other cases (no shading) else { // we have pen and no brush if (NonStroking == null) { PaintOperator = PaintOp.Stroke; } // we have brush but no pen else if (Stroking == null) { PaintOperator = FillRule == FillRule.EvenOdd ? PaintOp.FillEor : PaintOp.Fill; } // we have brush and pen else { PaintOperator = FillRule == FillRule.EvenOdd ? PaintOp.CloseFillStrokeEor: PaintOp.CloseFillStroke; } } // save graphics state Contents.SaveGraphicsState(); // set bland mode if (BlendMode != BlendMode.Normal) { Contents.SetBlendMode(BlendMode); } // stroking (pen) is defined if (Stroking != null) { if (Stroking.GetType() == typeof(Color)) { // pen color Contents.SetColorStroking((Color)Stroking); // set opacity if (PenOpacity != 1.0) { Contents.SetAlphaStroking(PenOpacity); } // pen width if (PenWidth >= 0) { Contents.SetLineWidth(PenWidth); } // line cap if (LineCap != (PdfLineCap)(-1)) { Contents.SetLineCap(LineCap); } // line join if (LineJoin != (PdfLineJoin)(-1)) { Contents.SetLineJoin(LineJoin); } // Miter if (MiterLimit != -1) { Contents.SetMiterLimit(MiterLimit); } // line is made of dashes if (DashArray != null) { Contents.SetDashLine(DashArray, DashPhase); } } else if (Stroking.GetType() == typeof(SysMedia.Pen)) { // media pen short cut SysMedia.Pen Pen = (SysMedia.Pen)Stroking; // media brush shortcut SysMedia.SolidColorBrush Brush = (SysMedia.SolidColorBrush)Pen.Brush; // media pen color short cut SysMedia.Color PenColor = Brush.Color; // pen color Contents.SetColorStroking(Color.FromArgb(PenColor.R, PenColor.G, PenColor.B)); // pen opacity if (PenColor.A != 255 || Brush.Opacity != 1.0) { Contents.SetAlphaStroking((PenColor.A / 255.0) * Brush.Opacity); } // pen thickness converted to user units double Thickness = Pen.Thickness * Math.Max(Math.Abs(ScaleX), Math.Abs(ScaleY)); Contents.SetLineWidth(Thickness); // line cap // Note: PDF line cap is the same for start and end. We will ignore EndLineCap // Triangle line cap will be round switch (Pen.StartLineCap) { case SysMedia.PenLineCap.Flat: Contents.SetLineCap(PdfLineCap.Butt); break; case SysMedia.PenLineCap.Square: Contents.SetLineCap(PdfLineCap.Square); break; default: Contents.SetLineCap(PdfLineCap.Round); break; } // line join switch (Pen.LineJoin) { case SysMedia.PenLineJoin.Bevel: Contents.SetLineJoin(PdfLineJoin.Bevel); break; case SysMedia.PenLineJoin.Miter: Contents.SetLineJoin(PdfLineJoin.Miter); break; default: Contents.SetLineJoin(PdfLineJoin.Round); break; } // Miter Contents.SetMiterLimit(Pen.MiterLimit); // dash pattern if (Pen.DashStyle.Dashes.Count > 0) { int End = Pen.DashStyle.Dashes.Count; double[] PenDashArray = new double[End]; for (int Index = 0; Index < End; Index++) { PenDashArray[Index] = Thickness * Pen.DashStyle.Dashes[Index]; } Contents.SetDashLine(PenDashArray, Thickness * Pen.DashStyle.Offset); } } } // non-stroking (brush) is defined // note shading brush was handled above if (NonStroking != null) { // set opacity if (BrushOpacity != 1.0) { Contents.SetAlphaNonStroking(BrushOpacity); } // brush color if (NonStroking.GetType() == typeof(Color)) { Contents.SetColorNonStroking((Color)NonStroking); } else if (NonStroking.GetType() == typeof(PdfTilingPattern)) { Contents.SetPatternNonStroking((PdfTilingPattern)NonStroking); } } // build path BuildPath(Contents, PaintOperator); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Create charting examples PDF document //////////////////////////////////////////////////////////////////// public void Test ( Boolean Debug, String FileName ) { // Step 1: Create empty document // Arguments: page width: 8.5”, page height: 11”, Unit of measure: inches // Return value: PdfDocument main class Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName); // Debug property // By default it is set to false. Use it for debugging only. // If this flag is set, PDF objects will not be compressed, font and images will be replaced // by text place holder. You can view the file with a text editor but you cannot open it with PDF reader. Document.Debug = Debug; // for encryption test // Document.SetEncryption("Password", Permission.All & ~Permission.Print); ArialNormal = new PdfFont(Document, "Arial", FontStyle.Regular, true); Comic = new PdfFont(Document, "Comic Sans MS", FontStyle.Bold, true); // Step 3: Add new page Page = new PdfPage(Document); // Step 4:Add contents to page PdfContents Contents = new PdfContents(Page); // save graphics state Contents.SaveGraphicsState(); // Draw frame around the page // Set line width to 0.02" Contents.SetLineWidth(0.02); // set frame color dark blue Contents.SetColorStroking(Color.DarkBlue); Contents.SetColorNonStroking(Color.FromArgb(240, 250, 250)); // rectangle position: x=1.0", y=1.0", width=6.5", height=9.0" Contents.DrawRectangle(1.0, 1.0, 6.5, 9.0, PaintOp.CloseFillStroke); Contents.DrawLine(1.0, 8.5, 7.5, 8.5); Contents.DrawLine(1.0, 6.0, 7.5, 6.0); Contents.DrawLine(1.0, 3.5, 7.5, 3.5); // page heading Contents.DrawText(Comic, 40.0, 4.25, 9.25, TextJustify.Center, 0.02, Color.FromArgb(128, 0, 255), Color.FromArgb(255, 0, 128), "PDF FILE WRITER"); // change nonstroking (fill) color to purple Contents.SetColorNonStroking(Color.Purple); // Draw second line of heading text // arguments: Handwriting font, Font size 30 point, Position X=4.25", Y=9.0" // Text Justify: Center (text center will be at X position) Contents.DrawText(Comic, 30.0, 4.25, 8.75, TextJustify.Center, "Media Example"); // create embedded media file Example1(); Example2(); // restore graphics sate (non stroking color will be restored to default) Contents.RestoreGraphicsState(); // create the PDF file Document.CreateFile(); // start default PDF reader and display the file Process Proc = new Process(); Proc.StartInfo = new ProcessStartInfo(FileName); Proc.Start(); // exit return; }
public void Test ( bool Debug, string InputFileName ) { // create document using (Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, InputFileName)) { // set document page mode to open the layers panel Document.InitialDocDisplay = InitialDocDisplay.UseLayers; // define font ArialFont = PdfFont.CreatePdfFont(Document, "Arial", FontStyle.Bold); // open layer control object (in PDF terms optional content object) PdfLayers Layers = new PdfLayers(Document, "PDF layers group"); // set layer panel to incluse all layers including ones that are not visible Layers.ListMode = ListMode.AllPages; // Add new page PdfPage Page = new PdfPage(Document); // Add contents to page PdfContents Contents = new PdfContents(Page); // heading Contents.DrawText(ArialFont, 24, 4.25, 10, TextJustify.Center, "PDF File Writer Layer Test/Demo"); // define layers PdfLayer DrawingTest = new PdfLayer(Layers, "Drawing Test"); PdfLayer Rectangle = new PdfLayer(Layers, "Rectangle"); PdfLayer HorLines = new PdfLayer(Layers, "Horizontal Lines"); PdfLayer VertLines = new PdfLayer(Layers, "Vertical Lines"); PdfLayer QRCodeLayer = new PdfLayer(Layers, "QRCode barcode"); PdfLayer Pdf417Layer = new PdfLayer(Layers, "PDF417 barcode"); PdfLayer NoBarcodeLayer = new PdfLayer(Layers, "No barcode"); // combine three layers into one group of radio buttons QRCodeLayer.RadioButton = "Barcode"; Pdf417Layer.RadioButton = "Barcode"; NoBarcodeLayer.RadioButton = "Barcode"; // set the order of layers in the layer pane Layers.DisplayOrder(DrawingTest); Layers.DisplayOrder(Rectangle); Layers.DisplayOrder(HorLines); Layers.DisplayOrder(VertLines); Layers.DisplayOrderStartGroup("Barcode group"); Layers.DisplayOrder(QRCodeLayer); Layers.DisplayOrder(Pdf417Layer); Layers.DisplayOrder(NoBarcodeLayer); Layers.DisplayOrderEndGroup(); // start a group layer Contents.LayerStart(DrawingTest); // sticky note annotation PdfAnnotation StickyNote = Page.AddStickyNote(2.0, 9.0, "My sticky note", StickyNoteIcon.Note); StickyNote.LayerControl = DrawingTest; // draw a single layer Contents.LayerStart(Rectangle); Contents.DrawText(ArialFont, 14, 1.0, 8.0, TextJustify.Left, "Draw rectangle"); Contents.LayerEnd(); // draw a single layer Contents.LayerStart(HorLines); Contents.DrawText(ArialFont, 14, 1.0, 7.5, TextJustify.Left, "Draw horizontal lines"); Contents.LayerEnd(); // draw a single layer Contents.LayerStart(VertLines); Contents.DrawText(ArialFont, 14, 1.0, 7.0, TextJustify.Left, "Draw vertical lines"); Contents.LayerEnd(); double Left = 4.0; double Right = 7.0; double Top = 9.0; double Bottom = 6.0; // draw a single layer Contents.LayerStart(Rectangle); Contents.SaveGraphicsState(); Contents.SetLineWidth(0.1); Contents.SetColorStroking(Color.Black); Contents.SetColorNonStroking(Color.LightBlue); Contents.DrawRectangle(Left, Bottom, 3.0, 3.0, PaintOp.CloseFillStroke); Contents.RestoreGraphicsState(); Contents.LayerEnd(); // save graphics state Contents.SaveGraphicsState(); // draw a single layer Contents.SetLineWidth(0.02); Contents.LayerStart(HorLines); for (int Row = 1; Row < 6; Row++) { Contents.DrawLine(Left, Bottom + 0.5 * Row, Right, Bottom + 0.5 * Row); } Contents.LayerEnd(); // draw a single layer Contents.LayerStart(VertLines); for (int Col = 1; Col < 6; Col++) { Contents.DrawLine(Left + 0.5 * Col, Bottom, Left + 0.5 * Col, Top); } Contents.LayerEnd(); // restore graphics state Contents.RestoreGraphicsState(); // terminate a group of layers Contents.LayerEnd(); // define QRCode barcode QREncoder QREncoder = new QREncoder(); QREncoder.ErrorCorrection = ErrorCorrection.M; QREncoder.Encode(QRCodeArticle); PdfImage QRImage = new PdfImage(Document); QRImage.LoadImage(QREncoder); // define PDF417 barcode Pdf417Encoder Pdf417Encoder = new Pdf417Encoder(); Pdf417Encoder.ErrorCorrection = ErrorCorrectionLevel.AutoMedium; Pdf417Encoder.Encode(Pdf417Article); PdfImage Pdf417Image = new PdfImage(Document); Pdf417Image.LoadImage(Pdf417Encoder); // draw a single layer Contents.LayerStart(QRCodeLayer); Contents.DrawText(ArialFont, 14, 1.0, 2.5, TextJustify.Left, "QRCode Barcode"); Contents.DrawImage(QRImage, 3.7, 2.5 - 1.75, 3.5); Contents.LayerEnd(); // draw a single layer Contents.LayerStart(Pdf417Layer); Contents.DrawText(ArialFont, 14, 1.0, 2.5, TextJustify.Left, "PDF417 Barcode"); Contents.DrawImage(Pdf417Image, 3.7, 2.5 - 1.75 * Pdf417Encoder.ImageHeight / Pdf417Encoder.ImageWidth, 3.5); Contents.LayerEnd(); // draw a single layer Contents.LayerStart(NoBarcodeLayer); Contents.DrawText(ArialFont, 14, 1.0, 3.0, TextJustify.Left, "Display no barcode"); Contents.LayerEnd(); // create pdf file Document.CreateFile(); // start default PDF reader and display the file Process Proc = new Process(); Proc.StartInfo = new ProcessStartInfo(InputFileName); Proc.Start(); } return; }
// Draw example of a text box private static void DrawTextBox(PdfDocument document, PdfPage page) { PdfContents zContents = new PdfContents(page); PdfFont zArialNormal = new PdfFont(document, "Arial", FontStyle.Regular, true); zArialNormal.CharSubstitution(945, 950, 161); // Save graphics state: zContents.SaveGraphicsState(); // translate origin to PosX=1.1" and PosY=1.1" this is the bottom left corner of the text box example zContents.Translate(1.1, 1.1); // Define constants // Box width 3.25" // Box height is 3.65" // Normal font size is 9.0 points. const Double Width = 3.15; const Double Height = 3.65; const Double FontSize = 9.0; // Create text box object width 3.25" // First line indent of 0.25" TextBox Box = new TextBox(Width, 0.25); // add text to the text box Box.AddText(zArialNormal, FontSize, "This area is an example of displaying text that is too long to fit within a fixed width " + "area. The text is displayed justified to right edge. You define a text box with the required " + "width and first line indent. You add text to this box. The box will divide the text into " + "lines. Each line is made of segments of text. For each segment, you define font, font " + "size, drawing style and color. After loading all the text, the program will draw the formatted text.\n"); Box.AddText(zArialNormal, FontSize - 2.0, "Arial size 7, "); Box.AddText(zArialNormal, FontSize - 1.0, "size 8, "); Box.AddText(zArialNormal, FontSize, "size 9, "); Box.AddText(zArialNormal, FontSize + 1.0, "size 10. "); Box.AddText(zArialNormal, FontSize, DrawStyle.Underline, "Underline, "); Box.AddText(zArialNormal, FontSize, DrawStyle.Strikeout, "Strikeout. "); Box.AddText(zArialNormal, FontSize, "Subscript H"); Box.AddText(zArialNormal, FontSize, DrawStyle.Subscript, "2"); Box.AddText(zArialNormal, FontSize, "O. Superscript A"); Box.AddText(zArialNormal, FontSize, DrawStyle.Superscript, "2"); Box.AddText(zArialNormal, FontSize, "+B"); Box.AddText(zArialNormal, FontSize, DrawStyle.Superscript, "2"); Box.AddText(zArialNormal, FontSize, "=C"); Box.AddText(zArialNormal, FontSize, DrawStyle.Superscript, "2"); Box.AddText(zArialNormal, FontSize, "\n"); Box.AddText(zArialNormal, FontSize, "\n"); // Draw the text box // Text left edge is at zero (note: origin was translated to 1.1") // The top text base line is at Height less first line ascent. // Text drawing is limited to vertical coordinate of zero. // First line to be drawn is line zero. // After each line add extra 0.015". // After each paragraph add extra 0.05" // Stretch all lines to make smooth right edge at box width of 3.15" // After all lines are drawn, PosY will be set to the next text line after the box's last paragraph Double PosY = Height; zContents.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, TextBoxJustify.FitToWidth, Box); // Create text box object width 3.25" // No first line indent Box = new TextBox(Width); // Add text as before. // No extra line spacing. // No right edge adjustment Box.AddText(zArialNormal, FontSize, "In the examples above this area the text box was set for first line indent of " + "0.25 inches. This paragraph has zero first line indent and no right justify."); zContents.DrawText(0.0, ref PosY, 0.0, 0, 0.01, 0.05, TextBoxJustify.Left, Box); // Create text box object width 2.75 // First line hanging indent of 0.5" Box = new TextBox(Width - 0.5, -0.5); // Add text Box.AddText(zArialNormal, FontSize, "This paragraph is set to first line hanging indent of 0.5 inches. " + "The left margin of this paragraph is 0.5 inches."); // Draw the text // left edge at 0.5" zContents.DrawText(0.5, ref PosY, 0.0, 0, 0.01, 0.05, TextBoxJustify.Left, Box); // restore graphics state zContents.RestoreGraphicsState(); }
//////////////////////////////////////////////////////////////////// // create base contents for all pages //////////////////////////////////////////////////////////////////// /// <summary> /// ovde se kreira naslov svake strane, zaglavlje tabele kao i same ivice tabela /// </summary> public void CreateBaseContents() { // create unattached contents BaseContents = new PdfContents(Document); // save graphics state BaseContents.SaveGraphicsState(); // restore graphics state BaseContents.RestoreGraphicsState(); BaseContents.DrawText(ArialBold, 14, 0.5 * PageWidth, 11.5, TextJustify.Center, "IZVEŠTAJ O ISPITIVANJU MEHANIČKIH OSOBINA"); //draw logo PdfImage Image2 = new PdfImage(Document, System.Environment.CurrentDirectory + "\\logoLjig.png"); //BaseContents.DrawImage(Image1, 0.95, p1.Y - 3.8, ImageSize.Width - 1, ImageSize.Height); BaseContents.DrawImage(Image2, 8.5, 7.7, 1.4, 0.7); BaseContents.DrawText(ArialNormal, 8, 0.48, 7.85, TextJustify.Left, "BR. ZB. IZVEŠTAJA "); BaseContents.DrawLine(1.6, 8.0, 2.3, 8.0); BaseContents.DrawLine(1.6, 7.8, 2.3, 7.8); BaseContents.DrawLine(1.6, 8.0, 1.6, 7.8); BaseContents.DrawLine(2.3, 8.0, 2.3, 7.8); BaseContents.DrawText(ArialNormal, 8, 1.6, 7.85, TextJustify.Left, _sumReport.Records[0].BrzbIzvestaja); //horizontal lines BaseContents.DrawLine(0.45, 7.6, 10.8, 7.6); //BaseContents.DrawLine(0.45, 7.4, 10.8, 7.4); BaseContents.DrawLine(0.45, 7.2, 10.8, 7.2); BaseContents.DrawLine(0.45, 7.0, 10.8, 7.0); BaseContents.DrawLine(0.45, 6.8, 10.8, 6.8); BaseContents.DrawLine(0.45, 6.6, 10.8, 6.6); BaseContents.DrawLine(0.45, 6.4, 10.8, 6.4); BaseContents.DrawLine(0.45, 6.2, 10.8, 6.2); BaseContents.DrawLine(0.45, 6.0, 10.8, 6.0); BaseContents.DrawLine(0.45, 5.8, 10.8, 5.8); BaseContents.DrawLine(0.45, 5.6, 10.8, 5.6); BaseContents.DrawLine(0.45, 5.4, 10.8, 5.4); BaseContents.DrawLine(0.45, 5.2, 10.8, 5.2); BaseContents.DrawLine(0.45, 5.0, 10.8, 5.0); BaseContents.DrawLine(0.45, 4.8, 10.8, 4.8); BaseContents.DrawLine(0.45, 4.6, 10.8, 4.6); BaseContents.DrawLine(0.45, 4.4, 10.8, 4.4); BaseContents.DrawLine(0.45, 4.2, 10.8, 4.2); BaseContents.DrawLine(0.45, 4.0, 10.8, 4.0); BaseContents.DrawLine(0.45, 3.8, 10.8, 3.8); BaseContents.DrawLine(0.45, 3.6, 10.8, 3.6); BaseContents.DrawLine(0.45, 3.4, 10.8, 3.4); BaseContents.DrawLine(0.45, 3.2, 10.8, 3.2); BaseContents.DrawLine(0.45, 3.0, 10.8, 3.0); BaseContents.DrawLine(0.45, 2.8, 10.8, 2.8); BaseContents.DrawLine(0.45, 2.6, 10.8, 2.6); BaseContents.DrawLine(0.45, 2.4, 10.8, 2.4); BaseContents.DrawLine(0.45, 2.2, 10.8, 2.2); BaseContents.DrawLine(0.45, 2.0, 10.8, 2.0); BaseContents.DrawLine(0.45, 1.8, 10.8, 1.8); BaseContents.DrawLine(0.45, 1.6, 10.8, 1.6); BaseContents.DrawLine(0.45, 1.4, 10.8, 1.4); BaseContents.DrawLine(0.45, 1.2, 10.8, 1.2); //BaseContents.DrawLine(0.45, 1.0, 10.8, 1.0);//31st row //BaseContents.DrawLine(0.45, 0.8, 10.8, 0.8);//32nd row //BaseContents.DrawLine(0.45, 0.6, 10.8, 0.6);//33th row //BaseContents.DrawLine(0.45, 0.4, 10.8, 0.4);//34th row //vertical two lines //BaseContents.DrawLine(0.45, 7.6, 0.45, 0.4);//this is for 34 rows per page //BaseContents.DrawLine(10.8, 7.6, 10.8, 0.4); BaseContents.DrawLine(0.45, 7.6, 0.45, 1.2); BaseContents.DrawLine(10.8, 7.6, 10.8, 1.2); //header BaseContents.DrawLine(0.75, 7.6, 0.75, 7.2); BaseContents.DrawText(ArialNormal, 8, 0.48, 7.42, TextJustify.Left, "RED."); BaseContents.DrawText(ArialNormal, 8, 0.48, 7.24, TextJustify.Left, "BR."); BaseContents.DrawLine(1.45 + 0.2125, 7.6, 1.45 + 0.2125, 7.2); BaseContents.DrawText(ArialNormal, 8, 1.00, 7.42, TextJustify.Left, "BROJ" /*"POLAZNI"*/); BaseContents.DrawText(ArialNormal, 8, 1.00, 7.24, TextJustify.Left, "UZORKA" /*"KVALITET"*/); BaseContents.DrawLine(2.15 + 2 * 0.2125, 7.6, 2.15 + 2 * 0.2125, 7.2); BaseContents.DrawText(ArialNormal, 8, 1.95, 7.32, TextJustify.Left, "ŠARŽA" /*"NAZIVNA"*/); //BaseContents.DrawText(ArialNormal, 8, 1.75, 7.24, TextJustify.Left, "DEBLJINA"); //BaseContents.DrawLine(3.8, 7.6, 3.8, 7.2); //BaseContents.DrawText(ArialNormal, 8, 2.67, 7.42, TextJustify.Left, "ISPITIVAČ"); BaseContents.DrawLine(4.5 - 0.7125, 7.6, 4.5 - 0.7125, 7.2); BaseContents.DrawText(ArialNormal, 8, 2.95, 7.42, TextJustify.Left, "POLAZNI" /*"BROJ"*/); BaseContents.DrawText(ArialNormal, 8, 2.95, 7.24, TextJustify.Left, "KVALITET" /*"UZORKA"*/); BaseContents.DrawLine(4.6, 7.6, 4.6, 7.2); BaseContents.DrawText(ArialNormal, 8, 3.95, 7.42, TextJustify.Left, "NAZIVNA" /*"ŠARŽA"*/); BaseContents.DrawText(ArialNormal, 8, 3.95, 7.24, TextJustify.Left, "DEBLJINA" /*"ŠARŽA"*/); //BaseContents.DrawLine(8.5, 7.6, 8.5, 7.2);//vertical line na kraju mehanicko tehnickih osobina BaseContents.DrawLine(8.5, 7.4, 8.5, 7.2); // samo za A ne za sve jel smo dodali Z BaseContents.DrawLine(4.6, 7.4, 9.4, 7.4); //horizontal line BaseContents.DrawText(ArialNormal, 8.5, 6.0, 7.45, TextJustify.Left, "MEHANIČKO-TEHNIČKE OSOBINE"); BaseContents.DrawText(ArialNormal, 8, 7.45 /*4.65*/, 7.24, TextJustify.Left, "Rm[MPa]"); BaseContents.DrawLine(5.2 + 0.00, 7.4, 5.2 + 0.00, 7.2); BaseContents.DrawText(ArialNormal, 8, 4.65 /*5.28*/, 7.24, TextJustify.Left, "R"); BaseContents.DrawText(ArialNormal, 6.5, 4.73 /*5.36*/, 7.24, TextJustify.Left, "p0.2"); BaseContents.DrawText(ArialNormal, 8, 4.92 /*5.55*/, 7.24, TextJustify.Left, "[MPa]"); BaseContents.DrawLine(5.9 + 0.00, 7.4, 5.9 + 0.00, 7.2); BaseContents.DrawText(ArialNormal, 8, 5.28 /*5.98*/, 7.24, TextJustify.Left, "R"); BaseContents.DrawText(ArialNormal, 6.5, 5.36 /*6.05*/, 7.24, TextJustify.Left, "t0.5"); BaseContents.DrawText(ArialNormal, 8, 5.55 /*6.24*/, 7.24, TextJustify.Left, "[MPa]"); BaseContents.DrawLine(6.6 + 2 * 0.00, 7.4, 6.6 + 2 * 0.00, 7.2); BaseContents.DrawText(ArialNormal, 8, 6.0 /*6.7*/, 7.24, TextJustify.Left, "ReL[MPa]"); BaseContents.DrawLine(7.3 + 3 * 0.00, 7.4, 7.3 + 3 * 0.00, 7.2); BaseContents.DrawText(ArialNormal, 8, 6.7 /*7.41*/, 7.24, TextJustify.Left, "ReH[MPa]"); BaseContents.DrawLine(8.0 + 4 * 0.00, 7.4, 8.0 + 4 * 0.00, 7.2); //BaseContents.DrawLine(8.7, 7.4, 8.7, 7.2); BaseContents.DrawText(ArialNormal, 8, 8.05, 7.24, TextJustify.Left, "A[%]"); BaseContents.DrawLine(9.0 + 4 * 0.00, 7.6, 9.0 + 4 * 0.00, 7.2);//za kraj mehanicko tehnickih osobina vertikalna linija BaseContents.DrawText(ArialNormal, 8, 9.15, 7.24, TextJustify.Left, "KV[J]"); BaseContents.DrawLine(9.6 + 4 * 0.00, 7.4, 9.6 + 4 * 0.00, 7.2); BaseContents.DrawText(ArialNormal, 8, 9.75, 7.24, TextJustify.Left, "KU[J]"); BaseContents.DrawLine(10.2 + 4 * 0.00, 7.4, 10.2 + 4 * 0.00, 7.2); //BaseContents.DrawLine(9.4, 7.4, 9.4, 7.2); //BaseContents.DrawText(ArialNormal, 8, 9.0, 7.24, TextJustify.Left, "At"); //BaseContents.DrawLine(10.8, 7.6, 10.8, 7.4);//vertical line BaseContents.DrawLine(9.4, 7.4, 10.8, 7.4);//horizontal line //BaseContents.DrawText(ArialNormal, 8, 9.45, 7.42, TextJustify.Left, "FAKTOR"); //BaseContents.DrawLine(10.2, 7.6, 10.2, 7.2);//faktor BaseContents.DrawText(ArialNormal, 8, 10.5, 7.24, TextJustify.Left, "n"); BaseContents.DrawText(ArialNormal, 8, 8.6, 7.24, TextJustify.Left, "Z[%]"); //BaseContents.DrawText(ArialNormal, 8, 0.5, 7.05, TextJustify.Left, "NAPOMENATEST"); //BaseContents.DrawLine(0.75, 7.4, 0.75, 7.2); //BaseContents.DrawLine(1.45, 7.4, 1.45, 7.2); //BaseContents.DrawLine(2.15, 7.4, 2.15, 7.2); //BaseContents.DrawLine(3.8, 7.4, 3.8, 7.2); BaseContents.DrawText(ArialNormal, 8, 0.45, 0.25, TextJustify.Left, "VERIFIKOVAO"); BaseContents.DrawLine(1.3, 0.2, 5, 0.2);//horizontal line BaseContents.DrawText(ArialNormal, 8, 7, 0.25, TextJustify.Left, "ISPITIVAČ"); BaseContents.DrawLine(7.8, 0.4, 9.8, 0.4); BaseContents.DrawLine(7.8, 0.2, 7.8, 0.4); BaseContents.DrawLine(9.8, 0.2, 9.8, 0.4); BaseContents.DrawLine(7.8, 0.2, 9.8, 0.2); BaseContents.DrawText(ArialNormal, 8, 7.8 + 0.01, 0.25, TextJustify.Left, _sumReport.Records[0].Ispitivac);//u jednom zbirnom izvestaju treba da ima samo jedan ispitivac // exit return; }
//////////////////////////////////////////////////////////////////// // Draw example of a text box //////////////////////////////////////////////////////////////////// private void DrawTextBox ( PdfContents Contents ) { // save graphics state Contents.SaveGraphicsState(); // translate origin to PosX=1.1" and PosY=1.1" this is the bottom left corner of the text box example Contents.Translate(1.1, 1.1); // Contents.TranslateScaleRotate(7.4, 1.1, 1.0, Math.PI / 2); // Define constants // Box width 3.25" // Box height is 3.65" // Normal font size is 9.0 points. const Double Width = 3.15; const Double Height = 3.65; const Double FontSize = 9.0; // Create text box object width 3.25" // First line indent of 0.25" TextBox Box = new TextBox(Width, 0.25); // add text to the text box Box.AddText(ArialNormal, FontSize, "This area is an example of displaying text that is too long to fit within a fixed width " + "area. The text is displayed justified to right edge. You define a text box with the required " + "width and first line indent. You add text to this box. The box will divide the text into " + "lines. Each line is made of segments of text. For each segment, you define font, font " + "size, drawing style and color. After loading all the text, the program will draw the formatted text.\n"); Box.AddText(TimesNormal, FontSize + 1.0, "Example of multiple fonts: Times New Roman, "); Box.AddText(Comic, FontSize, "Comic Sans MS, "); Box.AddText(ArialNormal, FontSize, "Example of regular, "); Box.AddText(ArialBold, FontSize, "bold, "); Box.AddText(ArialItalic, FontSize, "italic, "); Box.AddText(ArialBoldItalic, FontSize, "bold plus italic. "); Box.AddText(ArialNormal, FontSize - 2.0, "Arial size 7, "); Box.AddText(ArialNormal, FontSize - 1.0, "size 8, "); Box.AddText(ArialNormal, FontSize, "size 9, "); Box.AddText(ArialNormal, FontSize + 1.0, "size 10. "); Box.AddText(ArialNormal, FontSize, DrawStyle.Underline, "Underline, "); Box.AddText(ArialNormal, FontSize, DrawStyle.Strikeout, "Strikeout. "); Box.AddText(ArialNormal, FontSize, "Subscript H"); Box.AddText(ArialNormal, FontSize, DrawStyle.Subscript, "2"); Box.AddText(ArialNormal, FontSize, "O. Superscript A"); Box.AddText(ArialNormal, FontSize, DrawStyle.Superscript, "2"); Box.AddText(ArialNormal, FontSize, "+B"); Box.AddText(ArialNormal, FontSize, DrawStyle.Superscript, "2"); Box.AddText(ArialNormal, FontSize, "=C"); Box.AddText(ArialNormal, FontSize, DrawStyle.Superscript, "2"); Box.AddText(ArialNormal, FontSize, "\n"); Box.AddText(Comic, FontSize, Color.Red, "Lets add some color, "); Box.AddText(Comic, FontSize, Color.Green, "green, "); Box.AddText(Comic, FontSize, Color.Blue, "blue, "); Box.AddText(Comic, FontSize, Color.Orange, "orange, "); Box.AddText(Comic, FontSize, DrawStyle.Underline, Color.Purple, "and purple.\n"); // Draw the text box // Text left edge is at zero (note: origin was translated to 1.1") // The top text base line is at Height less first line ascent. // Text drawing is limited to vertical coordinate of zero. // First line to be drawn is line zero. // After each line add extra 0.015". // After each paragraph add extra 0.05" // Stretch all lines to make smooth right edge at box width of 3.15" // After all lines are drawn, PosY will be set to the next text line after the box's last paragraph Double PosY = Height; Contents.DrawText(0.0, ref PosY, 0.0, 0, 0.015, 0.05, true, Box); // Create text box object width 3.25" // No first line indent Box = new TextBox(Width); // Add text as before. // No extra line spacing. // No right edge adjustment Box.AddText(ArialNormal, FontSize, "In the examples above this area the text box was set for first line indent of " + "0.25 inches. This paragraph has zero first line indent and no right justify."); Contents.DrawText(0.0, ref PosY, 0.0, 0, 0.01, 0.05, false, Box); // Create text box object width 2.75 // First line hanging indent of 0.5" Box = new TextBox(Width - 0.5, -0.5); // Add text Box.AddText(ArialNormal, FontSize, "This paragraph is set to first line hanging indent of 0.5 inches. " + "The left margin of this paragraph is 0.5 inches."); // Draw the text // left edge at 0.5" Contents.DrawText(0.5, ref PosY, 0.0, 0, 0.01, 0.05, false, Box); // restore graphics state Contents.RestoreGraphicsState(); return; }
//////////////////////////////////////////////////////////////////// // Draw example of order form //////////////////////////////////////////////////////////////////// private void DrawBookOrderForm ( PdfContents Contents ) { // Order form simulation // Define constants to make the code readable // Define constants const Double Width = 3.05; const Double Height = 3.65; const Double Margin = 0.04; const Double FontSize = 9.0; Double LineSpacing = ArialNormal.LineSpacing(FontSize); Double Descent = ArialNormal.Descent(FontSize); Double ColWidth1 = ArialNormal.TextWidth(FontSize, "9999.99") + 2 * Margin; Double ColWidth2 = ArialNormal.TextWidth(FontSize, "Qty") + 2 * Margin; Double Col4LinePosX = Width - ColWidth1; Double Col3LinePosX = Col4LinePosX - ColWidth2; Double Col2LinePosX = Col3LinePosX - ColWidth1; Double Col1TextPosX = Margin; Double Col2TextPosX = Col3LinePosX - Margin; Double Col3TextPosX = Col4LinePosX - Margin; Double Col4TextPosX = Width - Margin; // save graphics state Contents.SaveGraphicsState(); // form line width 0.01" Contents.SetLineWidth(0.01); // Initial vertical position for contents Double PosY1 = Height - LineSpacing - 2 * Margin; // bottom of the contents area of the form Double PosY2 = 2 * Margin + 3 * LineSpacing; // shift origin, bottom left of the form to X=4.35" and Y=1.1" Contents.Translate(4.35, 1.1); // draw outline rectangle Contents.DrawRectangle(0.0, 0.0, Width, Height, PaintOp.CloseStroke); // draw two horizontal lines. under table heading and above total Contents.DrawLine(0, PosY1, Width, PosY1); Contents.DrawLine(0, PosY2, Width, PosY2); // draw three vertical lines separating the columns Contents.DrawLine(Col2LinePosX, Height, Col2LinePosX, PosY2); Contents.DrawLine(Col3LinePosX, Height, Col3LinePosX, PosY2); Contents.DrawLine(Col4LinePosX, Height, Col4LinePosX, 0); // draw table heading Double PosY = PosY1 + Margin + Descent; Contents.DrawText(ArialNormal, FontSize, Col1TextPosX, PosY, "Description"); Contents.DrawText(ArialNormal, FontSize, Col2TextPosX, PosY, TextJustify.Right, "Price"); Contents.DrawText(ArialNormal, FontSize, Col3TextPosX, PosY, TextJustify.Right, "Qty"); Contents.DrawText(ArialNormal, FontSize, Col4TextPosX, PosY, TextJustify.Right, "Total"); // reset order total Double Total = 0; // define text box for book title and author TextBox Box = new TextBox(Col2LinePosX - 2 * Margin); // initial vertical position PosY = PosY1 - Margin; // loop for all items in the order // Order class is a atabase simulation for this example foreach (Order Book in Order.OrderList) { // clear the text box Box.Clear(); // add book title and authors to the box Box.AddText(ArialNormal, FontSize, Book.Title); Box.AddText(ArialNormal, FontSize, ". By: "); Box.AddText(ArialNormal, FontSize, Book.Authors); // draw the title and authors. // on exit, PosY will be for next line Contents.DrawText(Col1TextPosX, ref PosY, PosY2, 0, Box); // move PosY up to allow drawing cost on the same line as the last text line of the box PosY += Descent; // draw price quantity and item's total Contents.DrawText(ArialNormal, FontSize, Col2TextPosX, PosY, TextJustify.Right, Book.Price.ToString("#.00")); Contents.DrawText(ArialNormal, FontSize, Col3TextPosX, PosY, TextJustify.Right, Book.Qty.ToString()); Contents.DrawText(ArialNormal, FontSize, Col4TextPosX, PosY, TextJustify.Right, Book.Total.ToString("#.00")); // update PosY for next item PosY -= Descent + 0.5 * LineSpacing; // accumulate total Total += Book.Total; } // draw total before tax PosY = PosY2 - Margin - ArialNormal.Ascent(FontSize); Contents.DrawText(ArialNormal, FontSize, Col3TextPosX, PosY, TextJustify.Right, "Total before tax"); Contents.DrawText(ArialNormal, FontSize, Col4TextPosX, PosY, TextJustify.Right, Total.ToString("#.00")); // draw tax (Ontario Canada HST) PosY -= LineSpacing; Contents.DrawText(ArialNormal, FontSize, Col3TextPosX, PosY, TextJustify.Right, "Tax (13%)"); Double Tax = Math.Round(0.13 * Total, 2, MidpointRounding.AwayFromZero); Contents.DrawText(ArialNormal, FontSize, Col4TextPosX, PosY, TextJustify.Right, Tax.ToString("#.00")); // draw final total PosY -= LineSpacing; Contents.DrawText(ArialNormal, FontSize, Col3TextPosX, PosY, TextJustify.Right, "Total payable"); Total += Tax; Contents.DrawText(ArialNormal, FontSize, Col4TextPosX, PosY, TextJustify.Right, Total.ToString("#.00")); // restore graphics state Contents.RestoreGraphicsState(); return; }