/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { // Create a PDF document with 10 pages. PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 216); PdfBrush blackBrush = new PdfBrush(); for (int i = 0; i < 10; i++) { PdfPage page = document.Pages.Add(); page.Graphics.DrawString((i + 1).ToString(), helvetica, blackBrush, 5, 5); } CreateNamedActions(document, helvetica); CreateGoToActions(document, helvetica); CreateRemoteGoToActions(document, helvetica); CreateLaunchActions(document, helvetica); CreateUriActions(document, helvetica); CreateJavaScriptActions(document, helvetica); CreateDocumentActions(document); // Compress the page graphic content. for (int i = 0; i < document.Pages.Count; i++) { document.Pages[i].Graphics.CompressAndClose(); } SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.actions.pdf") }; return output; }
/// <summary> /// /// </summary> /// <param name="page"></param> private static void DrawWatermarkOverPageContent(PdfPage page) { PdfBrush redBrush = new PdfBrush(new PdfRgbColor(192, 0, 0)); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 32); // The page graphics is located by default on top of existing page content. //page.SetGraphicsPosition(PdfPageGraphicsPosition.OverExistingPageContent); // Draw the watermark over page content. // Page content under the watermark will be masked. page.Graphics.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 335); page.Graphics.SaveGraphicsState(); // Draw the watermark over page content but using the Multiply blend mode. // The watermak will appear as if drawn under the page content, useful when watermarking scanned documents. // If the watermark is drawn under page content for scanned documents, it will not be visible because the scanned image will block it. PdfExtendedGraphicState gs1 = new PdfExtendedGraphicState(); gs1.BlendMode = PdfBlendMode.Multiply; page.Graphics.SetExtendedGraphicState(gs1); page.Graphics.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 385); // Draw the watermark over page content but using the Luminosity blend mode. // Both the page content and the watermark will be visible. PdfExtendedGraphicState gs2 = new PdfExtendedGraphicState(); gs2.BlendMode = PdfBlendMode.Luminosity; page.Graphics.SetExtendedGraphicState(gs2); page.Graphics.DrawString("Sample watermark over page content", helvetica, redBrush, 20, 435); page.Graphics.RestoreGraphicsState(); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PdfDocumentFeatures df = new PdfDocumentFeatures(); // Do not load file attachments, new file attachments cannot be added. df.EnableDocumentFileAttachments = false; // Do not load form fields, form fields cannot be filled and new form fields cannot be added. df.EnableDocumentFormFields = false; // Do not load embedded JavaScript code, new JavaScript code at document level cannot be added. df.EnableDocumentJavaScriptFragments = false; // Do not load the named destinations, new named destinations cannot be created. df.EnableDocumentNamedDestinations = false; // Do not load the document outlines, new outlines cannot be created. df.EnableDocumentOutline = false; // Do not load annotations, new annotations cannot be added to existing pages. df.EnablePageAnnotations = false; // Do not load the page graphics, new graphics cannot be added to existing pages. df.EnablePageGraphics = false; PdfFixedDocument document = new PdfFixedDocument(input, df); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 24); PdfBrush brush = new PdfBrush(); // Add a new page with some content on it. PdfPage page = document.Pages.Add(); page.Graphics.DrawString("New page added to an existing document.", helvetica, brush, 20, 50); // When document features have been specified at load time the document is automatically saved in incremental update mode. document.Save(input); return null; }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream s1, Stream s2) { PdfFixedDocument document = new PdfFixedDocument(); document.DisplayMode = PdfDisplayMode.UseAttachments; PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 16); PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("This document contains 2 file attachments:", helvetica, blackBrush, 50, 50); page.Graphics.DrawString("1. fileattachments.cs.html", helvetica, blackBrush, 50, 70); page.Graphics.DrawString("2. fileattachments.vb.html", helvetica, blackBrush, 50, 90); byte[] fileData1 = new byte[s1.Length]; s1.Read(fileData1, 0, fileData1.Length); PdfDocumentFileAttachment fileAttachment1 = new PdfDocumentFileAttachment(); fileAttachment1.Payload = fileData1; fileAttachment1.FileName = "fileattachments.cs.html"; fileAttachment1.Description = "C# Source Code for FileAttachments sample"; document.FileAttachments.Add(fileAttachment1); byte[] fileData2 = new byte[s2.Length]; s2.Read(fileData2, 0, fileData2.Length); PdfDocumentFileAttachment fileAttachment2 = new PdfDocumentFileAttachment(); fileAttachment2.Payload = fileData1; fileAttachment2.FileName = "fileattachments.vb.html"; fileAttachment2.Description = "VB.NET Source Code for FileAttachments sample"; document.FileAttachments.Add(fileAttachment2); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.fileattachments.pdf") }; return output; }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); document.DisplayMode = PdfDisplayMode.UseOutlines; PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 216); PdfBrush blackBrush = new PdfBrush(); for (int i = 0; i < 10; i++) { PdfPage page = document.Pages.Add(); page.Graphics.DrawString((i + 1).ToString(), helvetica, blackBrush, 50, 50); } PdfOutlineItem root = new PdfOutlineItem(); root.Title = "Contents"; root.VisualStyle = PdfOutlineItemVisualStyle.Bold; root.Color = new PdfRgbColor(255, 0, 0); document.Outline.Add(root); for (int i = 0; i < document.Pages.Count; i++) { // Create a destination to target page. PdfPageDirectDestination pageDestination = new PdfPageDirectDestination(); pageDestination.Page = document.Pages[i]; pageDestination.Top = 0; pageDestination.Left = 0; // Inherit current zoom pageDestination.Zoom = 0; // Create a go to action to be executed when the outline is clicked, // the go to action goes to specified destination. PdfGoToAction gotoPage = new PdfGoToAction(); gotoPage.Destination = pageDestination; // Create the outline in the table of contents PdfOutlineItem outline = new PdfOutlineItem(); outline.Title = string.Format("Go to page {0}", i + 1); outline.VisualStyle = PdfOutlineItemVisualStyle.Italic; outline.Action = gotoPage; root.Items.Add(outline); } root.Expanded = true; // Create an outline that will launch a link in the browser. PdfUriAction uriAction = new PdfUriAction(); uriAction.URI = "http://www.xfiniumsoft.com/"; PdfOutlineItem webOutline = new PdfOutlineItem(); webOutline.Title = "http://www.xfiniumsoft.com/"; webOutline.Color = new PdfRgbColor(0, 0, 255); webOutline.Action = uriAction; document.Outline.Add(webOutline); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.outlines.pdf") }; return output; }
/// <summary> /// Decrypts a PDF file /// </summary> /// <param name="input">Input stream.</param> /// <returns></returns> private static PdfFixedDocument Decrypt(Stream input) { PdfFixedDocument doc = new PdfFixedDocument(input, "xfiniumopen"); PdfPage page = doc.Pages[0]; PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBoldItalic, 16); PdfBrush blackBrush = new PdfBrush(); page.Graphics.DrawString("Decrypted document", helvetica, blackBrush, 5, 5); return doc; }
/// <summary> /// /// </summary> /// <param name="page"></param> private static void DrawWatermarkUnderPageContent(PdfPage page) { PdfBrush redBrush = new PdfBrush(new PdfRgbColor(192, 0, 0)); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 36); // Set the page graphics to be located under existing page content. page.SetGraphicsPosition(PdfPageGraphicsPosition.UnderExistingPageContent); PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions(); sao.Brush = redBrush; sao.Font = helvetica; PdfStringLayoutOptions slo = new PdfStringLayoutOptions(); slo.X = 130; slo.Y = 670; slo.Rotation = 60; page.Graphics.DrawString("Sample watermark under page content", sao, slo); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream output) { PdfFixedDocument document = new PdfFixedDocument(); // Init the save operation document.BeginSave(output); PdfRgbColor color = new PdfRgbColor(); PdfBrush brush = new PdfBrush(color); Random rnd = new Random(); for (int i = 0; i < 3; i++) { PdfPage page = document.Pages.Add(); page.Width = 1000; page.Height = 1000; for (int y = 1; y <= page.Height; y++) { for (int x = 0; x < page.Width; x++) { color.R = (byte)rnd.Next(256); color.G = (byte)rnd.Next(256); color.B = (byte)rnd.Next(256); page.Graphics.DrawRectangle(brush, x, y - 1, 1, 1); } if ((y % 100) == 0) { // Compress the graphics that have been drawn so far and save them. page.Graphics.Compress(); page.SaveGraphics(); } } // Close the page graphics and save the page. page.Graphics.CompressAndClose(); page.Save(); } // Finish the document. document.EndSave(); return null; }
private static void DisableTextCopy(PdfPage page, Stream ttfStream) { PdfStandardFont titleFont = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 22); PdfBrush blackBrush = new PdfBrush(new PdfRgbColor()); page.Graphics.DrawString("Draw text that cannot be copied and", titleFont, blackBrush, 20, 50); page.Graphics.DrawString("pasted in another applications", titleFont, blackBrush, 20, 75); ttfStream.Position = 0; PdfUnicodeTrueTypeFont f1 = new PdfUnicodeTrueTypeFont(ttfStream, 16, true); page.Graphics.DrawString("This text can be copied and pasted", f1, blackBrush, 20, 150); page.Graphics.DrawString("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", f1, blackBrush, 20, 175); ttfStream.Position = 0; PdfUnicodeTrueTypeFont f2 = new PdfUnicodeTrueTypeFont(ttfStream, 16, true); f2.EnableTextCopy = false; page.Graphics.DrawString("This text cannot be copied and pasted.", f2, blackBrush, 20, 225); page.Graphics.DrawString("Praesent sed massa a est fringilla mattis. Aenean sit amet odio ac nunc.", f2, blackBrush, 20, 250); }
private static void DrawAffineTransformations(PdfPage page, PdfFont titleFont, PdfFont sectionFont) { PdfBrush brush = new PdfBrush(); PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1); PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1); PdfPen bluePen = new PdfPen(PdfRgbColor.Blue, 1); PdfPen greenPen = new PdfPen(PdfRgbColor.Green, 1); page.Graphics.DrawString("Affine transformations", titleFont, brush, 20, 50); page.Graphics.DrawLine(blackPen, 0, page.Height / 2, page.Width, page.Height / 2); page.Graphics.DrawLine(blackPen, page.Width / 2, 0, page.Width / 2, page.Height); page.Graphics.SaveGraphicsState(); // Move the coordinate system in the center of the page. page.Graphics.TranslateTransform(page.Width / 2, page.Height / 2); // Draw a rectangle with the center at (0, 0) page.Graphics.DrawRectangle(redPen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4); // Rotate the coordinate system with 30 degrees. page.Graphics.RotateTransform(30); // Draw the same rectangle with the center at (0, 0) page.Graphics.DrawRectangle(greenPen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4); // Scale the coordinate system with 1.5 page.Graphics.ScaleTransform(1.5, 1.5); // Draw the same rectangle with the center at (0, 0) page.Graphics.DrawRectangle(bluePen, -page.Width / 4, -page.Height / 8, page.Width / 2, page.Height / 4); page.Graphics.RestoreGraphicsState(); page.Graphics.CompressAndClose(); }
private static void DrawToPage(PdfPageBase page, string text, PdfTrueTypeFont font, PdfBrush brushColor, PdfStringFormat formatLeft, RectangleF area, float y, out float yout, bool ignoreOut) { page.Canvas.DrawString(text, font, brushColor, area, formatLeft); SizeF size = font.MeasureString(text, area.Size, formatLeft); yout = (ignoreOut) ? y : y + size.Height + 2; }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { // Create the pdf document PdfFixedDocument document = new PdfFixedDocument(); // Create a new page in the document PdfPage page = document.Pages.Add(); PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1); PdfPen redPen = new PdfPen(PdfRgbColor.Red, 4); PdfPen greenPen = new PdfPen(PdfRgbColor.Green, 2); PdfBrush blackBrush = new PdfBrush(PdfRgbColor.Black); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 16); // Draw viewport border. page.Graphics.DrawRectangle(blackPen, 50, 50, 500, 500); // Draw the line to be measured. page.Graphics.DrawLine(greenPen, 70, 70, 530, 530); // Draw point A (line start) in the viewport. page.Graphics.DrawLine(redPen, 60, 70, 80, 70); page.Graphics.DrawLine(redPen, 70, 60, 70, 80); // Draw point B (line end) in the viewport. page.Graphics.DrawLine(redPen, 520, 530, 540, 530); page.Graphics.DrawLine(redPen, 530, 520, 530, 540); page.Graphics.DrawString("A", helvetica, blackBrush, 85, 65); page.Graphics.DrawString("B", helvetica, blackBrush, 505, 525); page.Graphics.DrawString("Viewport", helvetica, blackBrush, 50, 560); helvetica.Size = 10; page.Graphics.DrawString( "Open the file with Adobe Acrobat and measure the distance from A to B using the Distance tool.", helvetica, blackBrush, 50, 580); page.Graphics.DrawString("The measured distance should be 9 mi 186 ft 1 1/4 in.", helvetica, blackBrush, 50, 590); // Create a viewport that matches the rectangle above. PdfViewport vp = new PdfViewport(); vp.Name = "Sample viewport"; PdfPoint ll = page.ConvertVisualPointToStandardPoint(new PdfPoint(50, 50)); PdfPoint ur = page.ConvertVisualPointToStandardPoint(new PdfPoint(550, 550)); vp.Bounds = new PdfStandardRectangle(ll, ur); // Add the viewport to the page page.Viewports = new PdfViewportCollection(); page.Viewports.Add(vp); // Create a rectilinear measure for the viewport (CAD drawing for example). PdfRectilinearMeasure rlm = new PdfRectilinearMeasure(); // Attach the measure to the viewport. vp.Measure = rlm; // Set the measure scale: 1 inch (72 points) in PDF corresponds to 1 mile rlm.ScaleRatio = "1 in = 1 mi"; // Create a number format that controls the display of units for X axis. PdfNumberFormat xNumberFormat = new PdfNumberFormat(); xNumberFormat.MeasureUnit = "mi"; xNumberFormat.ConversionFactor = 1/72.0; // Conversion from user space units to miles xNumberFormat.FractionDisplay = PdfFractionDisplay.Decimal; xNumberFormat.Precision = 100000; rlm.X = new PdfNumberFormatCollection(); rlm.X.Add(xNumberFormat); // Create a chain of number formats that control the display of units for distance. rlm.Distance = new PdfNumberFormatCollection(); PdfNumberFormat miNumberFormat = new PdfNumberFormat(); miNumberFormat.MeasureUnit = "mi"; miNumberFormat.ConversionFactor = 1; // Initial unit is miles; no conversion needed rlm.Distance.Add(miNumberFormat); PdfNumberFormat ftNumberFormat = new PdfNumberFormat(); ftNumberFormat.MeasureUnit = "ft"; ftNumberFormat.ConversionFactor = 5280; // Conversion from miles to feet rlm.Distance.Add(ftNumberFormat); PdfNumberFormat inNumberFormat = new PdfNumberFormat(); inNumberFormat.MeasureUnit = "in"; inNumberFormat.ConversionFactor = 12; // Conversion from feet to inches inNumberFormat.FractionDisplay = PdfFractionDisplay.Fraction; inNumberFormat.Denominator = 8; // Fractions of inches rounded to nearest 1/8 rlm.Distance.Add(inNumberFormat); // Create a number format that controls the display of units area. PdfNumberFormat areaNumberFormat = new PdfNumberFormat(); areaNumberFormat.MeasureUnit = "acres"; areaNumberFormat.ConversionFactor = 640; // Conversion from square miles to acres rlm.Area = new PdfNumberFormatCollection(); rlm.Area.Add(xNumberFormat); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.measurements.pdf") }; return output; }
public ActionResult Barcode(string InsideBrowser) { //Create a new instance of PdfDocument class. PdfDocument document = new PdfDocument(); //Add a new page to the document. PdfPage page = document.Pages.Add(); //Create Pdf graphics for the page PdfGraphics g = page.Graphics; //Create a solid brush PdfBrush brush = PdfBrushes.Black; #region 2D Barcode //Set the font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 15f, PdfFontStyle.Bold); PdfPen pen = new PdfPen(brush, 0.5f); float width = page.GetClientSize().Width; float xPos = page.GetClientSize().Width / 2; PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; // Draw String g.DrawString("2D Barcodes", font, brush, new PointF(xPos, 10), format); #region QR Barcode font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold); g.DrawString("QR Barcode", font, brush, new PointF(10, 70)); PdfQRBarcode qrBarcode = new PdfQRBarcode(); // Sets the Input mode to Binary mode qrBarcode.InputMode = InputMode.BinaryMode; // Automatically select the Version qrBarcode.Version = QRCodeVersion.Auto; // Set the Error correction level to high qrBarcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.High; // Set dimension for each block qrBarcode.XDimension = 2; qrBarcode.Text = "Syncfusion Essential Studio Enterprise edition $995"; // Draw the QR barcode qrBarcode.Draw(page, new PointF(25, 100)); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular); g.DrawString("Input Type : Eight Bit Binary", font, brush, new PointF(250, 140)); g.DrawString("Encoded Data : Syncfusion Essential Studio Enterprise edition $995", font, brush, new PointF(250, 160)); g.DrawLine(pen, new PointF(0, 230), new PointF(width, 230)); #endregion #region Datamatrix font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold); g.DrawString("DataMatrix Barcode", font, brush, new PointF(10, 270)); PdfDataMatrixBarcode dataMatrixBarcode = new PdfDataMatrixBarcode("5575235 Win7 4GB 64bit 7Jun2010"); // Set dimension for each block dataMatrixBarcode.XDimension = 4; // Draw the barcode dataMatrixBarcode.Draw(page, new PointF(25, 310)); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular); g.DrawString("Symbol Type : Square", font, brush, new PointF(250, 360)); g.DrawString("Encoded Data : 5575235 Win7 4GB 64bit 7Jun2010", font, brush, new PointF(250, 380)); pen = new PdfPen(brush, 0.5f); g.DrawLine(pen, new PointF(0, 430), new PointF(width, 430)); string text = "TYPE 3523 - ETWS/N FE- SDFHW 06/08"; dataMatrixBarcode = new PdfDataMatrixBarcode(text); // rectangular matrix dataMatrixBarcode.Size = PdfDataMatrixSize.Size16x48; dataMatrixBarcode.XDimension = 4; dataMatrixBarcode.Draw(page, new PointF(25, 470)); g.DrawString("Symbol Type : Rectangle", font, brush, new PointF(250, 490)); g.DrawString("Encoded Data : " + text, font, brush, new PointF(250, 510)); pen = new PdfPen(brush, 0.5f); g.DrawLine(pen, new PointF(0, 570), new PointF(width, 570)); font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold); g.DrawString("PDF417 Barcode", font, brush, new PointF(10, 620)); Pdf417Barcode pdf417Barcode = new Pdf417Barcode(); pdf417Barcode.Text = "https://www.syncfusion.com/"; pdf417Barcode.ErrorCorrectionLevel = Pdf417ErrorCorrectionLevel.Auto; pdf417Barcode.XDimension = 1f; pdf417Barcode.Size = new SizeF(200, 50); pdf417Barcode.Draw(page, new PointF(25, 670)); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular); g.DrawString("Encoded Data : https://www.syncfusion.com/", font, brush, new PointF(250, 680)); #endregion # endregion # region 1D Barcode
private static void Create3DAnnotations(PdfFixedDocument document, PdfFont font, Stream u3dStream) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); page.Rotation = 90; page.Graphics.DrawString("3D annotations", font, blackBrush, 50, 50); byte[] u3dContent = new byte[u3dStream.Length]; u3dStream.Read(u3dContent, 0, u3dContent.Length); Pdf3DView view0 = new Pdf3DView(); view0.CameraToWorldMatrix = new double[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, -0.417542, -0.881257, -0.125705 }; view0.CenterOfOrbit = 0.123106; view0.ExternalName = "Default"; view0.InternalName = "Default"; view0.Projection = new Pdf3DProjection(); view0.Projection.FieldOfView = 30; Pdf3DView view1 = new Pdf3DView(); view1.CameraToWorldMatrix = new double[] { -0.999888, 0.014949, 0, 0.014949, 0.999887, 0.00157084, 0.0000234825, 0.00157066, -0.999999, -0.416654, -0.761122, -0.00184508 }; view1.CenterOfOrbit = 0.123106; view1.ExternalName = "Top"; view1.InternalName = "Top"; view1.Projection = new Pdf3DProjection(); view1.Projection.FieldOfView = 14.8096; Pdf3DView view2 = new Pdf3DView(); view2.CameraToWorldMatrix = new double[] { -1.0, -0.0000411671, 0.0000000000509201, -0.00000101387, 0.0246288, 0.999697, -0.0000411546, 0.999697, -0.0246288, -0.417072, -0.881787, -0.121915 }; view2.CenterOfOrbit = 0.123106; view2.ExternalName = "Side"; view2.InternalName = "Side"; view2.Projection = new Pdf3DProjection(); view2.Projection.FieldOfView = 12.3794; Pdf3DView view3 = new Pdf3DView(); view3.CameraToWorldMatrix = new double[] { -0.797002, -0.603977, -0.0000000438577, -0.294384, 0.388467, 0.873173, -0.527376, 0.695921, -0.48741, -0.3518, -0.844506, -0.0675629 }; view3.CenterOfOrbit = 0.123106; view3.ExternalName = "Isometric"; view3.InternalName = "Isometric"; view3.Projection = new Pdf3DProjection(); view3.Projection.FieldOfView = 15.1226; Pdf3DView view4 = new Pdf3DView(); view4.CameraToWorldMatrix = new double[] { 0.00737633, -0.999973, -0.0000000000147744, -0.0656414, -0.000484206, 0.997843, -0.997816, -0.00736042, -0.0656432, -0.293887, -0.757928, -0.119485 }; view4.CenterOfOrbit = 0.123106; view4.ExternalName = "Front"; view4.InternalName = "Front"; view4.Projection = new Pdf3DProjection(); view4.Projection.FieldOfView = 15.1226; Pdf3DView view5 = new Pdf3DView(); view5.CameraToWorldMatrix = new double[] { 0.0151008, 0.999886, 0.0000000000261366, 0.0492408, -0.000743662, 0.998787, 0.998673, -0.0150825, -0.0492464, -0.540019, -0.756862, -0.118884 }; view5.CenterOfOrbit = 0.123106; view5.ExternalName = "Back"; view5.InternalName = "Back"; view5.Projection = new Pdf3DProjection(); view5.Projection.FieldOfView = 12.3794; Pdf3DStream _3dStream = new Pdf3DStream(); _3dStream.Views.Add(view0); _3dStream.Views.Add(view1); _3dStream.Views.Add(view2); _3dStream.Views.Add(view3); _3dStream.Views.Add(view4); _3dStream.Views.Add(view5); _3dStream.Content = u3dContent; _3dStream.DefaultViewIndex = 0; Pdf3DAnnotation _3da = new Pdf3DAnnotation(); _3da.Stream = _3dStream; PdfAnnotationAppearance appearance = new PdfAnnotationAppearance(200, 200); appearance.Graphics.DrawString("Click to activate", font, blackBrush, 50, 50); _3da.NormalAppearance = appearance; page.Annotations.Add(_3da); _3da.VisualRectangle = new PdfVisualRectangle(36, 36, 720, 540); PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions(); sao.Font = font; sao.Brush = blackBrush; PdfStringLayoutOptions slo = new PdfStringLayoutOptions(); slo.Y = 585 + 18 / 2; slo.HorizontalAlign = PdfStringHorizontalAlign.Center; slo.VerticalAlign = PdfStringVerticalAlign.Middle; PdfPen blackPen = new PdfPen(new PdfRgbColor(0, 0, 0), 1); page.Graphics.DrawRectangle(blackPen, 50, 585, 120, 18); slo.X = 50 + 120 / 2; page.Graphics.DrawString("Top", sao, slo); PdfGoTo3DViewAction gotoTopView = new PdfGoTo3DViewAction(); gotoTopView.ViewIndex = 1; gotoTopView.TargetAnnotation = _3da; PdfLinkAnnotation linkGotoTopView = new PdfLinkAnnotation(); page.Annotations.Add(linkGotoTopView); linkGotoTopView.VisualRectangle = new PdfVisualRectangle(50, 585, 120, 18); linkGotoTopView.Action = gotoTopView; page.Graphics.DrawRectangle(blackPen, 190, 585, 120, 18); slo.X = 190 + 120 / 2; page.Graphics.DrawString("Side", sao, slo); PdfGoTo3DViewAction gotoSideView = new PdfGoTo3DViewAction(); gotoSideView.ViewIndex = 2; gotoSideView.TargetAnnotation = _3da; PdfLinkAnnotation linkGotoSideView = new PdfLinkAnnotation(); page.Annotations.Add(linkGotoSideView); linkGotoSideView.VisualRectangle = new PdfVisualRectangle(190, 585, 120, 18); linkGotoSideView.Action = gotoSideView; page.Graphics.DrawRectangle(blackPen, 330, 585, 120, 18); slo.X = 330 + 120 / 2; page.Graphics.DrawString("Isometric", sao, slo); PdfGoTo3DViewAction gotoIsometricView = new PdfGoTo3DViewAction(); gotoIsometricView.ViewIndex = 3; gotoIsometricView.TargetAnnotation = _3da; PdfLinkAnnotation linkGotoIsometricView = new PdfLinkAnnotation(); page.Annotations.Add(linkGotoIsometricView); linkGotoIsometricView.VisualRectangle = new PdfVisualRectangle(330, 585, 120, 18); linkGotoIsometricView.Action = gotoIsometricView; page.Graphics.DrawRectangle(blackPen, 470, 585, 120, 18); slo.X = 470 + 120 / 2; page.Graphics.DrawString("Front", sao, slo); PdfGoTo3DViewAction gotoFrontView = new PdfGoTo3DViewAction(); gotoFrontView.ViewIndex = 4; gotoFrontView.TargetAnnotation = _3da; PdfLinkAnnotation linkGotoFrontView = new PdfLinkAnnotation(); page.Annotations.Add(linkGotoFrontView); linkGotoFrontView.VisualRectangle = new PdfVisualRectangle(470, 585, 120, 18); linkGotoFrontView.Action = gotoFrontView; page.Graphics.DrawRectangle(blackPen, 610, 585, 120, 18); slo.X = 610 + 120 / 2; page.Graphics.DrawString("Back", sao, slo); PdfGoTo3DViewAction gotoBackView = new PdfGoTo3DViewAction(); gotoBackView.ViewIndex = 5; gotoBackView.TargetAnnotation = _3da; PdfLinkAnnotation linkGotoBackView = new PdfLinkAnnotation(); page.Annotations.Add(linkGotoBackView); linkGotoBackView.VisualRectangle = new PdfVisualRectangle(610, 585, 120, 18); linkGotoBackView.Action = gotoBackView; }
private static void CreateRichMediaAnnotations(PdfFixedDocument document, PdfFont font, Stream flashStream) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Rich media annotations", font, blackBrush, 50, 50); byte[] flashContent = new byte[flashStream.Length]; flashStream.Read(flashContent, 0, flashContent.Length); PdfRichMediaAnnotation rma = new PdfRichMediaAnnotation(); page.Annotations.Add(rma); rma.VisualRectangle = new PdfVisualRectangle(100, 100, 400, 400); rma.FlashPayload = flashContent; rma.FlashFile = "clock.swf"; rma.ActivationCondition = PdfRichMediaActivationCondition.PageVisible; }
private static void CreateInkAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); Random rnd = new Random(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Ink annotations", font, blackBrush, 50, 50); // The ink annotation will contain 3 lines, each one with 10 points. PdfPoint[][] points = new PdfPoint[3][]; for (int i = 0; i < points.Length; i++) { points[i] = new PdfPoint[10]; for (int j = 0; j < points[i].Length; j++) { points[i][j] = new PdfPoint(rnd.NextDouble() * page.Width, rnd.NextDouble() * page.Height); } } PdfInkAnnotation ia = new PdfInkAnnotation(); page.Annotations.Add(ia); ia.Contents = "I am an ink annotation."; ia.InkColor = new PdfRgbColor(255, 0, 255); ia.InkWidth = 5; ia.Points = points; }
/// <summary> /// Generates a PDF document that is encrypted using AES method. /// </summary> /// <param name="keySize">The encryption key size.</param> /// <param name="aes"></param> /// <returns></returns> private static PdfFixedDocument EncryptAES(int keySize, PdfAesSecurityHandler aes) { PdfFixedDocument doc = new PdfFixedDocument(); aes.EnableContentExtractionForAccessibility = false; aes.EnableDocumentAssembly = false; aes.EnableDocumentChange = false; aes.EnableContentExtraction = false; aes.EnableFormsFill = false; aes.EnableAnnotationsAndFieldsEdit = false; aes.EnablePrint = false; aes.EncryptMetadata = true; aes.KeySize = keySize; aes.UserPassword = "******"; aes.OwnerPassword = "******"; PdfPage page = doc.Pages.Add(); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBoldItalic, 16); PdfBrush blackBrush = new PdfBrush(); string text = string.Format("Encryption: AES {0} bit", keySize); if ((aes.KeySize == 256) && aes.UseEnhancedPasswordValidation) { text = text + " with enhanced password validation (Acrobat X or later)"; } page.Graphics.DrawString(text, helvetica, blackBrush, 50, 100); return doc; }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> //protected override void OnNavigatedTo(NavigationEventArgs e) //{ //} private async void Button_Click_1(object sender, RoutedEventArgs e) { Stream jpegImage = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Autumn Leaves.jpg"); Stream pngImage = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.syncfusion_logo.png"); #if STORE_SB Stream tiffImage = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.image.tif"); #else Stream tiffImage = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.image.tiff"); #endif Stream gifImage = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Ani.gif"); // Create a new instance of PdfDocument class. PdfDocument document = new PdfDocument(); // Set font. PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 22, PdfFontStyle.Bold); // Create brush. PdfBrush textBrush = PdfBrushes.DarkBlue; #region Jpeg image // Add a new section to the document. PdfSection section = document.Sections.Add(); // Add a new page to the newly created section. PdfPage page = section.Pages.Add(); PdfGraphics g = page.Graphics; g.DrawString("JPEG Image Drawing", font, textBrush, new PointF(10, 0)); //Drawing a jpeg image PdfImage image = new PdfBitmap(jpegImage); g.DrawImage(image, 0, 30); #endregion #region PNG Image page = section.Pages.Add(); g = page.Graphics; g.DrawString("PNG Image drawing", font, textBrush, new PointF(10, 0)); image = new PdfBitmap(pngImage); g.DrawImage(image, 0, 30); #endregion #region Multiframe Tiff PdfBitmap multiFrameImage = new PdfBitmap(tiffImage); int frameCount = multiFrameImage.FrameCount; for (int i = 0; i < frameCount; i++) { // Every frame in a new page. page = section.Pages.Add(); section.PageSettings.Margins.All = 0; g = page.Graphics; // Set the acive frame. multiFrameImage.ActiveFrame = i; // Draw active frame. g.DrawImage(multiFrameImage, 0, 0, page.Size.Width, page.Size.Height); if (i == 0) { #if STORE_SB g.DrawString("Tiff Image", font, textBrush, new PointF(10, 10)); #else g.DrawString("Multiframe Tiff Image", font, textBrush, new PointF(10, 10)); #endif } } #endregion #region Gif page = section.Pages.Add(); g = page.Graphics; // Draw gif image. image = new PdfBitmap(gifImage); g.DrawImage(image, 0, 0, g.ClientSize.Width, image.Height); g.DrawString("Gif Image", font, textBrush, new PointF(10, 0)); #endregion MemoryStream stream = new MemoryStream(); await document.SaveAsync(stream); document.Close(true); Save(stream, "Sample.pdf"); }
void OnButtonClicked(object sender, EventArgs e) { //Create new PDF document. PdfDocument document = new PdfDocument(); //Add page to the PDF document. PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; //Create font object. PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold); PdfBrush brush = PdfBrushes.Black; //Document security PdfSecurity security = document.Security; if (this.m_algorithms.SelectedItemPosition == 0) { security.Algorithm = PdfEncryptionAlgorithm.RC4; if (this.m_rc4Key.SelectedItemPosition == 0) { security.KeySize = PdfEncryptionKeySize.Key40Bit; } else if (this.m_rc4Key.SelectedItemPosition == 1) { security.KeySize = PdfEncryptionKeySize.Key128Bit; } } else if (this.m_algorithms.SelectedItemPosition == 1) { security.Algorithm = PdfEncryptionAlgorithm.AES; if (this.m_aesKey.SelectedItemPosition == 0) { security.KeySize = PdfEncryptionKeySize.Key128Bit; } else if (this.m_aesKey.SelectedItemPosition == 1) { security.KeySize = PdfEncryptionKeySize.Key256Bit; } else if (this.m_aesKey.SelectedItemPosition == 2) { security.KeySize = PdfEncryptionKeySize.Key256BitRevision6; } } security.OwnerPassword = "******"; security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint; security.UserPassword = "******"; string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" + "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm); if (this.m_algorithms.SelectedItemPosition == 1) { if (this.m_aesKey.SelectedItemPosition == 2) { text += String.Format("\n\nRevision: {0}", "Revision 6"); } else if (this.m_aesKey.SelectedItemPosition == 1) { text += String.Format("\n\nRevision: {0}", "Revision 5"); } } // Draw String. graphics.DrawString("Document is Encrypted with following settings", font, brush, Syncfusion.Drawing.PointF.Empty); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Bold); graphics.DrawString(text, font, brush, new Syncfusion.Drawing.PointF(0, 40)); MemoryStream stream = new MemoryStream(); //Save the PDF document. document.Save(stream); document.Close(); if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save("Securepdf.pdf", "application/pdf", stream, m_context); } }
void OnButtonClicked(object sender, EventArgs e) { //Create new PDF document. PdfDocument document = new PdfDocument(); //Add page to the PDF document. PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; //Create font object. PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold); PdfBrush brush = PdfBrushes.Black; //Document security PdfSecurity security = document.Security; if (this.m_algorithms.SelectedItemPosition == 0) { security.Algorithm = PdfEncryptionAlgorithm.RC4; if (this.m_rc4Key.SelectedItemPosition == 0) { security.KeySize = PdfEncryptionKeySize.Key40Bit; } else if (this.m_rc4Key.SelectedItemPosition == 1) { security.KeySize = PdfEncryptionKeySize.Key128Bit; } } else if (this.m_algorithms.SelectedItemPosition == 1) { security.Algorithm = PdfEncryptionAlgorithm.AES; if (this.m_aesKey.SelectedItemPosition == 0) { security.KeySize = PdfEncryptionKeySize.Key128Bit; } else if (this.m_aesKey.SelectedItemPosition == 1) { security.KeySize = PdfEncryptionKeySize.Key256Bit; } else if (this.m_aesKey.SelectedItemPosition == 2) { security.KeySize = PdfEncryptionKeySize.Key256BitRevision6; } } if (this.m_encryptionKey.SelectedItemPosition == 0) { security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents; } else if (this.m_encryptionKey.SelectedItemPosition == 1) { security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContentsExceptMetadata; } else if (this.m_encryptionKey.SelectedItemPosition == 2) { //Read the file Stream file = typeof(Encryption).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Products.xml"); //Creates an attachment PdfAttachment attachment = new PdfAttachment("Products.xml", file); attachment.ModificationDate = DateTime.Now; attachment.Description = "About Syncfusion"; attachment.MimeType = "application/txt"; //Adds the attachment to the document document.Attachments.Add(attachment); security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments; } security.OwnerPassword = "******"; security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint; security.UserPassword = "******"; string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" + "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm); if (this.m_algorithms.SelectedItemPosition == 1) { if (this.m_aesKey.SelectedItemPosition == 2) { text += String.Format("\n\nRevision: {0}", "Revision 6"); } else if (this.m_aesKey.SelectedItemPosition == 1) { text += String.Format("\n\nRevision: {0}", "Revision 5"); } } // Draw String. graphics.DrawString("Document is Encrypted with following settings", font, brush, Syncfusion.Drawing.PointF.Empty); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Bold); graphics.DrawString(text, font, brush, new Syncfusion.Drawing.PointF(0, 40)); MemoryStream stream = new MemoryStream(); //Save the PDF document. document.Save(stream); document.Close(); if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save("Securepdf.pdf", "application/pdf", stream, m_context); } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> //protected override void OnNavigatedTo(NavigationEventArgs e) //{ //} private async void Button_Click_1(object sender, RoutedEventArgs e) { PdfDocument document = new PdfDocument(); PdfPageBase page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); PdfBrush brush = PdfBrushes.Black; PdfForm form = document.Form; //Document security PdfSecurity security = document.Security; //Specify key size and encryption algorithm if (encryptionTechnique.SelectionBoxItem.ToString() == "40-Bit RC4") { //use 40 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key40Bit; security.Algorithm = PdfEncryptionAlgorithm.RC4; } else if (encryptionTechnique.SelectionBoxItem.ToString() == "128-Bit RC4") { //use 128 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key128Bit; security.Algorithm = PdfEncryptionAlgorithm.RC4; } else if (encryptionTechnique.SelectionBoxItem.ToString() == "128-Bit AES") { //use 128 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key128Bit; security.Algorithm = PdfEncryptionAlgorithm.AES; } else if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES") { //use 256 bits key in AES mode security.KeySize = PdfEncryptionKeySize.Key256Bit; security.Algorithm = PdfEncryptionAlgorithm.AES; } else if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES Revision 6") { //use 256 bits key in AES mode with Revision 6 security.KeySize = PdfEncryptionKeySize.Key256BitRevision6; security.Algorithm = PdfEncryptionAlgorithm.AES; } if (!cmbencryptOption.IsEnabled || cmbencryptOption.SelectedIndex == 0) { security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents; } else if (cmbencryptOption.SelectedIndex == 1) { security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContentsExceptMetadata; } else if (cmbencryptOption.SelectedIndex == 2) { //Read the file Stream imgStream = typeof(Encryption).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Products.xml"); PdfAttachment attachment = new PdfAttachment("Products.xml", imgStream); attachment.ModificationDate = DateTime.Now; attachment.Description = "About Syncfusion"; attachment.MimeType = "application/txt"; //Adds the attachment to the document document.Attachments.Add(attachment); security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments; } security.OwnerPassword = txtOwnerPassword.Password; security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint; security.UserPassword = txtUserPassword.Password; string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" + "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm); if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES Revision 6") { text += String.Format("\n\nRevision: {0}", "Revision6"); } else if (encryptionTechnique.SelectionBoxItem.ToString() == "256-Bit AES") { text += String.Format("\n\nRevision: {0}", "Revision5"); } graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16f, PdfFontStyle.Bold); graphics.DrawString(text, font, brush, new PointF(0, 40)); MemoryStream stream = new MemoryStream(); await document.SaveAsync(stream); document.Close(true); Save(stream, "FormFilling.pdf"); }
private void button1_Click(object sender, EventArgs e) { //Create a Pdf document PdfDocument doc = new PdfDocument(); //Add a page PdfPageBase page = doc.Pages.Add(); float y = 10; //Title PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold)); PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center); page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1); y = y + font1.MeasureString("Country List", format1).Height; y = y + 5; //Create a table PdfTable table = new PdfTable(); table.Style.BorderPen = new PdfPen(brush1, 0.5f); //Header style table.Style.HeaderSource = PdfHeaderSource.Rows; table.Style.HeaderRowCount = 1; table.Style.ShowHeader = true; table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue; table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 14f, FontStyle.Bold)); table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); //Repeat header table.Style.RepeatHeader = true; //Body style table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue; table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f)); table.Style.DefaultStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); table.Style.AlternateStyle = new PdfCellStyle(); table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightYellow; table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f)); table.Style.AlternateStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); table.DataSource = GetData(); //Set the Pdf table layout and specify the paginate bounds PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat(); tableLayout.Break = PdfLayoutBreakType.FitElement; tableLayout.Layout = PdfLayoutType.Paginate; tableLayout.PaginateBounds = new RectangleF(0, y, page.ActualSize.Width - 100, page.ActualSize.Height / 3); //Set the row height table.BeginRowLayout += new BeginRowLayoutEventHandler(table_BeginRowLayout); //Drow the table in page PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout); //Save the document string output = "InsertPageBreak_out.pdf"; doc.SaveToFile(output); doc.Close(); //Launch the Pdf file PDFDocumentViewer(output); }
private PdfPageBase DrawPages(PdfDocument doc) { //Set margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; //Create one page PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin); float y = 10; //Title PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold)); PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center); page.Canvas.DrawString("Part List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1); y = y + font1.MeasureString("Part List", format1).Height; y = y + 5; //Create data table PdfTable table = new PdfTable(); table.Style.CellPadding = 2; table.Style.BorderPen = new PdfPen(brush1, 0.75f); table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue; table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f)); table.Style.AlternateStyle = new PdfCellStyle(); table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightYellow; table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f)); table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions; table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue; table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold)); table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); table.Style.ShowHeader = true; using (OleDbConnection conn = new OleDbConnection()) { conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb"; OleDbCommand command = new OleDbCommand(); command.CommandText = " select Description, OnHand, OnOrder, Cost, ListPrice from parts "; command.Connection = conn; using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command)) { DataTable dataTable = new DataTable(); dataAdapter.Fill(dataTable); table.DataSourceType = PdfTableDataSourceType.TableDirect; table.DataSource = dataTable; } } float width = page.Canvas.ClientSize.Width - (table.Columns.Count + 1) * table.Style.BorderPen.Width; for (int i = 0; i < table.Columns.Count; i++) { if (i == 0) { table.Columns[i].Width = width * 0.40f * width; table.Columns[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); } else { table.Columns[i].Width = width * 0.15f * width; table.Columns[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); } } PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat(); tableLayout.Break = PdfLayoutBreakType.FitElement; tableLayout.Layout = PdfLayoutType.Paginate; PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout); y = result.Bounds.Bottom + 3; PdfBrush brush2 = PdfBrushes.Gray; PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f)); result.Page.Canvas.DrawString(String.Format("* {0} parts in the list.", table.Rows.Count), font2, brush2, 5, y); return(result.Page); }
public void AddRectangle(int x, int y, int w, int h, PdfBrush color) { m_grapics.DrawRectangle(color, x, y, w, h); }
/// <summary> /// Generates a PDF document that is encrypted using RC4 method. /// </summary> /// <param name="keySize">The encryption key size.</param> /// <param name="rc4"></param> /// <returns></returns> private static PdfFixedDocument EncryptRC4(int keySize, PdfRc4SecurityHandler rc4) { PdfFixedDocument doc = new PdfFixedDocument(); rc4.EnableContentExtractionForAccessibility = false; rc4.EnableDocumentAssembly = false; rc4.EnableDocumentChange = false; rc4.EnableContentExtraction = false; rc4.EnableFormsFill = false; rc4.EnableAnnotationsAndFieldsEdit = false; rc4.EnablePrint = false; rc4.EncryptMetadata = true; rc4.KeySize = keySize; rc4.UserPassword = "******"; rc4.OwnerPassword = "******"; PdfPage page = doc.Pages.Add(); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBoldItalic, 16); PdfBrush blackBrush = new PdfBrush(); page.Graphics.DrawString(string.Format("Encryption: RC4 {0} bit", keySize), helvetica, blackBrush, 50, 100); return doc; }
private void DrawPage(PdfPageBase page) { float pageWidth = page.Canvas.ClientSize.Width; float y = 0; //Title y = y + 5; PdfBrush brush2 = new PdfSolidBrush(Color.Black); PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold)); PdfStringFormat format2 = new PdfStringFormat(PdfTextAlignment.Center); format2.CharacterSpacing = 1f; String text = "Summary of Science"; page.Canvas.DrawString(text, font2, brush2, pageWidth / 2, y, format2); SizeF size = font2.MeasureString(text, format2); y = y + size.Height + 6; //Icon PdfImage image = PdfImage.FromFile(@"..\\..\\..\\..\\..\\..\\Data\\Wikipedia_Science.png"); page.Canvas.DrawImage(image, new PointF(pageWidth - image.PhysicalDimension.Width, y)); float imageLeftSpace = pageWidth - image.PhysicalDimension.Width - 2; float imageBottom = image.PhysicalDimension.Height + y; //Reference content PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 9f)); PdfStringFormat format3 = new PdfStringFormat(); format3.ParagraphIndent = font3.Size * 2; format3.MeasureTrailingSpaces = true; format3.LineSpacing = font3.Size * 1.5f; String text1 = "(All text and picture from "; String text2 = "Wikipedia"; String text3 = ", the free encyclopedia)"; page.Canvas.DrawString(text1, font3, brush2, 0, y, format3); size = font3.MeasureString(text1, format3); float x1 = size.Width; format3.ParagraphIndent = 0; PdfTrueTypeFont font4 = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Underline)); PdfBrush brush3 = PdfBrushes.Blue; page.Canvas.DrawString(text2, font4, brush3, x1, y, format3); size = font4.MeasureString(text2, format3); x1 = x1 + size.Width; page.Canvas.DrawString(text3, font3, brush2, x1, y, format3); y = y + size.Height; //Content PdfStringFormat format4 = new PdfStringFormat(); text = System.IO.File.ReadAllText(@"..\\..\\..\\..\\..\\..\\Data\\Summary_of_Science.txt"); PdfTrueTypeFont font5 = new PdfTrueTypeFont(new Font("Arial", 10f)); format4.LineSpacing = font5.Size * 1.5f; PdfStringLayouter textLayouter = new PdfStringLayouter(); float imageLeftBlockHeight = imageBottom - y; PdfStringLayoutResult result = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight)); if (result.ActualSize.Height < imageBottom - y) { imageLeftBlockHeight = imageLeftBlockHeight + result.LineHeight; result = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight)); } foreach (LineInfo line in result.Lines) { page.Canvas.DrawString(line.Text, font5, brush2, 0, y, format4); y = y + result.LineHeight; } PdfTextWidget textWidget = new PdfTextWidget(result.Remainder, font5, brush2); PdfTextLayout textLayout = new PdfTextLayout(); textLayout.Break = PdfLayoutBreakType.FitPage; textLayout.Layout = PdfLayoutType.Paginate; RectangleF bounds = new RectangleF(new PointF(0, y), page.Canvas.ClientSize); textWidget.StringFormat = format4; textWidget.Draw(page, bounds, textLayout); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); PdfPage page = document.Pages.Add(); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 20); PdfBrush blackBrush = new PdfBrush(PdfRgbColor.Black); page.Graphics.DrawString("The digits below, from 0 to 9, are drawn using a Type3 font.", helvetica, blackBrush, 50, 100); PdfType3Font t3 = new PdfType3Font("DemoT3"); t3.Size = 24; t3.FirstChar = (byte)' '; t3.LastChar = (byte)'9'; t3.FontMatrix = new PdfMatrix(0.01, 0, 0, 0.01, 0, 0); double[] widths = new double[] { 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100 }; t3.Widths = widths; PdfPen hollowPen = new PdfPen(null, 8); PdfBrush hollowBrush = new PdfBrush(null); // space PdfType3Glyph t3s = new PdfType3Glyph(0x20, new PdfSize(100, 100)); t3.Glyphs.Add(t3s); // 0 PdfType3Glyph t30 = new PdfType3Glyph(0x30, new PdfSize(100, 100)); t30.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90); t30.Graphics.CompressAndClose(); t3.Glyphs.Add(t30); // 1 PdfType3Glyph t31 = new PdfType3Glyph(0x31, new PdfSize(100, 100)); t31.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90); t31.Graphics.DrawEllipse(hollowBrush, 40, 40, 20, 20); t31.Graphics.CompressAndClose(); t3.Glyphs.Add(t31); // 2 PdfType3Glyph t32 = new PdfType3Glyph(0x32, new PdfSize(100, 100)); t32.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90); t32.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20); t32.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20); t32.Graphics.CompressAndClose(); t3.Glyphs.Add(t32); // 3 PdfType3Glyph t33 = new PdfType3Glyph(0x33, new PdfSize(100, 100)); t33.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90); t33.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20); t33.Graphics.DrawEllipse(hollowBrush, 40, 40, 20, 20); t33.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20); t33.Graphics.CompressAndClose(); t3.Glyphs.Add(t33); // 4 PdfType3Glyph t34 = new PdfType3Glyph(0x34, new PdfSize(100, 100)); t34.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90); t34.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20); t34.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20); t34.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20); t34.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20); t34.Graphics.CompressAndClose(); t3.Glyphs.Add(t34); // 5 PdfType3Glyph t35 = new PdfType3Glyph(0x35, new PdfSize(100, 100)); t35.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90); t35.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20); t35.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20); t35.Graphics.DrawEllipse(hollowBrush, 40, 40, 20, 20); t35.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20); t35.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20); t35.Graphics.CompressAndClose(); t3.Glyphs.Add(t35); // 6 PdfType3Glyph t36 = new PdfType3Glyph(0x36, new PdfSize(100, 100)); t36.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90); t36.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20); t36.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20); t36.Graphics.DrawEllipse(hollowBrush, 15, 40, 20, 20); t36.Graphics.DrawEllipse(hollowBrush, 65, 40, 20, 20); t36.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20); t36.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20); t36.Graphics.CompressAndClose(); t3.Glyphs.Add(t36); // 7 PdfType3Glyph t37 = new PdfType3Glyph(0x37, new PdfSize(100, 100)); t37.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90); t37.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20); t37.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20); t37.Graphics.DrawEllipse(hollowBrush, 15, 40, 20, 20); t37.Graphics.DrawEllipse(hollowBrush, 40, 40, 20, 20); t37.Graphics.DrawEllipse(hollowBrush, 65, 40, 20, 20); t37.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20); t37.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20); t37.Graphics.CompressAndClose(); t3.Glyphs.Add(t37); // 8 PdfType3Glyph t38 = new PdfType3Glyph(0x38, new PdfSize(100, 100)); t38.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90); t38.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20); t38.Graphics.DrawEllipse(hollowBrush, 40, 15, 20, 20); t38.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20); t38.Graphics.DrawEllipse(hollowBrush, 15, 40, 20, 20); t38.Graphics.DrawEllipse(hollowBrush, 65, 40, 20, 20); t38.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20); t38.Graphics.DrawEllipse(hollowBrush, 40, 65, 20, 20); t38.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20); t38.Graphics.CompressAndClose(); t3.Glyphs.Add(t38); // 9 PdfType3Glyph t39 = new PdfType3Glyph(0x39, new PdfSize(100, 100)); t39.Graphics.DrawRectangle(hollowPen, 5, 5, 90, 90); t39.Graphics.DrawEllipse(hollowBrush, 15, 15, 20, 20); t39.Graphics.DrawEllipse(hollowBrush, 40, 15, 20, 20); t39.Graphics.DrawEllipse(hollowBrush, 65, 15, 20, 20); t39.Graphics.DrawEllipse(hollowBrush, 15, 40, 20, 20); t39.Graphics.DrawEllipse(hollowBrush, 40, 40, 20, 20); t39.Graphics.DrawEllipse(hollowBrush, 65, 40, 20, 20); t39.Graphics.DrawEllipse(hollowBrush, 15, 65, 20, 20); t39.Graphics.DrawEllipse(hollowBrush, 40, 65, 20, 20); t39.Graphics.DrawEllipse(hollowBrush, 65, 65, 20, 20); t39.Graphics.CompressAndClose(); t3.Glyphs.Add(t39); PdfBrush paleVioletRedbrush = new PdfBrush(PdfRgbColor.PaleVioletRed); page.Graphics.DrawString("0 1 2 3 4 5 6 7 8 9", t3, paleVioletRedbrush, 50, 150); PdfBrush midnightBluebrush = new PdfBrush(PdfRgbColor.MidnightBlue); page.Graphics.DrawString("0 1 2 3 4 5 6 7 8 9", t3, midnightBluebrush, 50, 200); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.type3fonts.pdf") }; return output; }
private async void BarcodeSample() { MemoryStream stream = new MemoryStream(); //Create a new instance of PdfDocument class. using (PdfDocument document = new PdfDocument()) { //Add a new page to the document. PdfPage page = document.Pages.Add(); //Create Pdf graphics for the page PdfGraphics g = page.Graphics; //Create a solid brush PdfBrush brush = PdfBrushes.Black; #region 2D Barcode //Set the font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 15f, PdfFontStyle.Bold); PdfPen pen = new PdfPen(brush, 0.5f); float width = page.GetClientSize().Width; float xPos = page.GetClientSize().Width / 2; PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; // Draw String g.DrawString("2D Barcodes", font, brush, new PointF(xPos, 10), format); #region QR Barcode font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold); g.DrawString("QR Barcode", font, brush, new PointF(10, 90)); //Create QR barcode PdfQRBarcode qrBarcode = new PdfQRBarcode(); //Set input mode qrBarcode.InputMode = InputMode.BinaryMode; //Set error correction level qrBarcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.High; //Set dimension qrBarcode.XDimension = 4; //Add data qrBarcode.Text = "Syncfusion Essential Studio Enterprise edition $995"; //Draw barcode on Pdf page qrBarcode.Draw(page, new PointF(25, 120)); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular); g.DrawString("Input Type : Eight Bit Binary", font, brush, new PointF(250, 160)); g.DrawString("Encoded Data : Syncfusion Essential Studio Enterprise edition $995", font, brush, new PointF(250, 180)); g.DrawLine(pen, new PointF(0, 320), new PointF(width, 320)); #endregion #region Datamatrix font = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold); g.DrawString("DataMatrix Barcode", font, brush, new PointF(10, 340)); PdfDataMatrixBarcode dataMatrixBarcode = new PdfDataMatrixBarcode("5575235 Win7 4GB 64bit 7Jun2010"); // Set dimension for each block dataMatrixBarcode.XDimension = 4; // Draw the barcode dataMatrixBarcode.Draw(page, new PointF(25, 540)); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular); g.DrawString("Symbol Type : Square", font, brush, new PointF(250, 590)); g.DrawString("Encoded Data : 5575235 Win7 4GB 64bit 7Jun2010", font, brush, new PointF(250, 610)); pen = new PdfPen(brush, 0.5f); g.DrawLine(pen, new PointF(0, 700), new PointF(width, 700)); string text = "TYPE 3523 - ETWS/N FE- SDFHW 06/08"; dataMatrixBarcode = new PdfDataMatrixBarcode(text); // rectangular matrix dataMatrixBarcode.Size = PdfDataMatrixSize.Size16x48; dataMatrixBarcode.XDimension = 4; dataMatrixBarcode.Draw(page, new PointF(25, 400)); g.DrawString("Symbol Type : Rectangle", font, brush, new PointF(250, 420)); g.DrawString("Encoded Data : " + text, font, brush, new PointF(250, 440)); pen = new PdfPen(brush, 0.5f); #endregion #endregion page = document.Pages.Add(); g = page.Graphics; //Set the font font = new PdfStandardFont(PdfFontFamily.Helvetica, 15f, PdfFontStyle.Bold); // Draw String g.DrawString("1D/Linear Barcodes", font, brush, new PointF(150, 10)); // Set string format. format = new PdfStringFormat(); format.WordWrap = PdfWordWrapType.Word; #region Code39 // Drawing Code39 barcode PdfCode39Barcode barcode = new PdfCode39Barcode(); // Setting height of the barcode barcode.BarHeight = 45; barcode.Text = "CODE39$"; //Printing barcode on to the Pdf. barcode.Draw(page, new PointF(25, 70)); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular); g.DrawString("Type : Code39", font, brush, new PointF(200, 80)); g.DrawString("Allowed Characters : 0-9, A-Z,a dash(-),a dot(.),$,/,+,%, SPACE", font, brush, new PointF(200, 100)); g.DrawLine(pen, new PointF(0, 150), new PointF(width, 150)); #endregion #region Code39Extended // Drawing Code39Extended barcode PdfCode39ExtendedBarcode barcodeExt = new PdfCode39ExtendedBarcode(); // Setting height of the barcode barcodeExt.BarHeight = 45; barcodeExt.Text = "CODE39Ext"; //Printing barcode on to the Pdf. barcodeExt.Draw(page, new PointF(25, 200)); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular); g.DrawString("Type : Code39Ext", font, brush, new PointF(200, 210)); g.DrawString("Allowed Characters : 0-9 A-Z a-z ", font, brush, new PointF(200, 230)); g.DrawLine(pen, new PointF(0, 270), new PointF(width, 270)); #endregion #region Code11Barcode // Drawing Code11 barcode PdfCode11Barcode barcode11 = new PdfCode11Barcode(); // Setting height of the barcode barcode11.BarHeight = 45; barcode11.Text = "012345678"; barcode11.EncodeStartStopSymbols = true; //Printing barcode on to the Pdf. barcode11.Draw(page, new PointF(25, 300)); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular); g.DrawString("Type : Code 11", font, brush, new PointF(200, 310)); g.DrawString("Allowed Characters : 0-9, a dash(-) ", font, brush, new PointF(200, 330)); g.DrawLine(pen, new PointF(0, 370), new PointF(width, 370)); #endregion #region Codabar // Drawing CodaBarcode PdfCodabarBarcode codabar = new PdfCodabarBarcode(); // Setting height of the barcode codabar.BarHeight = 45; codabar.Text = "0123"; //Printing barcode on to the Pdf. codabar.Draw(page, new PointF(25, 400)); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 9, PdfFontStyle.Regular); g.DrawString("Type : Codabar", font, brush, new PointF(200, 410)); g.DrawString("Allowed Characters : A,B,C,D,0-9,-$,:,/,a dot(.),+ ", font, brush, new PointF(200, 430)); g.DrawLine(pen, new PointF(0, 470), new PointF(width, 470)); #endregion #region Code32 PdfCode32Barcode code32 = new PdfCode32Barcode(); code32.Font = font; // Setting height of the barcode code32.BarHeight = 45; code32.Text = "01234567"; code32.TextDisplayLocation = TextLocation.Bottom; code32.EnableCheckDigit = true; code32.ShowCheckDigit = true; //Printing barcode on to the Pdf. code32.Draw(page, new PointF(25, 500)); g.DrawString("Type : Code32", font, brush, new PointF(200, 500)); g.DrawString("Allowed Characters : 1 2 3 4 5 6 7 8 9 0 ", font, brush, new PointF(200, 520)); g.DrawLine(pen, new PointF(0, 580), new PointF(width, 580)); #endregion #region Code93 PdfCode93Barcode code93 = new PdfCode93Barcode(); // Setting height of the barcode code93.BarHeight = 45; code93.Text = "ABC 123456789"; //Printing barcode on to the Pdf. code93.Draw(page, new PointF(25, 600)); g.DrawString("Type : Code93", font, brush, new PointF(200, 600)); g.DrawString("Allowed Characters : 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - . $ / + % SPACE ", font, brush, new RectangleF(200, 620, 300, 200), format); g.DrawLine(pen, new PointF(0, 680), new PointF(width, 680)); #endregion #region Code93Extended PdfCode93ExtendedBarcode code93ext = new PdfCode93ExtendedBarcode(); //Setting height of the barcode code93ext.BarHeight = 45; code93ext.EncodeStartStopSymbols = true; code93ext.Text = "(abc) 123456789"; //Printing barcode on to the Pdf. page = document.Pages.Add(); code93ext.Draw(page, new PointF(25, 50)); g = page.Graphics; g.DrawString("Type : Code93 Extended", font, brush, new PointF(200, 50)); g.DrawString("Allowed Characters : All 128 ASCII characters ", font, brush, new PointF(200, 70)); g.DrawLine(pen, new PointF(0, 120), new PointF(width, 120)); #endregion #region Code128 PdfCode128ABarcode barcode128A = new PdfCode128ABarcode(); // Setting height of the barcode barcode128A.BarHeight = 45; barcode128A.Text = "ABCD 12345"; barcode128A.EnableCheckDigit = true; barcode128A.EncodeStartStopSymbols = true; barcode128A.ShowCheckDigit = true; //Printing barcode on to the Pdf. barcode128A.Draw(page, new PointF(25, 135)); g.DrawString("Type : Code128 A", font, brush, new PointF(200, 135)); g.DrawString("Allowed Characters : NUL (0x00) SOH (0x01) STX (0x02) ETX (0x03) EOT (0x04) ENQ (0x05) ACK (0x06) BEL (0x07) BS (0x08) HT (0x09) LF (0x0A) VT (0x0B) FF (0x0C) CR (0x0D) SO (0x0E) SI (0x0F) DLE (0x10) DC1 (0x11) DC2 (0x12) DC3 (0x13) DC4 (0x14) NAK (0x15) SYN (0x16) ETB (0x17) CAN (0x18) EM (0x19) SUB (0x1A) ESC (0x1B) FS (0x1C) GS (0x1D) RS (0x1E) US (0x1F) SPACE (0x20) \" ! # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ / ]^ _ ", font, brush, new RectangleF(200, 155, 300, 200), format); g.DrawLine(pen, new PointF(0, 250), new PointF(width, 250)); PdfCode128BBarcode barcode128B = new PdfCode128BBarcode(); // Setting height of the barcode barcode128B.BarHeight = 45; barcode128B.Text = "12345 abcd"; barcode128B.EnableCheckDigit = true; barcode128B.EncodeStartStopSymbols = true; barcode128B.ShowCheckDigit = true; //Printing barcode on to the Pdf. barcode128B.Draw(page, new PointF(25, 280)); g.DrawString("Type : Code128 B", font, brush, new PointF(200, 280)); g.DrawString("Allowed Characters : SPACE (0x20) ! \" # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ / ]^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ DEL (\x7F) ", font, brush, new RectangleF(200, 300, 300, 200), format); g.DrawLine(pen, new PointF(0, 350), new PointF(width, 350)); PdfCode128CBarcode barcode128C = new PdfCode128CBarcode(); // Setting height of the barcode barcode128C.BarHeight = 45; barcode128C.Text = "001122334455"; barcode128C.EnableCheckDigit = true; barcode128C.EncodeStartStopSymbols = true; barcode128C.ShowCheckDigit = true; //Printing barcode on to the Pdf. barcode128C.Draw(page, new PointF(25, 370)); g.DrawString("Type : Code128 C", font, brush, new PointF(200, 370)); g.DrawString("Allowed Characters : 0 1 2 3 4 5 6 7 8 9 ", font, brush, new PointF(200, 390)); g.DrawLine(pen, new PointF(0, 440), new PointF(width, 440)); #endregion //Save the PDF document document.Save(stream); } stream.Position = 0; if (IsToggled) { PdfViewerUI pdfViewer = new SampleBrowser.PdfViewerUI(); pdfViewer.PdfDocumentStream = stream; if (Device.Idiom != TargetIdiom.Phone && Device.OS == TargetPlatform.Windows) { await PDFViewModel.Navigation.PushModalAsync(new NavigationPage(pdfViewer)); } else { await PDFViewModel.Navigation.PushAsync(pdfViewer); } } else { if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Barcode.pdf", "application/pdf", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("Barcode.pdf", "application/pdf", stream); } } }
private static void CreatePolylineAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Polyline annotations", font, blackBrush, 50, 50); int[] vertices = new int[] { 3, 4, 5, 6 }; double centerY = 125, centerX = 150; double radius = 50; for (int i = 0; i < vertices.Length; i++) { PdfPoint[] points = new PdfPoint[vertices[i]]; double angle = 90; double rotation = 360 / vertices[i]; for (int j = 0; j < vertices[i]; j++) { points[j] = new PdfPoint(); points[j].X = centerX + radius * Math.Cos(Math.PI * angle / 180); points[j].Y = centerY - radius * Math.Sin(Math.PI * angle / 180); angle = angle + rotation; } PdfPolylineAnnotation polyline = new PdfPolylineAnnotation(); page.Annotations.Add(polyline); polyline.Author = "Xfinium.Pdf"; polyline.Contents = "Polyline annotation with " + vertices[i] + " vertices."; polyline.Points = points; polyline.LineColor = new PdfRgbColor(192, 0, 0); polyline.LineWidth = 3; centerY = centerY + 150; } }
public ActionResult Encryption(string InsideBrowser, string encryptionType) { PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold); PdfBrush brush = PdfBrushes.Black; PdfForm form = document.Form; //Document security PdfSecurity security = document.Security; //Specify key size and encryption algorithm if (encryptionType == "40_RC4") { //use 40 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key40Bit; } else if (encryptionType == "128_RC4") { //use 128 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key128Bit; security.Algorithm = PdfEncryptionAlgorithm.RC4; } else if (encryptionType == "128_AES") { //use 128 bits key in AES mode security.KeySize = PdfEncryptionKeySize.Key128Bit; security.Algorithm = PdfEncryptionAlgorithm.AES; } else if (encryptionType == "256_AES") { //use 256 bits key in AES mode security.KeySize = PdfEncryptionKeySize.Key256Bit; security.Algorithm = PdfEncryptionAlgorithm.AES; } else if (encryptionType == "256_AES_Revision_6") { security.KeySize = PdfEncryptionKeySize.Key256BitRevision6; security.Algorithm = PdfEncryptionAlgorithm.AES; } security.OwnerPassword = "******"; security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint; security.UserPassword = "******"; string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" + "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm); if (encryptionType == "256_AES_Revision_6") { text += String.Format("\n\nRevision: {0}", "Revision 6"); } else if (encryptionType == "256_AES") { text += String.Format("\n\nRevision: {0}", "Revision 5"); } graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Bold); graphics.DrawString(text, font, brush, new PointF(0, 40)); //Stream the output to the browser. if (InsideBrowser == "Browser") { return(document.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(document.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
private static void CreateSquareCircleAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Square annotations", font, blackBrush, 50, 50); PdfSquareAnnotation square1 = new PdfSquareAnnotation(); page.Annotations.Add(square1); square1.Author = "Xfinium.pdf"; square1.Contents = "Square annotation with red border"; square1.BorderColor = new PdfRgbColor(255, 0, 0); square1.BorderWidth = 3; square1.VisualRectangle = new PdfVisualRectangle(50, 70, 250, 150); PdfSquareAnnotation square2 = new PdfSquareAnnotation(); page.Annotations.Add(square2); square2.Author = "Xfinium.pdf"; square2.Contents = "Square annotation with blue interior"; square2.BorderColor = null; square2.BorderWidth = 0; square2.InteriorColor = new PdfRgbColor(0, 0, 192); square2.VisualRectangle = new PdfVisualRectangle(50, 270, 250, 150); PdfSquareAnnotation square3 = new PdfSquareAnnotation(); page.Annotations.Add(square3); square3.Author = "Xfinium.pdf"; square3.Contents = "Square annotation with yellow border and green interior"; square3.BorderColor = new PdfRgbColor(255, 255, 0); square3.BorderWidth = 3; square3.InteriorColor = new PdfRgbColor(0, 192, 0); square3.VisualRectangle = new PdfVisualRectangle(50, 470, 250, 150); page.Graphics.DrawString("Circle annotations", font, blackBrush, 50, 350); PdfCircleAnnotation circle1 = new PdfCircleAnnotation(); page.Annotations.Add(circle1); circle1.Author = "Xfinium.pdf"; circle1.Contents = "Circle annotation with red border"; circle1.BorderColor = new PdfRgbColor(255, 0, 0); circle1.BorderWidth = 3; circle1.VisualRectangle = new PdfVisualRectangle(350, 70, 250, 150); PdfCircleAnnotation circle2 = new PdfCircleAnnotation(); page.Annotations.Add(circle2); circle2.Author = "Xfinium.pdf"; circle2.Contents = "Circle annotation with blue interior"; circle2.BorderColor = null; circle2.BorderWidth = 0; circle2.InteriorColor = new PdfRgbColor(0, 0, 192); circle2.VisualRectangle = new PdfVisualRectangle(350, 270, 250, 150); PdfCircleAnnotation circle3 = new PdfCircleAnnotation(); page.Annotations.Add(circle3); circle3.Author = "Xfinium.pdf"; circle3.Contents = "Circle annotation with yellow border and green interior"; circle3.BorderColor = new PdfRgbColor(255, 255, 0); circle3.BorderWidth = 3; circle3.InteriorColor = new PdfRgbColor(0, 192, 0); circle3.VisualRectangle = new PdfVisualRectangle(350, 470, 250, 150); }
public PdfLayoutResult AddRectangleText(string leftText, string rightText, float y, float height, PdfBrush rectangleBrush = null, PdfBrush textBrush = null, PdfFont font = null) { rectangleBrush = rectangleBrush ?? AccentBrush; textBrush = textBrush ?? PdfBrushes.White; font = font ?? SubHeadingFont; DrawRectangle(0, y, PageWidth, height, rectangleBrush); y += 5; PdfLayoutResult result = AddText(leftText, 10, y, font, textBrush); AddText(rightText, 10, result.Bounds.Y, font, textBrush, true); return(result); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); document.OptionalContentProperties = new PdfOptionalContentProperties(); PdfStandardFont helveticaBold = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 18); PdfBrush blackBrush = new PdfBrush(); PdfBrush greenBrush = new PdfBrush(PdfRgbColor.DarkGreen); PdfBrush yellowBrush = new PdfBrush(PdfRgbColor.Yellow); PdfPen bluePen = new PdfPen(PdfRgbColor.DarkBlue, 5); PdfPen redPen = new PdfPen(PdfRgbColor.DarkRed, 5); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Simple optional content: the green rectangle", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage1 = new PdfOptionalContentGroup(); ocgPage1.Name = "Page 1 - Green Rectangle"; page.Graphics.BeginOptionalContentGroup(ocgPage1); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 100, 570, 400); page.Graphics.EndOptionalContentGroup(); page = document.Pages.Add(); page.Graphics.DrawString("Multipart optional content: the green rectangles", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage2 = new PdfOptionalContentGroup(); ocgPage2.Name = "Page 2 - Green Rectangles"; page.Graphics.BeginOptionalContentGroup(ocgPage2); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200); page.Graphics.EndOptionalContentGroup(); page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680); page.Graphics.BeginOptionalContentGroup(ocgPage2); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200); page.Graphics.EndOptionalContentGroup(); page = document.Pages.Add(); page.Graphics.DrawString("Imbricated optional content: the green and yellow rectangles", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage31 = new PdfOptionalContentGroup(); ocgPage31.Name = "Page 3 - Green Rectangle"; page.Graphics.BeginOptionalContentGroup(ocgPage31); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 100, 570, 600); PdfOptionalContentGroup ocgPage32 = new PdfOptionalContentGroup(); ocgPage32.Name = "Page 3 - Yellow Rectangle"; page.Graphics.BeginOptionalContentGroup(ocgPage32); page.Graphics.DrawRectangle(redPen, yellowBrush, 100, 200, 400, 300); page.Graphics.EndOptionalContentGroup(); // ocgPage32 page.Graphics.EndOptionalContentGroup(); // ocgPage31 page = document.Pages.Add(); page.Graphics.DrawString("Multipage optional content: the green rectangles on page 4 & 5", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage45 = new PdfOptionalContentGroup(); ocgPage45.Name = "Page 4 & 5 - Green Rectangles"; page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200); page.Graphics.EndOptionalContentGroup(); page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680); page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200); page.Graphics.EndOptionalContentGroup(); page = document.Pages.Add(); page.Graphics.DrawString("Multipage optional content: continued", helveticaBold, blackBrush, 20, 50); page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200); page.Graphics.EndOptionalContentGroup(); page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680); page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200); page.Graphics.EndOptionalContentGroup(); // Build the display tree for the optional content, // how its structure and relationships between optional content groups are presented to the user. PdfOptionalContentDisplayTreeNode ocgPage1Node = new PdfOptionalContentDisplayTreeNode(ocgPage1); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage1Node); PdfOptionalContentDisplayTreeNode ocgPage2Node = new PdfOptionalContentDisplayTreeNode(ocgPage2); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage2Node); PdfOptionalContentDisplayTreeNode ocgPage31Node = new PdfOptionalContentDisplayTreeNode(ocgPage31); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage31Node); PdfOptionalContentDisplayTreeNode ocgPage32Node = new PdfOptionalContentDisplayTreeNode(ocgPage32); ocgPage31Node.Nodes.Add(ocgPage32Node); PdfOptionalContentDisplayTreeNode ocgPage45Node = new PdfOptionalContentDisplayTreeNode(ocgPage45); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage45Node); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.optionalcontent.pdf") }; return output; }
public PdfLayoutResult AddText(string text, float x, float y, PdfFont font = null, PdfBrush brush = null, bool xIsRightOffset = false, float?forceTextSize = null) { font = font ?? NormalFont; brush = brush ?? AccentBrush; if (xIsRightOffset) { SizeF textSize = font.MeasureString(text); float textWidth = forceTextSize ?? textSize.Width; x = PageWidth - textWidth - x; } PdfTextElement element = new PdfTextElement(text, font, brush); PdfLayoutResult result = element.Draw(CurrentPage, new PointF(x, y)); return(result); }
private static void DrawShadings(PdfPage page, PdfFont titleFont, PdfFont sectionFont) { PdfBrush brush = new PdfBrush(); PdfPen blackPen = new PdfPen(PdfRgbColor.Black, 1); PdfRgbColor randomPenColor = new PdfRgbColor(); PdfPen randomPen = new PdfPen(randomPenColor, 1); PdfRgbColor randomBrushColor = new PdfRgbColor(); PdfBrush randomBrush = new PdfBrush(randomBrushColor); page.Graphics.DrawString("Shadings", titleFont, brush, 20, 50); page.Graphics.DrawString("Horizontal", sectionFont, brush, 25, 70); PdfAxialShading horizontalShading = new PdfAxialShading(); horizontalShading.StartColor = new PdfRgbColor(255, 0, 0); horizontalShading.EndColor = new PdfRgbColor(0, 0, 255); horizontalShading.StartPoint = new PdfPoint(25, 90); horizontalShading.EndPoint = new PdfPoint(175, 90); // Clip the shading to desired area. PdfPath hsArea = new PdfPath(); hsArea.AddRectangle(25, 90, 150, 150); page.Graphics.SaveGraphicsState(); page.Graphics.SetClip(hsArea); page.Graphics.DrawShading(horizontalShading); page.Graphics.RestoreGraphicsState(); page.Graphics.DrawString("Vertical", sectionFont, brush, 225, 70); PdfAxialShading verticalShading = new PdfAxialShading(); verticalShading.StartColor = new PdfRgbColor(255, 0, 0); verticalShading.EndColor = new PdfRgbColor(0, 0, 255); verticalShading.StartPoint = new PdfPoint(225, 90); verticalShading.EndPoint = new PdfPoint(225, 240); // Clip the shading to desired area. PdfPath vsArea = new PdfPath(); vsArea.AddRectangle(225, 90, 150, 150); page.Graphics.SaveGraphicsState(); page.Graphics.SetClip(vsArea); page.Graphics.DrawShading(verticalShading); page.Graphics.RestoreGraphicsState(); page.Graphics.DrawString("Diagonal", sectionFont, brush, 425, 70); PdfAxialShading diagonalShading = new PdfAxialShading(); diagonalShading.StartColor = new PdfRgbColor(255, 0, 0); diagonalShading.EndColor = new PdfRgbColor(0, 0, 255); diagonalShading.StartPoint = new PdfPoint(425, 90); diagonalShading.EndPoint = new PdfPoint(575, 240); // Clip the shading to desired area. PdfPath dsArea = new PdfPath(); dsArea.AddRectangle(425, 90, 150, 150); page.Graphics.SaveGraphicsState(); page.Graphics.SetClip(dsArea); page.Graphics.DrawShading(diagonalShading); page.Graphics.RestoreGraphicsState(); page.Graphics.DrawString("Extended shading", sectionFont, brush, 25, 260); PdfAxialShading extendedShading = new PdfAxialShading(); extendedShading.StartColor = new PdfRgbColor(255, 0, 0); extendedShading.EndColor = new PdfRgbColor(0, 0, 255); extendedShading.StartPoint = new PdfPoint(225, 280); extendedShading.EndPoint = new PdfPoint(375, 280); extendedShading.ExtendStart = true; extendedShading.ExtendEnd = true; // Clip the shading to desired area. PdfPath esArea = new PdfPath(); esArea.AddRectangle(25, 280, 550, 30); page.Graphics.SaveGraphicsState(); page.Graphics.SetClip(esArea); page.Graphics.DrawShading(extendedShading); page.Graphics.RestoreGraphicsState(); page.Graphics.DrawPath(blackPen, esArea); page.Graphics.DrawString("Limited shading", sectionFont, brush, 25, 330); PdfAxialShading limitedShading = new PdfAxialShading(); limitedShading.StartColor = new PdfRgbColor(255, 0, 0); limitedShading.EndColor = new PdfRgbColor(0, 0, 255); limitedShading.StartPoint = new PdfPoint(225, 350); limitedShading.EndPoint = new PdfPoint(375, 350); limitedShading.ExtendStart = false; limitedShading.ExtendEnd = false; // Clip the shading to desired area. PdfPath lsArea = new PdfPath(); lsArea.AddRectangle(25, 350, 550, 30); page.Graphics.SaveGraphicsState(); page.Graphics.SetClip(lsArea); page.Graphics.DrawShading(limitedShading); page.Graphics.RestoreGraphicsState(); page.Graphics.DrawPath(blackPen, lsArea); page.Graphics.DrawString("Multi-stop shading", sectionFont, brush, 25, 400); // Multi-stop shadings use a stitching function to combine the functions that define each gradient part. // Function for red to blue shading. PdfExponentialFunction redToBlueFunc = new PdfExponentialFunction(); // Linear function redToBlueFunc.Exponent = 1; redToBlueFunc.Domain = new double[] { 0, 1 }; // Red color for start redToBlueFunc.C0 = new double[] { 1, 0, 0 }; // Blue color for start redToBlueFunc.C1 = new double[] { 0, 0, 1 }; // Function for blue to green shading. PdfExponentialFunction blueToGreenFunc = new PdfExponentialFunction(); // Linear function blueToGreenFunc.Exponent = 1; blueToGreenFunc.Domain = new double[] { 0, 1 }; // Blue color for start blueToGreenFunc.C0 = new double[] { 0, 0, 1 }; // Green color for start blueToGreenFunc.C1 = new double[] { 0, 1, 0 }; //Stitching function for the shading. PdfStitchingFunction shadingFunction = new PdfStitchingFunction(); shadingFunction.Functions.Add(redToBlueFunc); shadingFunction.Functions.Add(blueToGreenFunc); shadingFunction.Domain = new double[] { 0, 1 }; shadingFunction.Encode = new double[] { 0, 1, 0, 1 }; // Entire shading goes from 0 to 1 (100%). // We set the first shading (red->blue) to cover 30% (0 - 0.3) and // the second shading to cover 70% (0.3 - 1). shadingFunction.Bounds = new double[] { 0.3 }; // The multistop shading PdfAxialShading multiStopShading = new PdfAxialShading(); multiStopShading.StartPoint = new PdfPoint(25, 420); multiStopShading.EndPoint = new PdfPoint(575, 420); // The colorspace must match the colors specified in C0 & C1 multiStopShading.ColorSpace = new PdfRgbColorSpace(); multiStopShading.Function = shadingFunction; // Clip the shading to desired area. PdfPath mssArea = new PdfPath(); mssArea.AddRectangle(25, 420, 550, 30); page.Graphics.SaveGraphicsState(); page.Graphics.SetClip(mssArea); page.Graphics.DrawShading(multiStopShading); page.Graphics.RestoreGraphicsState(); page.Graphics.DrawPath(blackPen, lsArea); page.Graphics.DrawString("Radial shading", sectionFont, brush, 25, 470); PdfRadialShading rs1 = new PdfRadialShading(); rs1.StartColor = new PdfRgbColor(0, 255, 0); rs1.EndColor = new PdfRgbColor(255, 0, 255); rs1.StartCircleCenter = new PdfPoint(50, 500); rs1.StartCircleRadius = 10; rs1.EndCircleCenter = new PdfPoint(500, 570); rs1.EndCircleRadius = 100; page.Graphics.DrawShading(rs1); PdfRadialShading rs2 = new PdfRadialShading(); rs2.StartColor = new PdfRgbColor(0, 255, 0); rs2.EndColor = new PdfRgbColor(255, 0, 255); rs2.StartCircleCenter = new PdfPoint(80, 600); rs2.StartCircleRadius = 10; rs2.EndCircleCenter = new PdfPoint(110, 690); rs2.EndCircleRadius = 100; page.Graphics.DrawShading(rs2); page.Graphics.CompressAndClose(); }
public ActionResult Encryption(string InsideBrowser, string encryptionType) { PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold); PdfBrush brush = PdfBrushes.Black; PdfForm form = document.Form; //Document security PdfSecurity security = document.Security; //Specify key size and encryption algorithm if (encryptionType == "40_RC4") { //use 40 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key40Bit; } else if (encryptionType == "128_RC4") { //use 128 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key128Bit; security.Algorithm = PdfEncryptionAlgorithm.RC4; } else if (encryptionType == "128_AES") { //use 128 bits key in AES mode security.KeySize = PdfEncryptionKeySize.Key128Bit; security.Algorithm = PdfEncryptionAlgorithm.AES; } else if (encryptionType == "256_AES") { //use 256 bits key in AES mode security.KeySize = PdfEncryptionKeySize.Key256Bit; security.Algorithm = PdfEncryptionAlgorithm.AES; } else if (encryptionType == "256_AES_Revision_6") { security.KeySize = PdfEncryptionKeySize.Key256BitRevision6; security.Algorithm = PdfEncryptionAlgorithm.AES; } security.OwnerPassword = "******"; security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint; security.UserPassword = "******"; string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" + "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm); if (encryptionType == "256_AES_Revision_6") { text += String.Format("\n\nRevision: {0}", "Revision 6"); } else if (encryptionType == "256_AES") { text += String.Format("\n\nRevision: {0}", "Revision 5"); } graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Bold); graphics.DrawString(text, font, brush, new PointF(0, 40)); //Saving the PDF to the MemoryStream MemoryStream ms = new MemoryStream(); document.Save(ms); //If the position is not set to '0' then the PDF will be empty. ms.Position = 0; //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); fileStreamResult.FileDownloadName = "Secure.pdf"; return(fileStreamResult); }
/// <summary> /// /// </summary> /// <param name="page"></param> private static void DrawWatermarkWithTransparency(PdfPage page) { PdfBrush redBrush = new PdfBrush(new PdfRgbColor(192, 0, 0)); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 36); // The page graphics is located by default on top of existing page content. //page.SetGraphicsPosition(PdfPageGraphicsPosition.OverExistingPageContent); page.Graphics.SaveGraphicsState(); PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions(); sao.Brush = redBrush; sao.Font = helvetica; PdfStringLayoutOptions slo = new PdfStringLayoutOptions(); slo.X = 130; slo.Y = 670; slo.Rotation = 60; // Draw the watermark over page content but setting the transparency to a value lower than 1. // The page content will be partially visible through the watermark. PdfExtendedGraphicState gs1 = new PdfExtendedGraphicState(); gs1.FillAlpha = 0.3; page.Graphics.SetExtendedGraphicState(gs1); page.Graphics.DrawString("Sample watermark over page content", sao, slo); page.Graphics.RestoreGraphicsState(); }
private void button1_Click(object sender, EventArgs e) { //Create a pdf document. PdfDocument doc = new PdfDocument(); // Create one page PdfPageBase page = doc.Pages.Add(); float pageWidth = page.Canvas.ClientSize.Width; float y = 0; //page header PdfPen pen1 = new PdfPen(Color.LightGray, 1f); PdfBrush brush1 = new PdfSolidBrush(Color.LightGray); PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Italic)); PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Right); String text = "Demo of Spire.Pdf"; page.Canvas.DrawString(text, font1, brush1, pageWidth, y, format1); SizeF size = font1.MeasureString(text, format1); y = y + size.Height + 1; page.Canvas.DrawLine(pen1, 0, y, pageWidth, y); //title y = y + 5; PdfBrush brush2 = new PdfSolidBrush(Color.Black); PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold)); PdfStringFormat format2 = new PdfStringFormat(PdfTextAlignment.Center); format2.CharacterSpacing = 1f; text = "Summary of Science"; page.Canvas.DrawString(text, font2, brush2, pageWidth / 2, y, format2); size = font2.MeasureString(text, format2); y = y + size.Height + 6; //icon PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Wikipedia_Science.png"); page.Canvas.DrawImage(image, new PointF(pageWidth - image.PhysicalDimension.Width, y)); float imageLeftSpace = pageWidth - image.PhysicalDimension.Width - 2; float imageBottom = image.PhysicalDimension.Height + y; //refenrence content PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 9f)); PdfStringFormat format3 = new PdfStringFormat(); format3.ParagraphIndent = font3.Size * 2; format3.MeasureTrailingSpaces = true; format3.LineSpacing = font3.Size * 1.5f; String text1 = "(All text and picture from "; String text2 = "Wikipedia"; String text3 = ", the free encyclopedia)"; page.Canvas.DrawString(text1, font3, brush2, 0, y, format3); size = font3.MeasureString(text1, format3); float x1 = size.Width; format3.ParagraphIndent = 0; PdfTrueTypeFont font4 = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Underline)); PdfBrush brush3 = PdfBrushes.Blue; page.Canvas.DrawString(text2, font4, brush3, x1, y, format3); size = font4.MeasureString(text2, format3); x1 = x1 + size.Width; page.Canvas.DrawString(text3, font3, brush2, x1, y, format3); y = y + size.Height; //content PdfStringFormat format4 = new PdfStringFormat(); text = System.IO.File.ReadAllText(@"..\..\..\..\..\..\Data\Summary_of_Science.txt"); PdfTrueTypeFont font5 = new PdfTrueTypeFont(new Font("Arial", 10f)); format4.LineSpacing = font5.Size * 1.5f; PdfStringLayouter textLayouter = new PdfStringLayouter(); float imageLeftBlockHeight = imageBottom - y; PdfStringLayoutResult result = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight)); if (result.ActualSize.Height < imageBottom - y) { imageLeftBlockHeight = imageLeftBlockHeight + result.LineHeight; result = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight)); } foreach (LineInfo line in result.Lines) { page.Canvas.DrawString(line.Text, font5, brush2, 0, y, format4); y = y + result.LineHeight; } PdfTextWidget textWidget = new PdfTextWidget(result.Remainder, font5, brush2); PdfTextLayout textLayout = new PdfTextLayout(); textLayout.Break = PdfLayoutBreakType.FitPage; textLayout.Layout = PdfLayoutType.Paginate; RectangleF bounds = new RectangleF(new PointF(0, y), page.Canvas.ClientSize); textWidget.StringFormat = format4; textWidget.Draw(page, bounds, textLayout); //Save pdf file. doc.SaveToFile("TextLayout.pdf"); doc.Close(); //Launching the Pdf file. PDFDocumentViewer("TextLayout.pdf"); }
private static void DrawToPage(PdfPageBase page, string text, PdfTrueTypeFont font, PdfBrush brushColor, PdfStringFormat formatLeft, float x, float y, out float yout) { DrawToPage(page, text, font, brushColor, formatLeft, x, y, out yout, false); }
private void button1_Click(object sender, System.EventArgs e) { PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); PdfBrush brush = PdfBrushes.Black; PdfForm form = document.Form; //Document security PdfSecurity security = document.Security; //Specify key size and encryption algorithm if (rdButton40Bit.Checked) { //use 40 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key40Bit; } else if (rdButton128Bit.Checked && rdButtonRC4.Checked) { //use 128 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key128Bit; security.Algorithm = PdfEncryptionAlgorithm.RC4; } else if (rdButton128Bit.Checked && rdButtonAES.Checked) { //use 128 bits key in AES mode security.KeySize = PdfEncryptionKeySize.Key128Bit; security.Algorithm = PdfEncryptionAlgorithm.AES; } else if (rdButton256Bit.Checked) { //use 256 bits key in AES mode security.KeySize = PdfEncryptionKeySize.Key256Bit; security.Algorithm = PdfEncryptionAlgorithm.AES; } else if (rdButton256BitRevision6.Checked) { security.KeySize = PdfEncryptionKeySize.Key256BitRevision6; security.Algorithm = PdfEncryptionAlgorithm.AES; } if (cmbEncrypt.SelectedIndex == 0 || !cmbEncrypt.Enabled) { security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents; } else if (cmbEncrypt.SelectedIndex == 1) { security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContentsExceptMetadata; } else if (cmbEncrypt.SelectedIndex == 2) { security.EncryptionOptions = PdfEncryptionOptions.EncryptOnlyAttachments; //Read the file FileStream file = new FileStream(GetFullTemplatePath("Products.xml", false), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Creates an attachment PdfAttachment attachment = new PdfAttachment("Products.xml", file); attachment.ModificationDate = DateTime.Now; attachment.Description = "About Syncfusion"; attachment.MimeType = "application/txt"; //Adds the attachment to the document document.Attachments.Add(attachment); } security.OwnerPassword = "******"; security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint; security.UserPassword = "******"; string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" + "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm); if (rdButton256BitRevision6.Checked) { text += String.Format("\n\nRevision: {0}", "Revision6"); } else if (rdButton256Bit.Checked) { text += String.Format("\n\nRevision: {0}", "Revision5"); } graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16f, PdfFontStyle.Bold); graphics.DrawString(text, font, brush, new PointF(0, 40)); document.Save("Sample.pdf"); //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the PDF file using the default Application.[Acrobat Reader] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.pdf"); #endif this.Close(); } else { // Exit this.Close(); } }
private PdfTable DesignPdfTable(PdfBrush brushColor) { PdfTable table = new PdfTable(); table.Style.CellPadding = 2; table.Style.BorderPen = new PdfPen(brushColor, 0.75f); table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.Gray; table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f)); table.Style.AlternateStyle = new PdfCellStyle(); table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightGray; table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f)); table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions; table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.White; table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold)); table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); table.Style.ShowHeader = true; return table; }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); document.OptionalContentProperties = new PdfOptionalContentProperties(); PdfStandardFont helveticaBold = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 18); PdfBrush blackBrush = new PdfBrush(); PdfBrush greenBrush = new PdfBrush(PdfRgbColor.DarkGreen); PdfBrush yellowBrush = new PdfBrush(PdfRgbColor.Yellow); PdfPen bluePen = new PdfPen(PdfRgbColor.DarkBlue, 5); PdfPen redPen = new PdfPen(PdfRgbColor.DarkRed, 5); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Simple optional content: the green rectangle", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage1 = new PdfOptionalContentGroup(); ocgPage1.Name = "Page 1 - Green Rectangle"; page.Graphics.BeginOptionalContentGroup(ocgPage1); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 100, 570, 400); page.Graphics.EndOptionalContentGroup(); page = document.Pages.Add(); page.Graphics.DrawString("Multipart optional content: the green rectangles", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage2 = new PdfOptionalContentGroup(); ocgPage2.Name = "Page 2 - Green Rectangles"; page.Graphics.BeginOptionalContentGroup(ocgPage2); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200); page.Graphics.EndOptionalContentGroup(); page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680); page.Graphics.BeginOptionalContentGroup(ocgPage2); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200); page.Graphics.EndOptionalContentGroup(); page = document.Pages.Add(); page.Graphics.DrawString("Imbricated optional content: the green and yellow rectangles", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage31 = new PdfOptionalContentGroup(); ocgPage31.Name = "Page 3 - Green Rectangle"; page.Graphics.BeginOptionalContentGroup(ocgPage31); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 100, 570, 600); PdfOptionalContentGroup ocgPage32 = new PdfOptionalContentGroup(); ocgPage32.Name = "Page 3 - Yellow Rectangle"; page.Graphics.BeginOptionalContentGroup(ocgPage32); page.Graphics.DrawRectangle(redPen, yellowBrush, 100, 200, 400, 300); page.Graphics.EndOptionalContentGroup(); // ocgPage32 page.Graphics.EndOptionalContentGroup(); // ocgPage31 page = document.Pages.Add(); page.Graphics.DrawString("Multipage optional content: the green rectangles on page 4 & 5", helveticaBold, blackBrush, 20, 50); PdfOptionalContentGroup ocgPage45 = new PdfOptionalContentGroup(); ocgPage45.Name = "Page 4 & 5 - Green Rectangles"; page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200); page.Graphics.EndOptionalContentGroup(); page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680); page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200); page.Graphics.EndOptionalContentGroup(); page = document.Pages.Add(); page.Graphics.DrawString("Multipage optional content: continued", helveticaBold, blackBrush, 20, 50); page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 200, 570, 200); page.Graphics.EndOptionalContentGroup(); page.Graphics.DrawRectangle(redPen, yellowBrush, 250, 90, 110, 680); page.Graphics.BeginOptionalContentGroup(ocgPage45); page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 500, 570, 200); page.Graphics.EndOptionalContentGroup(); // Build the display tree for the optional content, // how its structure and relationships between optional content groups are presented to the user. PdfOptionalContentDisplayTreeNode ocgPage1Node = new PdfOptionalContentDisplayTreeNode(ocgPage1); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage1Node); PdfOptionalContentDisplayTreeNode ocgPage2Node = new PdfOptionalContentDisplayTreeNode(ocgPage2); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage2Node); PdfOptionalContentDisplayTreeNode ocgPage31Node = new PdfOptionalContentDisplayTreeNode(ocgPage31); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage31Node); PdfOptionalContentDisplayTreeNode ocgPage32Node = new PdfOptionalContentDisplayTreeNode(ocgPage32); ocgPage31Node.Nodes.Add(ocgPage32Node); PdfOptionalContentDisplayTreeNode ocgPage45Node = new PdfOptionalContentDisplayTreeNode(ocgPage45); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage45Node); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.optionalcontent.pdf") }; return(output); }
public void AddLine(int x1, int y1, int x2, int y2, PdfBrush color, float width) { PdfPen pen = new PdfPen(color, width); m_grapics.DrawLine(pen, x1, y1, x2, y2); }
public void BankUdbetalingsUdskrifter(dbData3060DataContext p_dbData3060, int lobnr) { var antal = (from c in p_dbData3060.tbltilpbs where c.id == lobnr select c).Count(); if (antal == 0) { throw new Exception("101 - Der er ingen PBS forsendelse for id: " + lobnr); } var qrykrd = from k in p_dbData3060.tblMedlems join h in p_dbData3060.tbloverforsels on k.Nr equals h.Nr where h.tilpbsid == lobnr select new { k.Nr, k.Navn, h.betalingsdato, h.advistekst, h.advisbelob, h.bankregnr, h.bankkontonr, h.SFaknr, }; // Start loop over betalinger i tbloverforsel int testantal = qrykrd.Count(); foreach (var krd in qrykrd) { //Create a pdf document. PdfDocument doc = new PdfDocument(); doc.DocumentInformation.Author = "Løbeklubben Puls 3060"; doc.DocumentInformation.Title = String.Format("Bankudbetaling {0}", ""); doc.DocumentInformation.Creator = "Medlem3060"; doc.DocumentInformation.Subject = String.Format("Faktura {0}", ((int)krd.SFaknr).ToString()); doc.DocumentInformation.CreationDate = DateTime.Now; //margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(2f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; // Create one page PdfPageBase page = doc.Pages.Add(PdfPageSize.A5, margin); float width = page.Canvas.ClientSize.Width; float y = 5; //title PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold)); PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left); string s = String.Format("Bankudbetaling {0}", ((int)krd.SFaknr).ToString()); page.Canvas.DrawString(s, font1, brush1, 1, y, format1); y = y + 35; String[][] dataSource = new String[7][]; int i = 0; String[] datarow = new String[2]; datarow[0] = "Tekst på eget kontoudtog"; datarow[1] = krd.advistekst; dataSource[i++] = datarow; datarow = new String[2]; datarow[0] = "Navn/kendenavn"; datarow[1] = krd.Navn; dataSource[i++] = datarow; datarow = new String[2]; datarow[0] = "Regnr"; datarow[1] = krd.bankregnr; dataSource[i++] = datarow; datarow = new String[2]; datarow[0] = "Konto"; datarow[1] = krd.bankkontonr; dataSource[i++] = datarow; datarow = new String[2]; datarow[0] = "Tekst til beløbsmodtager"; datarow[1] = krd.advistekst; dataSource[i++] = datarow; datarow = new String[2]; datarow[0] = "Beløb"; datarow[1] = ((decimal)(krd.advisbelob)).ToString("#0.00;-#0.00"); dataSource[i++] = datarow; datarow = new String[2]; datarow[0] = "Betalingsdato"; datarow[1] = ((DateTime)krd.betalingsdato).ToShortDateString(); dataSource[i++] = datarow; PdfTable table = new PdfTable(); table.Style.CellPadding = 5; //2; table.Style.HeaderSource = PdfHeaderSource.Rows; table.Style.HeaderRowCount = 0; table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold)); table.Style.ShowHeader = true; table.Style.RepeatHeader = true; table.DataSource = dataSource; table.Columns[0].Width = 100; // width * 0.30f * width; table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); table.Columns[1].Width = 100; // width * 0.10f * width; table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); PdfLayoutResult result = table.Draw(page, new PointF(0, y)); y = y + result.Bounds.Height + 5; //Save pdf file. string BilagPath = (from r in Program.karMedlemPrivat where r.key == "BankudbetalingPath" select r.value).First(); string BilagNavn = String.Format(@"Faktura {0}.pdf", ((int)krd.SFaknr).ToString()); string filename = Path.Combine(BilagPath, BilagNavn); doc.SaveToFile(filename); doc.Close(); } }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 12); PdfBrush brush = new PdfBrush(); PdfPage page = document.Pages.Add(); // First name page.Graphics.DrawString("First name:", helvetica, brush, 50, 50); PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname"); page.Fields.Add(firstNameTextBox); firstNameTextBox.Widgets[0].Font = helvetica; firstNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 45, 200, 20); firstNameTextBox.Widgets[0].BorderColor = PdfRgbColor.Black; firstNameTextBox.Widgets[0].BorderWidth = 1; // Last name page.Graphics.DrawString("Last name:", helvetica, brush, 50, 80); PdfTextBoxField lastNameTextBox = new PdfTextBoxField("lastname"); page.Fields.Add(lastNameTextBox); lastNameTextBox.Widgets[0].Font = helvetica; lastNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 75, 200, 20); lastNameTextBox.Widgets[0].BorderColor = PdfRgbColor.Black; lastNameTextBox.Widgets[0].BorderWidth = 1; // Sex page.Graphics.DrawString("Sex:", helvetica, brush, 50, 110); PdfRadioButtonField sexRadioButton = new PdfRadioButtonField("sex"); PdfRadioButtonWidget maleRadioItem = new PdfRadioButtonWidget(); sexRadioButton.Widgets.Add(maleRadioItem); PdfRadioButtonWidget femaleRadioItem = new PdfRadioButtonWidget(); sexRadioButton.Widgets.Add(femaleRadioItem); page.Fields.Add(sexRadioButton); page.Graphics.DrawString("Male", helvetica, brush, 180, 110); maleRadioItem.ExportValue = "M"; maleRadioItem.CheckStyle = PdfCheckStyle.Circle; maleRadioItem.VisualRectangle = new PdfVisualRectangle(150, 105, 20, 20); maleRadioItem.BorderColor = PdfRgbColor.Black; maleRadioItem.BorderWidth = 1; page.Graphics.DrawString("Female", helvetica, brush, 280, 110); femaleRadioItem.ExportValue = "F"; femaleRadioItem.CheckStyle = PdfCheckStyle.Circle; femaleRadioItem.VisualRectangle = new PdfVisualRectangle(250, 105, 20, 20); femaleRadioItem.BorderColor = PdfRgbColor.Black; femaleRadioItem.BorderWidth = 1; // First car page.Graphics.DrawString("First car:", helvetica, brush, 50, 140); PdfComboBoxField firstCarList = new PdfComboBoxField("firstcar"); firstCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes")); firstCarList.Items.Add(new PdfListItem("BMW", "BMW")); firstCarList.Items.Add(new PdfListItem("Audi", "Audi")); firstCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen")); firstCarList.Items.Add(new PdfListItem("Porsche", "Porsche")); firstCarList.Items.Add(new PdfListItem("Honda", "Honda")); firstCarList.Items.Add(new PdfListItem("Toyota", "Toyota")); firstCarList.Items.Add(new PdfListItem("Lexus", "Lexus")); firstCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti")); firstCarList.Items.Add(new PdfListItem("Acura", "Acura")); page.Fields.Add(firstCarList); firstCarList.Widgets[0].Font = helvetica; firstCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 135, 200, 20); firstCarList.Widgets[0].BorderColor = PdfRgbColor.Black; firstCarList.Widgets[0].BorderWidth = 1; // Second car page.Graphics.DrawString("Second car:", helvetica, brush, 50, 170); PdfListBoxField secondCarList = new PdfListBoxField("secondcar"); secondCarList.Items.Add(new PdfListItem("Mercedes", "Mercedes")); secondCarList.Items.Add(new PdfListItem("BMW", "BMW")); secondCarList.Items.Add(new PdfListItem("Audi", "Audi")); secondCarList.Items.Add(new PdfListItem("Volkswagen", "Volkswagen")); secondCarList.Items.Add(new PdfListItem("Porsche", "Porsche")); secondCarList.Items.Add(new PdfListItem("Honda", "Honda")); secondCarList.Items.Add(new PdfListItem("Toyota", "Toyota")); secondCarList.Items.Add(new PdfListItem("Lexus", "Lexus")); secondCarList.Items.Add(new PdfListItem("Infiniti", "Infiniti")); secondCarList.Items.Add(new PdfListItem("Acura", "Acura")); page.Fields.Add(secondCarList); secondCarList.Widgets[0].Font = helvetica; secondCarList.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 165, 200, 60); secondCarList.Widgets[0].BorderColor = PdfRgbColor.Black; secondCarList.Widgets[0].BorderWidth = 1; // I agree page.Graphics.DrawString("I agree:", helvetica, brush, 50, 240); PdfCheckBoxField agreeCheckBox = new PdfCheckBoxField("agree"); page.Fields.Add(agreeCheckBox); agreeCheckBox.Widgets[0].Font = helvetica; (agreeCheckBox.Widgets[0] as PdfCheckWidget).ExportValue = "YES"; (agreeCheckBox.Widgets[0] as PdfCheckWidget).CheckStyle = PdfCheckStyle.Check; agreeCheckBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 235, 20, 20); agreeCheckBox.Widgets[0].BorderColor = PdfRgbColor.Black; agreeCheckBox.Widgets[0].BorderWidth = 1; // Sign here page.Graphics.DrawString("Sign here:", helvetica, brush, 50, 270); PdfSignatureField signHereField = new PdfSignatureField("signhere"); page.Fields.Add(signHereField); signHereField.Widgets[0].Font = helvetica; signHereField.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 265, 200, 60); // Submit form PdfPushButtonField submitBtn = new PdfPushButtonField("submit"); page.Fields.Add(submitBtn); submitBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 45, 150, 30); (submitBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Submit form"; submitBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray; PdfSubmitFormAction submitFormAction = new PdfSubmitFormAction(); submitFormAction.DataFormat = PdfSubmitDataFormat.FDF; submitFormAction.Fields.Add("firstname"); submitFormAction.Fields.Add("lastname"); submitFormAction.Fields.Add("sex"); submitFormAction.Fields.Add("firstcar"); submitFormAction.Fields.Add("secondcar"); submitFormAction.Fields.Add("agree"); submitFormAction.Fields.Add("signhere"); submitFormAction.SubmitFields = true; submitFormAction.Url = "http://www.xfiniumsoft.com/"; submitBtn.Widgets[0].MouseUp = submitFormAction; // Reset form PdfPushButtonField resetBtn = new PdfPushButtonField("reset"); page.Fields.Add(resetBtn); resetBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 85, 150, 30); (resetBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Reset form"; resetBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray; PdfResetFormAction resetFormAction = new PdfResetFormAction(); resetBtn.Widgets[0].MouseUp = resetFormAction; // Print form PdfPushButtonField printBtn = new PdfPushButtonField("print"); page.Fields.Add(printBtn); printBtn.Widgets[0].VisualRectangle = new PdfVisualRectangle(450, 125, 150, 30); (printBtn.Widgets[0] as PdfPushButtonWidget).Caption = "Print form"; printBtn.Widgets[0].BackgroundColor = PdfRgbColor.LightGray; PdfJavaScriptAction printAction = new PdfJavaScriptAction(); printAction.Script = "this.print(true);\n"; printBtn.Widgets[0].MouseUp = printAction; SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.formgenerator.pdf") }; return output; }
private void button1_Click(object sender, System.EventArgs e) { //Create a new PDF Document. The pdfDoc object represents the PDF document. //This document has one page by default and additional pages have to be added. PdfDocument pdfDoc = new PdfDocument(); PdfPage page = pdfDoc.Pages.Add(); // Get xmp object. XmpMetadata xmp = pdfDoc.DocumentInformation.XmpMetadata; // XMP Basic Schema. BasicSchema basic = xmp.BasicSchema; basic.Advisory.Add("advisory"); basic.BaseURL = new Uri("http://google.com"); basic.CreateDate = DateTime.Now; basic.CreatorTool = "creator tool"; basic.Identifier.Add("identifier"); basic.Label = "label"; basic.MetadataDate = DateTime.Now; basic.ModifyDate = DateTime.Now; basic.Nickname = "nickname"; basic.Rating.Add(-25); //Setting various Document properties. pdfDoc.DocumentInformation.Title = "Document Properties Information"; pdfDoc.DocumentInformation.Author = "Syncfusion"; pdfDoc.DocumentInformation.Keywords = "PDF"; pdfDoc.DocumentInformation.Subject = "PDF demo"; pdfDoc.DocumentInformation.Producer = "Syncfusion Software"; pdfDoc.DocumentInformation.CreationDate = DateTime.Now; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f); PdfFont boldFont = new PdfStandardFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold); PdfBrush brush = PdfBrushes.Black; PdfGraphics g = page.Graphics; PdfStringFormat format = new PdfStringFormat(); format.LineSpacing = 10f; g.DrawString("Press Ctrl+D to see Document Properties", boldFont, brush, 10, 10); g.DrawString("Basic Schema Xml:", boldFont, brush, 10, 50); g.DrawString(basic.XmlData.OuterXml, font, brush, new RectangleF(10, 70, 500, 500), format); //Defines and set values for Custom metadata and add them to the Pdf document CustomSchema custom = new CustomSchema(xmp, "custom", "http://www.syncfusion.com/"); custom["Company"] = "Syncfusion"; custom["Website"] = "http://www.syncfusion.com/"; custom["Product"] = "Essential PDF"; //Save the PDF Document to disk. pdfDoc.Save("Sample.pdf"); //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the PDF file using the default Application.[Acrobat Reader] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.pdf"); #endif this.Close(); } else { // Exit this.Close(); } }
private static void CreateFileAttachmentAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); Random rnd = new Random(); // Random binary data to be used a file content for file attachment annotations. byte[] fileData = new byte[256]; PdfPage page = document.Pages.Add(); string[] fileAttachmentAnnotationNames = new string[] { "Graph", "Paperclip", "PushPin", "Tag" }; page.Graphics.DrawString("B/W file attachment annotations", font, blackBrush, 50, 50); for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++) { rnd.NextBytes(fileData); PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation(); faa.Author = "Xfinium.Pdf"; faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation."; faa.IconName = fileAttachmentAnnotationNames[i]; faa.Payload = fileData; faa.FileName = "BlackAndWhite" + fileAttachmentAnnotationNames[i] + ".dat"; page.Annotations.Add(faa); faa.Location = new PdfPoint(50, 100 + 40 * i); page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i); } byte[] rgb = new byte[3]; page.Graphics.DrawString("Color file attachment annotations", font, blackBrush, 300, 50); for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++) { rnd.NextBytes(fileData); PdfFileAttachmentAnnotation faa = new PdfFileAttachmentAnnotation(); faa.Author = "Xfinium.Pdf"; faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation."; faa.IconName = fileAttachmentAnnotationNames[i]; faa.Payload = fileData; faa.FileName = "Color" + fileAttachmentAnnotationNames[i] + ".dat"; rnd.NextBytes(rgb); faa.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]); rnd.NextBytes(rgb); faa.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]); page.Annotations.Add(faa); faa.Location = new PdfPoint(300, 100 + 40 * i); page.Graphics.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i); } page.Graphics.DrawString("File attachment annotations with custom icons", font, blackBrush, 50, 700); PdfFileAttachmentAnnotation customFileAttachmentAnnotation = new PdfFileAttachmentAnnotation(); customFileAttachmentAnnotation.Author = "Xfinium.Pdf"; customFileAttachmentAnnotation.Contents = "File attachment annotation with custom icon."; page.Annotations.Add(customFileAttachmentAnnotation); customFileAttachmentAnnotation.IconName = "Custom icon appearance"; customFileAttachmentAnnotation.Location = new PdfPoint(50, 720); PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50); PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10); PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10); customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40); customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height); customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0); customAppearance.Graphics.CompressAndClose(); customFileAttachmentAnnotation.NormalAppearance = customAppearance; }
private void button1_Click(object sender, EventArgs e) { //Create a pdf document. PdfDocument doc = new PdfDocument(); //margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; // Create one page PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin); float y = 10; //title PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold)); PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center); page.Canvas.DrawString("Part List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1); y = y + font1.MeasureString("Part List", format1).Height; y = y + 5; //create data table PdfTable table = new PdfTable(); table.Style.CellPadding = 1; table.Style.BorderPen = new PdfPen(brush1, 0.75f); table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue; table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true); table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions; table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue; table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true); table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); table.Style.ShowHeader = true; table.Style.RepeatHeader = true; using (OleDbConnection conn = new OleDbConnection()) { conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb"; OleDbCommand command = new OleDbCommand(); command.CommandText = " select * from parts "; command.Connection = conn; using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command)) { DataTable dataTable = new DataTable(); dataAdapter.Fill(dataTable); dataTable.Columns.RemoveAt(1); table.DataSourceType = PdfTableDataSourceType.TableDirect; table.DataSource = dataTable; } } float width = page.Canvas.ClientSize.Width - (table.Columns.Count + 1) * table.Style.BorderPen.Width; for (int i = 0; i < table.Columns.Count; i++) { if (i == 1) { table.Columns[i].Width = width * 0.4f * width; table.Columns[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); } else { table.Columns[i].Width = width * 0.12f * width; table.Columns[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); } } table.BeginRowLayout += new BeginRowLayoutEventHandler(table_BeginRowLayout); PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat(); tableLayout.Break = PdfLayoutBreakType.FitElement; tableLayout.Layout = PdfLayoutType.Paginate; PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout); y = result.Bounds.Bottom + 5; PdfBrush brush2 = PdfBrushes.Gray; PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f)); result.Page.Canvas.DrawString(String.Format("* All {0} parts in the list", table.Rows.Count), font2, brush2, 5, y); //Save pdf file. doc.SaveToFile("TableLayout.pdf"); doc.Close(); //Launching the Pdf file. PDFDocumentViewer("TableLayout.pdf"); }
private static void CreateLineAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Line annotations", font, blackBrush, 50, 50); PdfLineEndSymbol[] les = new PdfLineEndSymbol[] { PdfLineEndSymbol.Circle, PdfLineEndSymbol.ClosedArrow, PdfLineEndSymbol.None, PdfLineEndSymbol.OpenArrow }; for (int i = 0; i < les.Length; i++) { PdfLineAnnotation la = new PdfLineAnnotation(); page.Annotations.Add(la); la.Author = "Xfinium.Pdf"; la.Contents = "I am a line annotation with " + les[i].ToString() + " ending."; la.StartPoint = new PdfPoint(50, 100 + 40 * i); la.EndPoint = new PdfPoint(250, 100 + 40 * i); la.EndLineSymbol = les[i]; page.Graphics.DrawString("Line end symbol: " + les[i].ToString(), font, blackBrush, 270, 100 + 40 * i); } }
private void button1_Click(object sender, EventArgs e) { //Create a pdf document. PdfDocument doc = new PdfDocument(); //margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; //create section PdfSection section = doc.Sections.Add(); section.PageSettings.Size = PdfPageSize.A4; section.PageSettings.Margins = margin; // Create one page PdfPageBase page = section.Pages.Add(); float y = 10; //title PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold)); PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center); page.Canvas.DrawString("Attachment", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1); y = y + font1.MeasureString("Attachment", format1).Height; y = y + 5; //attachment PdfAttachment attachment = new PdfAttachment("Header.png"); attachment.Data = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\Header.png"); attachment.Description = "Page header picture of demo."; attachment.MimeType = "image/png"; doc.Attachments.Add(attachment); attachment = new PdfAttachment("Footer.png"); attachment.Data = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\Footer.png"); attachment.Description = "Page footer picture of demo."; attachment.MimeType = "image/png"; doc.Attachments.Add(attachment); PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold)); PointF location = new PointF(0, y); String label = "Sales Report Chart"; byte[] data = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\SalesReportChart.png"); SizeF size = font2.MeasureString(label); RectangleF bounds = new RectangleF(location, size); page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds); bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height); PdfAttachmentAnnotation annotation1 = new PdfAttachmentAnnotation(bounds, "SalesReportChart.png", data); annotation1.Color = Color.Teal; annotation1.Flags = PdfAnnotationFlags.ReadOnly; annotation1.Icon = PdfAttachmentIcon.Graph; annotation1.Text = "Sales Report Chart"; (page as PdfNewPage).Annotations.Add(annotation1); y = y + size.Height + 2; location = new PointF(0, y); label = "Science Personification Boston"; data = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\SciencePersonificationBoston.jpg"); size = font2.MeasureString(label); bounds = new RectangleF(location, size); page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds); bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height); PdfAttachmentAnnotation annotation2 = new PdfAttachmentAnnotation(bounds, "SciencePersonificationBoston.jpg", data); annotation2.Color = Color.Orange; annotation2.Flags = PdfAnnotationFlags.NoZoom; annotation2.Icon = PdfAttachmentIcon.PushPin; annotation2.Text = "SciencePersonificationBoston.jpg, from Wikipedia, the free encyclopedia"; (page as PdfNewPage).Annotations.Add(annotation2); y = y + size.Height + 2; location = new PointF(0, y); label = "Picture of Science"; data = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\Wikipedia_Science.png"); size = font2.MeasureString(label); bounds = new RectangleF(location, size); page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds); bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height); PdfAttachmentAnnotation annotation3 = new PdfAttachmentAnnotation(bounds, "Wikipedia_Science.png", data); annotation3.Color = Color.SaddleBrown; annotation3.Flags = PdfAnnotationFlags.Locked; annotation3.Icon = PdfAttachmentIcon.Tag; annotation3.Text = "Wikipedia_Science.png, from Wikipedia, the free encyclopedia"; (page as PdfNewPage).Annotations.Add(annotation3); y = y + size.Height + 2; location = new PointF(0, y); label = "Hawaii Killer Font"; data = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\Hawaii_Killer.ttf"); size = font2.MeasureString(label); bounds = new RectangleF(location, size); page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds); bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height); PdfAttachmentAnnotation annotation4 = new PdfAttachmentAnnotation(bounds, "Hawaii_Killer.ttf", data); annotation4.Color = Color.CadetBlue; annotation4.Flags = PdfAnnotationFlags.NoRotate; annotation4.Icon = PdfAttachmentIcon.Paperclip; annotation4.Text = "Hawaii Killer Font, from http://www.1001freefonts.com"; (page as PdfNewPage).Annotations.Add(annotation4); y = y + size.Height + 2; //Save pdf file. doc.SaveToFile("Attachment.pdf"); doc.Close(); //Launching the Pdf file. PDFDocumentViewer("Attachment.pdf"); }
private static void CreateRedactionAnnotations(PdfFixedDocument document, PdfFont font, Stream flashStream) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Redaction annotations", font, blackBrush, 50, 50); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10); page.Graphics.DrawString( "Open the file with Adobe Acrobat, right click on the annotation and select \"Apply redactions\". The text under the annotation will be redacted.", helvetica, blackBrush, 50, 110); PdfFormXObject redactionAppearance = new PdfFormXObject(250, 150); redactionAppearance.Graphics.DrawRectangle(new PdfBrush(PdfRgbColor.LightGreen), 0, 0, redactionAppearance.Width, redactionAppearance.Height); PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions(); sao.Brush = new PdfBrush(PdfRgbColor.DarkRed); sao.Font = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 32); PdfStringLayoutOptions slo = new PdfStringLayoutOptions(); slo.Width = redactionAppearance.Width; slo.Height = redactionAppearance.Height; slo.X = 0; slo.Y = 0; slo.HorizontalAlign = PdfStringHorizontalAlign.Center; slo.VerticalAlign = PdfStringVerticalAlign.Middle; redactionAppearance.Graphics.DrawString("This content has been redacted", sao, slo); PdfRedactionAnnotation redactionAnnotation = new PdfRedactionAnnotation(); page.Annotations.Add(redactionAnnotation); redactionAnnotation.Author = "XFINIUM.PDF"; redactionAnnotation.BorderColor = new PdfRgbColor(192, 0, 0); redactionAnnotation.BorderWidth = 1; redactionAnnotation.OverlayAppearance = redactionAppearance; redactionAnnotation.VisualRectangle = new PdfVisualRectangle(50, 100, 250, 150); }
public void AddText(string text, int x, int y, PdfBrush color) { m_grapics.DrawString(text, m_font, color, x, y); }
private static void CreateRubberStampAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); string[] rubberStampAnnotationNames = new string[] { "Approved", "AsIs", "Confidential", "Departmental", "Draft", "Experimental", "Expired", "Final", "ForComment", "ForPublicRelease", "NotApproved", "NotForPublicRelease", "Sold", "TopSecret" }; page.Graphics.DrawString("Rubber stamp annotations", font, blackBrush, 50, 50); for (int i = 0; i < rubberStampAnnotationNames.Length; i++) { PdfRubberStampAnnotation rsa = new PdfRubberStampAnnotation(); rsa.Author = "Xfinium.Pdf"; rsa.Contents = "I am a " + rubberStampAnnotationNames[i] + " rubber stamp annotation."; rsa.StampName = rubberStampAnnotationNames[i]; page.Annotations.Add(rsa); rsa.VisualRectangle = new PdfVisualRectangle(50, 70 + 50 * i, 200, 40); page.Graphics.DrawString(rubberStampAnnotationNames[i], font, blackBrush, 270, 85 + 50 * i); } page.Graphics.DrawString("Stamp annotations with custom appearance", font, blackBrush, 350, 50); PdfRubberStampAnnotation customRubberStampAnnotation = new PdfRubberStampAnnotation(); customRubberStampAnnotation.Contents = "Rubber stamp annotation with custom appearance."; customRubberStampAnnotation.StampName = "Custom"; page.Annotations.Add(customRubberStampAnnotation); customRubberStampAnnotation.VisualRectangle = new PdfVisualRectangle(350, 70, 200, 40); PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50); PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10); PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10); customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40); customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height); customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0); customAppearance.Graphics.CompressAndClose(); customRubberStampAnnotation.NormalAppearance = customAppearance; }
public MemoryStream testc( ) { var text = "Blaze Boilers & Fires"; PdfDocument doc = new PdfDocument(); //Adds a page. PdfPage page = doc.Pages.Add(); //create a new PDF string format PdfStringFormat drawFormat = new PdfStringFormat(); drawFormat.WordWrap = PdfWordWrapType.Word; drawFormat.Alignment = PdfTextAlignment.Justify; drawFormat.LineAlignment = PdfVerticalAlignment.Top; PdfTemplate header = AddHeader(doc, text, "Header and Footer Demo"); page.Graphics.DrawPdfTemplate(header, new PointF()); PdfFont headFont = new PdfStandardFont(PdfFontFamily.Helvetica, 16f); PdfBrush brush = PdfBrushes.Red; RectangleF headerBounds = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50); //PdfPageTemplateElement header = new PdfPageTemplateElement(headerBounds); //PdfTextElement elementHead = new PdfTextElement(text, headFont, brush); //Set the string format //elementHead.StringFormat = drawFormat; //Draw the text element // PdfLayoutResult resultHead = elementHead.Draw(page, headerBounds); // doc.Template.Top = header; //bounds RectangleF bounds = new RectangleF(new PointF(20, 20), new SizeF(page.Graphics.ClientSize.Width - 30, page.Graphics.ClientSize.Height - 20)); //Create a new text elememt PdfTextElement element = new PdfTextElement("01293400400", headFont, brush); //Set the string format element.StringFormat = drawFormat; //Draw the text element PdfLayoutResult result = element.Draw(page, bounds); // Draw the string one after another. result = element.Draw(result.Page, new RectangleF(result.Bounds.X, result.Bounds.Bottom + 10, result.Bounds.Width, result.Bounds.Height)); // Creates a PdfLightTable. PdfLightTable pdfLightTable = new PdfLightTable(); //Add colums to light table pdfLightTable.Columns.Add(new PdfColumn("Item")); pdfLightTable.Columns.Add(new PdfColumn("Description")); pdfLightTable.Columns.Add(new PdfColumn("Cost")); //Add row pdfLightTable.Rows.Add(new string[] { "abc", "21", "Male" }); PdfLightTable totalTable = new PdfLightTable(); totalTable.Columns.Add(new PdfColumn("Total")); totalTable.Rows.Add(new string[] { "£34" }); //Includes the style to display the header of the light table. pdfLightTable.Style.ShowHeader = true; //Draws PdfLightTable and returns the rendered bounds. result = pdfLightTable.Draw(page, new PointF(result.Bounds.Left, result.Bounds.Bottom + 20)); //draw string with returned bounds from table result = element.Draw(result.Page, result.Bounds.X, result.Bounds.Bottom + 10); //draw string with returned bounds from table element.Draw(result.Page, result.Bounds.X, result.Bounds.Bottom + 10); MemoryStream stream = new MemoryStream(); doc.Save(stream); return(stream); }
private static void CreateTextAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); string[] textAnnotationNames = new string[] { "Comment", "Check", "Circle", "Cross", "Help", "Insert", "Key", "NewParagraph", "Note", "Paragraph", "RightArrow", "RightPointer", "Star", "UpArrow", "UpLeftArrow" }; page.Graphics.DrawString("B/W text annotations", font, blackBrush, 50, 50); for (int i = 0; i < textAnnotationNames.Length; i++) { PdfTextAnnotation ta = new PdfTextAnnotation(); ta.Author = "Xfinium.Pdf"; ta.Contents = "I am a " + textAnnotationNames[i] + " annotation."; ta.IconName = textAnnotationNames[i]; page.Annotations.Add(ta); ta.Location = new PdfPoint(50, 100 + 40 * i); page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i); } Random rnd = new Random(); byte[] rgb = new byte[3]; page.Graphics.DrawString("Color text annotations", font, blackBrush, 300, 50); for (int i = 0; i < textAnnotationNames.Length; i++) { PdfTextAnnotation ta = new PdfTextAnnotation(); ta.Author = "Xfinium.Pdf"; ta.Contents = "I am a " + textAnnotationNames[i] + " annotation."; ta.IconName = textAnnotationNames[i]; rnd.NextBytes(rgb); ta.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]); rnd.NextBytes(rgb); ta.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]); page.Annotations.Add(ta); ta.Location = new PdfPoint(300, 100 + 40 * i); page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i); } page.Graphics.DrawString("Text annotations with custom icons", font, blackBrush, 50, 700); PdfTextAnnotation customTextAnnotation = new PdfTextAnnotation(); customTextAnnotation.Author = "Xfinium.Pdf"; customTextAnnotation.Contents = "Text annotation with custom icon."; page.Annotations.Add(customTextAnnotation); customTextAnnotation.IconName = "Custom icon appearance"; customTextAnnotation.Location = new PdfPoint(50, 720); PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50); PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10); PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10); customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40); customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height); customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0); customAppearance.Graphics.CompressAndClose(); customTextAnnotation.NormalAppearance = customAppearance; }
private static void DrawToPageWithHeader(PdfPageBase page, string header, string text, PdfTrueTypeFont fontHeader, PdfTrueTypeFont font, PdfBrush brushColor, PdfStringFormat formatLeft, float leftMargin, float y, out float yout) { DrawToPageWithHeader(page, header, text, fontHeader, font, brushColor, formatLeft, leftMargin, y, out yout, false); }
private static void CreateTextMarkupAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Text markup annotations", font, blackBrush, 50, 50); PdfTextMarkupAnnotationType[] tmat = new PdfTextMarkupAnnotationType[] { PdfTextMarkupAnnotationType.Highlight, PdfTextMarkupAnnotationType.Squiggly, PdfTextMarkupAnnotationType.StrikeOut, PdfTextMarkupAnnotationType.Underline }; PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions(); sao.Brush = blackBrush; sao.Font = font; PdfStringLayoutOptions slo = new PdfStringLayoutOptions(); slo.HorizontalAlign = PdfStringHorizontalAlign.Center; slo.VerticalAlign = PdfStringVerticalAlign.Bottom; for (int i = 0; i < tmat.Length; i++) { PdfTextMarkupAnnotation tma = new PdfTextMarkupAnnotation(); page.Annotations.Add(tma); tma.VisualRectangle = new PdfVisualRectangle(50, 100 + 50 * i, 200, font.Size + 2); tma.TextMarkupType = tmat[i]; slo.X = 150; slo.Y = 100 + 50 * i + font.Size; page.Graphics.DrawString(tmat[i].ToString() + " annotation.", sao, slo); } }
private static void DrawToPageWithHeader(PdfPageBase page, string header, string text, PdfTrueTypeFont fontHeader, PdfTrueTypeFont font, PdfBrush brushColor, PdfStringFormat formatLeft, float x, float y, out float yout, bool ignoreOut) { page.Canvas.DrawString(header, fontHeader, brushColor, x, y, formatLeft); SizeF size = font.MeasureString(header, formatLeft); page.Canvas.DrawString(text, font, brushColor, x + size.Width + 1, y, formatLeft); yout = (ignoreOut) ? y : y + size.Height + 2; }
private void button1_Click(object sender, System.EventArgs e) { PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold); PdfBrush brush = PdfBrushes.Black; PdfForm form = document.Form; //Document security PdfSecurity security = document.Security; //Specify key size and encryption algorithm if (rdButton40Bit.Checked) { //use 40 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key40Bit; } else if (rdButton128Bit.Checked && rdButtonRC4.Checked) { //use 128 bits key in RC4 mode security.KeySize = PdfEncryptionKeySize.Key128Bit; security.Algorithm = PdfEncryptionAlgorithm.RC4; } else if (rdButton128Bit.Checked && rdButtonAES.Checked) { //use 128 bits key in AES mode security.KeySize = PdfEncryptionKeySize.Key128Bit; security.Algorithm = PdfEncryptionAlgorithm.AES; } else if (rdButton256Bit.Checked) { //use 256 bits key in AES mode security.KeySize = PdfEncryptionKeySize.Key256Bit; security.Algorithm = PdfEncryptionAlgorithm.AES; } else if (rdButton256BitRevision6.Checked) { security.KeySize = PdfEncryptionKeySize.Key256BitRevision6; security.Algorithm = PdfEncryptionAlgorithm.AES; } security.OwnerPassword = "******"; security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint; security.UserPassword = "******"; string text = "Security options:\n\n" + String.Format("KeySize: {0}\n\nEncryption Algorithm: {4}\n\nOwner Password: {1}\n\nPermissions: {2}\n\n" + "UserPassword: {3}", security.KeySize, security.OwnerPassword, security.Permissions, security.UserPassword, security.Algorithm); if (rdButton256BitRevision6.Checked) { text += String.Format("\n\nRevision: {0}", "Revision6"); } else if (rdButton256Bit.Checked) { text += String.Format("\n\nRevision: {0}", "Revision5"); } graphics.DrawString("Document is Encrypted with following settings", font, brush, PointF.Empty); font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16f, PdfFontStyle.Bold); graphics.DrawString(text, font, brush, new PointF(0, 40)); document.Save("Sample.pdf"); //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the PDF file using the default Application.[Acrobat Reader] System.Diagnostics.Process.Start("Sample.pdf"); this.Close(); } else { // Exit this.Close(); } }
private void button1_Click(object sender, EventArgs e) { //Create a pdf document PdfDocument doc = new PdfDocument(); //Set the margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; //Add a page PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin); float y = 10; //Title PdfBrush brush = PdfBrushes.Black; PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold)); PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center); page.Canvas.DrawString("Country List", font, brush, page.Canvas.ClientSize.Width / 2, y, format); y = y + font.MeasureString("Country List", format).Height; y = y + 5; //Create data table PdfTable table = new PdfTable(); table.Style.BorderPen = new PdfPen(brush, 0.5f); //Header style table.Style.HeaderSource = PdfHeaderSource.Rows; table.Style.HeaderRowCount = 1; table.Style.ShowHeader = true; table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue; table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 14f, FontStyle.Bold)); table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); //Repeat header table.Style.RepeatHeader = true; //Body style table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue; table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f)); table.Style.AlternateStyle = new PdfCellStyle(); table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightYellow; table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f)); table.DataSource = GetData(); foreach (PdfColumn column in table.Columns) { column.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); } //Set the row height table.BeginRowLayout += new BeginRowLayoutEventHandler(table_BeginRowLayout); //Draw text below the table PdfLayoutResult result = table.Draw(page, new PointF(0, y)); y = y + result.Bounds.Height + 5; PdfBrush brush2 = PdfBrushes.Gray; PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f)); page.Canvas.DrawString(String.Format("* {0} countries in the list.", table.Rows.Count), font2, brush2, 5, y); //Save the document doc.SaveToFile("AddRepeatingColumn_out.pdf"); doc.Close(); //Launch the Pdf PDFDocumentViewer("AddRepeatingColumn_out.pdf"); }