void Pdf_Clicked(object sender, EventArgs args) { PdfDocument document = new PdfDocument(); document.PageSettings.Orientation = PdfPageOrientation.Landscape; document.PageSettings.Margins.All = 50; PdfPage page = document.Pages.Add(); PdfGraphics g = page.Graphics; PdfTextElement element = new PdfTextElement(@"Syncfusion Software 2501 Aerial Center Parkway Suite 200 Morrisville, NC 27560 USA Tel +1 888.936.8638 Fax +1 919.573.0306"); element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200)); Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("XamarinIOInvoice.SyncfusionLogo.jpg"); PdfImage img = PdfImage.FromStream(imgStream); page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45)); PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14); g.DrawRectangle(new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 20)); PdfGrid grid = new PdfGrid(); grid.DataSource = GetDataSource(); PdfGridCellStyle cellStyle = new PdfGridCellStyle(); cellStyle.Borders.All = PdfPens.White; PdfGridRow header = grid.Headers[0]; PdfGridCellStyle headerStyle = new PdfGridCellStyle(); headerStyle.Borders.All = new PdfPen(new PdfColor(126, 151, 173)); headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(126, 151, 173)); headerStyle.TextBrush = PdfBrushes.White; headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular); for (int i = 0; i < header.Cells.Count; i++) { if (i == 0) header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); else header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); } header.ApplyStyle(headerStyle); cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f); cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f); cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(131, 130, 136)); foreach (PdfGridRow row in grid.Rows) { row.ApplyStyle(cellStyle); for (int i = 0; i < row.Cells.Count; i++) { PdfGridCell cell = row.Cells[i]; if (i == 0) cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); else cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); if (i > 1) { float val = float.MinValue; float.TryParse(cell.Value.ToString(), out val); cell.Value = "$" + val.ToString(); } } } PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Layout = PdfLayoutType.Paginate; PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new Syncfusion.Drawing.PointF(0, result.Bounds.Bottom + 40), new Syncfusion.Drawing.SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat); float pos = 0.0f; for (int i = 0; i < grid.Columns.Count - 1; i++) pos += grid.Columns[i].Width; PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f); gridResult.Page.Graphics.DrawString("Total Due", font, new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 20), new Syncfusion.Drawing.SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), new PdfSolidBrush(new PdfColor(89, 89, 93)), new Syncfusion.Drawing.PointF(pos - 55, gridResult.Bounds.Bottom + 60)); pos += grid.Columns[4].Width; gridResult.Page.Graphics.DrawString("$13600", font, new PdfSolidBrush(new PdfColor(131, 130, 136)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 20), new Syncfusion.Drawing.SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); MemoryStream data = new MemoryStream(); document.Save(data); document.Close(); DependencyService.Get<ISave>().SaveTextAsync("Invoice.pdf", "application/pdf", data); }
/// <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> /// 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; }
void OnButtonClicked(object sender, EventArgs e) { Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Syncfusion_Windows8_whitepaper.pdf"); PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 100f, PdfFontStyle.Regular); foreach (PdfPageBase lPage in ldoc.Pages) { PdfGraphics g = lPage.Graphics; PdfGraphicsState state = g.Save(); g.SetTransparency(0.25f); g.TranslateTransform(50, lPage.Size.Height / 2 ); g.RotateTransform(-40); g.DrawString("Syncfusion", font, PdfPens.Red, PdfBrushes.Red, new PointF(0,0)); } MemoryStream stream = new MemoryStream(); ldoc.Save(stream); ldoc.Close(true); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("Stamping.pdf", "application/pdf", stream); else Xamarin.Forms.DependencyService.Get<ISave>().Save("Stamping.pdf", "application/pdf", stream); }
/// <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> /// /// </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() { 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; }
public ActionResult PainterReport(int?id) { var p = db.Painters.Find(id); if (p == null) { return(NotFound()); } //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document PdfPage page = document.Pages.Add(); //Create PDF graphics for the page PdfGraphics graphics = page.Graphics; //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text string str = $"Имя: {p.FirstName}.\nФамилия: {p.LastName}.\n Отчество: {p.FathersName}.\n " + $"Возраст: {p.Age}.\n Место рождения: {p.BirthPlace}.\n Дата рождения: {p.BirthDate.Value.ToLongDateString()}.\n " + $"Страна: {p.Country}.\n Дата смерти: {p.DeathDate.Value.ToLongDateString()}.\n Место смерти: {p.DeathPlace}.\n Картины: "; foreach (var painting in p.Paintings) { str += $"\n\t\"{painting.Name}\""; } str += "."; string str1 = Translit(str);//cyrillic ->latin graphics.DrawString(str1, font, PdfBrushes.Black, new PointF(0, 0)); //Saving the PDF to the MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); fileStreamResult.FileDownloadName = $"Report {Translit($"{p.LastName}")}.pdf"; return(fileStreamResult); }
public IActionResult Post([FromBody] Prescription prescription) { PdfDocument doc = new PdfDocument(); PdfPage page = doc.Pages.Add(); PdfGrid pdfGrid = new PdfGrid(); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); PdfGraphics graphics = page.Graphics; graphics.DrawString("Prescription from Dr. Sangeetha generated at " + DateTime.Now, font, PdfBrushes.Black, new PointF(0, 0)); List <object> data = new List <object>(); Object row1 = new { ID = "\n PatientName", Name = "\n " + prescription.Name + "\n" }; Object row2 = new { ID = "\n Age & gender", Name = "\n " + prescription.Age + "\n" }; Object row3 = new { ID = "\n Symptoms", Name = "\n " + prescription.Symptoms + "\n" }; Object row4 = new { ID = "\n Diagnosis", Name = "\n " + prescription.Diagnosis + "\n" }; Object row5 = new { ID = "\n Remarks", Name = "\n " + prescription.Remarks + "\n" }; data.Add(row1); data.Add(row2); data.Add(row3); data.Add(row4); data.Add(row5); //Add list to IEnumerable IEnumerable <object> dataTable = data; //Assign data source. pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 20)); //Save the PDF document to stream MemoryStream stream = new MemoryStream(); doc.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Close the document. doc.Close(true); //Defining the ContentType for pdf file. string contentType = "application/pdf"; //Define the file name. string fileName = "Prescription.pdf"; return(File(stream, contentType, fileName)); }
/// <summary> /// Performs creating of the *.pdf document to be printed with advertisment /// </summary> /// <param name="companyId">Id of the company to print</param> public static void CreatePdfForCompany(int companyId) { for (int i = 0; i < Companies.Count; i++) { if (Companies[i].CId == companyId) // If the inputted id and id of object are equal { PdfDocument document = new PdfDocument(); // creates the PDF object PdfPage page = document.Pages.Add(); // adds a new page PdfGraphics graphics = page.Graphics; // declares graphics PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); // and text parameters graphics.DrawString("JOB ADVERTISMENT:", font, PdfBrushes.Black, new PointF(0, 0)); // Outputs text graphics.DrawString("Company name: " + Companies[i].CompanyName, font, PdfBrushes.Black, new PointF(0, 40)); // graphics.DrawString("Position: " + Companies[i].Position, font, PdfBrushes.Black, new PointF(0, 70)); // int position = 100; if (Companies[i].WorkingConditions != "") // Such constructions make output { // only if there is an information graphics.DrawString("Working conditions: " + Companies[i].WorkingConditions, font, PdfBrushes.Black, new PointF(0, position)); // in this property position += 30; } if (Companies[i].PaymentConditions != "") { graphics.DrawString("Payment conditions: " + Companies[i].PaymentConditions, font, PdfBrushes.Black, new PointF(0, position)); position += 30; } if (Companies[i].LivingConditions != "") { graphics.DrawString("Living conditions: " + Companies[i].LivingConditions, font, PdfBrushes.Black, new PointF(0, position)); position += 30; } position += 30; if (Companies[i].CompanyRequirements != "") { graphics.DrawString("Requirements: " + Companies[i].CompanyRequirements, font, PdfBrushes.Black, new PointF(0, position)); } string fileName = FolderBrowsing() + "person_" + Companies[i].CId + ".pdf"; //Save the document document.Save(fileName); //Close the document document.Close(true); Process.Start(fileName); } } }
public IActionResult CreateDocument() { //Opens the Word template document FileStream fileStreamPath = new FileStream(@"wwwroot/test_template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) { //string[] fieldNames = { "ContactName", "CompanyName", "Address", "City", "Country", "Phone" }; //string[] fieldValues = { "Nancy Davolio", "Syncfusion", "507 - 20th Ave. E.Apt. 2A", "Seattle, WA", "USA", "(206) 555-9857-x5467" }; string[] fieldNames = { "firstname", "lastname", "address", "age" }; string[] fieldValues = { "Dennis", "Huillca", "APV Agua Buena D-1 San Sebastian", "30" }; string[] fieldValues2 = { "Roy", "Palacios", "Surco Lima", "31" }; //Performs the mail merge document.MailMerge.Execute(fieldNames, fieldValues); document.MailMerge.Execute(fieldNames, fieldValues2); //Converts Word document to PDF DocIORenderer render = new DocIORenderer(); PdfDocument pdfDocument = render.ConvertToPDF(document); render.Dispose(); //adding the watermark PdfGraphics graphics = pdfDocument.Pages[0].Graphics; //set the font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 60); PdfGraphicsState state = graphics.Save(); graphics.SetTransparency(0.15f); graphics.RotateTransform(-30); graphics.DrawString("PREVIEW", font, PdfPens.Black, PdfBrushes.Red, new PointF(-40, 450)); //Saves de pdf to disk FileStream outfs = new FileStream(@"wwwroot/foobar.pdf", FileMode.Create, FileAccess.Write); pdfDocument.Save(outfs); outfs.Close(); pdfDocument.Close(); //Saves the Word document to MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); FileStream fs = new FileStream(@"wwwroot/foobar.docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); document.Save(fs, FormatType.Docx); fs.Close(); //stream.WriteTo(fs); stream.Position = 0; //Download Word document in the browser return(File(stream, "application/msword", "Result.docx")); } }
/// <summary> /// Creates textbox and adds it in the form. /// </summary> /// <param name="page"></param> /// <param name="text"></param> /// <param name="tooltip"></param> /// <param name="f"></param> /// <param name="bounds"></param> private void CreateTextBox(PdfPage page, string text, string tooltip, RectangleF bounds, bool readOnly, string value) { // Create a Text box field. PdfTextBoxField textBoxField = new PdfTextBoxField(page, text); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); //Set properties to the textbox. textBoxField.Font = font; textBoxField.BackColor = Syncfusion.Drawing.Color.FromArgb(255, 238, 238, 248); textBoxField.BorderColor = white; textBoxField.Bounds = bounds; textBoxField.ToolTip = tooltip; textBoxField.ReadOnly = readOnly; textBoxField.Text = value; document.Form.Fields.Add(textBoxField); }
void GridPdfExportExtension_DrawPdfHeader(object sender, PdfHeaderFooterEventArgs e) { PdfPageTemplateElement header = e.HeaderFooterTemplate; PdfSolidBrush brush = new PdfSolidBrush(new PdfColor(System.Drawing.Color.FromArgb(44, 71, 120))); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold); //Set formatting's for the text. PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; format.LineAlignment = PdfVerticalAlignment.Middle; //Draw title. header.Graphics.DrawString("Syncfusion Essential PDF", font, brush, new System.Drawing.RectangleF(0, 0, header.Width, header.Height), format); }
void OnButtonClicked(object sender, EventArgs e) { #region Field Definitions IEnumerable <TableProducts> products = DataProvider.GetProducts(); PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8f); smallFont = new PdfStandardFont(font, 5f); PdfFont bigFont = new PdfStandardFont(font, 16f); PdfBrush orangeBrush = new PdfSolidBrush(new PdfColor(247, 148, 29)); PdfBrush grayBrush = new PdfSolidBrush(new PdfColor(170, 171, 171)); borderPen = new PdfPen(PdfBrushes.DarkGray, .3f); borderPen.LineCap = PdfLineCap.Square; transparentPen = new PdfPen(PdfBrushes.Transparent, .3f); transparentPen.LineCap = PdfLineCap.Square; # endregion
public static async void SaveChangesFile(string text) { PdfLoadedDocument loadedDocument = new PdfLoadedDocument(); await loadedDocument.OpenAsync(openFile).ConfigureAwait(true); loadedDocument.Pages.RemoveAt(0); Syncfusion.Pdf.PdfPage page = (Syncfusion.Pdf.PdfPage)loadedDocument.Pages.Add(); PdfGraphics graphics = page.Graphics; Syncfusion.Pdf.Graphics.PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); graphics.DrawString(text, font, PdfBrushes.Black, new PointF(0, 0)); await loadedDocument.Save().ConfigureAwait(true); loadedDocument.Dispose(); }
public ActionResult PaintingReport(int?id) { var p = db.Paintings.Find(id); if (p == null) { return(NotFound()); } //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document PdfPage page = document.Pages.Add(); //Create PDF graphics for the page PdfGraphics graphics = page.Graphics; //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text string str = $"Название: {p.Name}.\nХудожник: {p.Painter.FirstName} {p.Painter.LastName}.\n Материал: {p.Medium}.\n " + $"Год написания: {p.Year}.\n Размер: {p.Size_x} см x {p.Size_y} см."; foreach (var am in p.ArtMovements) { str += $"\n\t\"{am.Name}\""; } str += "."; string str1 = Translit(str);//cyrillic ->latin graphics.DrawString(str1, font, PdfBrushes.Black, new PointF(0, 0)); //Saving the PDF to the MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); fileStreamResult.FileDownloadName = $"Report \"{Translit($"{p.Name}")} \".pdf"; return(fileStreamResult); }
private void save_Clicked(object sender, EventArgs e) { pointsToShow.Clear(); foreach (var p in pointsInDB) { if (p.Show) { pointsToShow.Add(p); } } if (pointsToShow.Count == 0) { DisplayAlert("Warning", "Nothing to save", "OK"); } else { DateTime dt = DateTime.Now; string filename = dt.ToString().Replace(' ', '_'); PdfDocument document = new PdfDocument(); //Add a page to the document PdfPage page = document.Pages.Add(); //Create PDF graphics for the page PdfGraphics graphics = page.Graphics; //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); //Draw the text for (int i = 0; i < pointsToShow.Count; i++) { graphics.DrawString($"{pointsToShow[i].Name}\t\t{pointsToShow[i].ToString()}", font, PdfBrushes.Black, new PointF(0, (20 * i))); } //Save the document to the stream MemoryStream stream = new MemoryStream(); document.Save(stream); //Close the document document.Close(true); //Save the stream as a file in the device and invoke it for viewing Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView(filename, "application/pdf", stream); } }
public MemoryStream CreatePdfDocument(CbTransH trans) { string Title = "BUKTI KAS/BANK"; string Tanggal = "Tanggal"; string NoDoc = "No."; // var cetak = JsonConvert.DeserializeObject(trans); // Console.WriteLine(trans); //Create a new PDF document PdfDocument document = new PdfDocument(); // document.PageSettings = new PdfPageSettings(new SizeF(300, 400)); //Add a page document.PageSettings.Margins.All = 0; PdfPage page = document.Pages.Add(); //Create Pdf graphics for the page PdfGraphics g = page.Graphics; //Create a solid brush PdfBrush brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); PdfBrush tintamerah = new PdfSolidBrush(Color.Red); //Set the font PdfFont fontJudul = new PdfStandardFont(PdfFontFamily.TimesRoman, 16); PdfFont fontField = new PdfStandardFont(PdfFontFamily.TimesRoman, 10); //Draw Kotak RectangleF rectangle = new RectangleF(20, 120, 50, 50); g.DrawRectangle(brush, rectangle); g.TranslateTransform(60, 0); // Judul //Draw the text g.DrawString(Title, fontJudul, tintamerah, new PointF(150, 20)); g.DrawString(Tanggal, fontField, brush, new PointF(0, 50)); g.DrawString(trans.Tanggal.ToShortDateString(), fontField, brush, new PointF(50, 50)); g.DrawString(NoDoc, fontField, brush, new PointF(0, 80)); g.DrawString(trans.DocNo, fontField, brush, new PointF(50, 80)); //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; return(ms); }
public MemoryStream GetQrPdf(string displayString, string data) { const int width = 250; const int height = 125; const int qrSize = 100; var document = new PdfDocument { PageSettings = { Size = new Syncfusion.Drawing.SizeF(250, 125), Orientation = PdfPageOrientation.Landscape, Margins = new PdfMargins { All = 0 }, } }; var page = document.Pages.Add(); var graphics = page.Graphics; //Set the font. PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14, PdfFontStyle.Bold); //Draw the text. using (var imageStream = GenerateQRCodeImage(data)) { var image = new PdfBitmap(imageStream); graphics.DrawImage(image, width / 2 - qrSize / 2, 0, qrSize, qrSize); } graphics.DrawString( displayString, font, PdfBrushes.Black, new RectangleF(0, qrSize - 5, width, 20), new PdfStringFormat { Alignment = PdfTextAlignment.Center }); //Save the document. var stream = new MemoryStream(); document.Save(stream); document.Close(); stream.Reset(); return(stream); }
/// <summary> /// Occurs when the PdfExportingOptions.Exporting event occurs. /// </summary> /// <param name="sender">The PdfExportingOptions object.</param> /// <param name="e">The DataGridPdfExportingEventArgs that contains the event data.</param> private void OnExporting(object sender, DataGridPdfExportingEventArgs e) { if (e.CellType == ExportCellType.HeaderCell) { if (e.Level == 0) { e.CellStyle.BackgroundBrush = PdfBrushes.DarkBlue; } else { e.CellStyle.BackgroundBrush = PdfBrushes.OrangeRed; } PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); e.CellStyle.Font = font; e.CellStyle.TextBrush = PdfBrushes.White; } }
public static ActionResult CreateReportPdfofIngredients(List <Ingredient> ingredients, List <ItemListModel> itemList) { //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document PdfPage page = document.Pages.Add(); //Create PDF graphics for the page PdfGraphics graphics = page.Graphics; //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); var data = "INGREDIENTS \n"; foreach (var ingredient in ingredients) { data = data + "\n" + ingredient.Name + ingredient.Quantity + ingredient.QuantityType; } data = data + "\n" + "ALL ITEMS"; foreach (var itemListModel in itemList) { data = data + "\n" + itemListModel.Content + itemListModel.Quantity + itemListModel.QuantityType; } //Draw the text graphics.DrawString(data, font, PdfBrushes.Black, new PointF(0, 0)); //Saving the PDF to the MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream); //Set the position as '0'. stream.Position = 0; //Download the PDF document in the browser FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); fileStreamResult.FileDownloadName = "ReportPDF.pdf"; return(fileStreamResult); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helveticaBold = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16); PdfPage page = document.Pages.Add(); DrawTextLines(page, helveticaBold); page = document.Pages.Add(); DrawTextWrap(page, helveticaBold); page = document.Pages.Add(); DrawTextRenderingModes(page, helveticaBold); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.text.pdf") }; return output; }
private void AddFooters([NotNull] PdfDocument doc, [NotNull] PdfStandardFont font) { var pages = doc.Pages.OfType <PdfPage>().ToArray(); var textSize = font.MeasureString(_model.Name); int i = 1; foreach (var page in pages) { var y = page.Graphics.ClientSize.Height - textSize.Height - 5; page.Graphics.DrawLine(PdfPens.Black, 0, y, page.Graphics.ClientSize.Width, y); WriteText(page, _model.Name, font, 0, y + 5); WriteText(page, $"Page {i}", font, 0, y + 5, null, true); i++; } }
/// <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); }
//create the pdf header void pdfConvertor_DrawPDFHeader(object sender, PDFHeaderFooterEventArgs e) { PdfPageTemplateElement header = e.HeaderFooterTemplate; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 24); float doubleHeight = font.Height * 2; Color activeColor = Color.FromArgb(44, 71, 120); SizeF imageSize = new SizeF(110f, 35f); //Locating the logo on the right corner of the Drawing Surface PointF imageLocation = new PointF(e.HeaderFooterTemplate.Width - imageSize.Width - 20, 5); PdfImage img = new PdfBitmap(FindImageFile(@"Common\Images\Grid\PDF_logo\logo.png")); //Draw the image in the Header. header.Graphics.DrawImage(img, imageLocation, imageSize); PdfSolidBrush brush = new PdfSolidBrush(activeColor); PdfPen pen = new PdfPen(Color.DarkBlue, 3f); font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold); //Set formattings for the text PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; format.LineAlignment = PdfVerticalAlignment.Middle; //Draw title header.Graphics.DrawString("Syncfusion Essential Grid", font, brush, new RectangleF(0, 0, header.Width, header.Height), format); brush = new PdfSolidBrush(Color.Gray); font = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold); format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Left; format.LineAlignment = PdfVerticalAlignment.Bottom; //Draw some lines in the header pen = new PdfPen(Color.DarkBlue, 0.7f); header.Graphics.DrawLine(pen, 0, 0, header.Width, 0); pen = new PdfPen(Color.DarkBlue, 2f); header.Graphics.DrawLine(pen, 0, 03, header.Width + 3, 03); pen = new PdfPen(Color.DarkBlue, 2f); header.Graphics.DrawLine(pen, 0, header.Height - 3, header.Width, header.Height - 3); header.Graphics.DrawLine(pen, 0, header.Height, header.Width, header.Height); }
void OnButtonClicked(object sender, EventArgs e) { //Load PDF document to stream. #if COMMONSB Stream docStream = typeof(Stamping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Samples.Assets.Product Catalog.pdf"); #else Stream docStream = typeof(Stamping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.PDF.Samples.Assets.Product Catalog.pdf"); #endif //Load the PDF document into the loaded document object. PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream); //Create font object. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 100f, PdfFontStyle.Regular); //Stamp or watermark on all the pages. foreach (PdfPageBase lPage in ldoc.Pages) { PdfGraphics g = lPage.Graphics; PdfGraphicsState state = g.Save(); g.TranslateTransform(ldoc.Pages[0].Size.Width / 2, ldoc.Pages[0].Size.Height / 2); g.SetTransparency(0.25f); SizeF waterMarkSize = font.MeasureString("Sample"); g.RotateTransform(-40); g.DrawString("Sample", font, PdfPens.Red, PdfBrushes.Red, new PointF(-waterMarkSize.Width / 2, -waterMarkSize.Height / 2)); g.Restore(state); } MemoryStream stream = new MemoryStream(); //Save the PDF document ldoc.Save(stream); //Close the document ldoc.Close(true); //Open in default system viewer. if (Device.RuntimePlatform == Device.UWP) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("Stamping.pdf", "application/pdf", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("Stamping.pdf", "application/pdf", stream); } }
// funcion que genera el pdf de la garantia // Entrada: la entrada son los datos del dispositivo a generar garantia // Salida: como saida es un memoryStream con el documento // Restricciones: la factura no puede ser nula public static MemoryStream crearPDFGarantia(Dispositivo disp) { PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); PdfFont font2 = new PdfStandardFont(PdfFontFamily.Helvetica, 12); string fechaInicio = DateTime.Now.ToString("yyy-MM-dd"); string diafinal = DateTime.Now.ToString("dd"); int mesFinal = Convert.ToInt32(DateTime.Now.ToString("MM")); mesFinal = mesFinal + disp.tipo.tiempoGarantia; int anoFinal = Convert.ToInt32(DateTime.Now.ToString("yyyy")); anoFinal = anoFinal + (mesFinal / 12); int nuevoMes = mesFinal % 12; string fechafinal = anoFinal + "-" + nuevoMes + "-" + diafinal; graphics.DrawString("Garantía para Dispositivo: " + disp.nombre, font, PdfBrushes.Black, new PointF(0, 0)); graphics.DrawString("Usuario: " + usuarioActual.nombre + " " + usuarioActual.apellido + ".", font2, PdfBrushes.Black, new PointF(0, 40)); graphics.DrawString("Tipo Dispositivo: " + disp.Tipo.nombre + ".", font2, PdfBrushes.Black, new PointF(0, 80)); graphics.DrawString("Marca: " + disp.marca + ".", font2, PdfBrushes.Black, new PointF(0, 120)); graphics.DrawString("NumeroSerie: " + disp.numero_Serie + ".", font2, PdfBrushes.Black, new PointF(0, 160)); graphics.DrawString("Fecha Inicio Garantia: ", font2, PdfBrushes.Black, new PointF(0, 200)); graphics.DrawString(" " + fechaInicio, font2, PdfBrushes.Black, new PointF(0, 240)); graphics.DrawString("Fecha Final Garantia: ", font2, PdfBrushes.Black, new PointF(0, 280)); graphics.DrawString(" " + fechafinal, font2, PdfBrushes.Black, new PointF(0, 320)); MemoryStream stream = new MemoryStream(); document.Save(stream); stream.Position = 0; document.Close(true); return(stream); }
public void SaveAsPDF() { // Synfusion.PDF for save as pdf //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document PdfPage page = document.Pages.Add(); //Create PDF graphics for the page //PdfGraphics graphics = page.Graphics; //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); int x = 0; int y = 0; // Syncfusion.PDF ends if (Families != null) { foreach (var value in Families) { string str = $"{value.ParentName} : {value.PhoneNumber}"; //Draw string in the PDF page page.Graphics.DrawString(str, font, PdfBrushes.Black, new PointF(x, y)); y += 30; } } //Save the document to the stream MemoryStream stream = new MemoryStream(); document.Save(stream); //Close the document document.Close(true); stream.Position = 0; //Save the stream as a file in the device and invoke it for viewing Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView("Sample.pdf", "application/pdf", stream); }
public MemoryStream CreatePdf(WeatherForecast[] forecasts) { if (forecasts == null) { throw new ArgumentNullException("Data cannot be null"); } using PdfDocument pdfDocument = new PdfDocument(); int paragraphAfterSpacing = 8; int cellMargin = 8; PdfPage page = pdfDocument.Pages.Add(); PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 10); PdfTextElement title = new PdfTextElement("Weather Forecast", font, PdfBrush); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helveticaBold = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16); PdfPage page = document.Pages.Add(); DrawTextLines(page, helveticaBold); page = document.Pages.Add(); DrawTextWrap(page, helveticaBold); page = document.Pages.Add(); DrawTextRenderingModes(page, helveticaBold); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.text.pdf") }; return(output); }
public static void createPDFfromList <T>(List <T> items, string title, string location) { //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page PdfPage page = doc.Pages.Add(); //Create PDF graphics for the page. PdfGraphics graphics = page.Graphics; //Set the standard font. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. PdfTextElement textElement = new PdfTextElement(title, font); textElement.Draw(graphics, new PointF(200, 0)); //Create a PdfGrid PdfGrid pdfGrid = new PdfGrid(); //Create table from list var myType = typeof(T); DataTable dataTable = new DataTable(); foreach (PropertyInfo info in myType.GetProperties()) { dataTable.Columns.Add(new DataColumn(info.Name, info.PropertyType)); } foreach (var item in items) { DataRow dr = dataTable.NewRow(); foreach (PropertyInfo info in myType.GetProperties()) { dr[info.Name] = info.GetValue(item); } dataTable.Rows.Add(dr); } //Assign data source pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document pdfGrid.Draw(page, new PointF(0, 50)); //Save the document doc.Save(location); //Close the document doc.Close(true); }
private async System.Threading.Tasks.Task PdfButtonClicked(object sender, EventArgs e) { // Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page to the document PdfPage page = document.Pages.Add(); //Create PDF graphics for the page PdfGraphics graphics = page.Graphics; //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text graphics.DrawString("Zähler Art: " + zaehlerArt, font, PdfBrushes.Black, new PointF(0, 20)); graphics.DrawString("Zähler Stände: " + ZählerStand.Text, font, PdfBrushes.Black, new PointF(0, 50)); graphics.DrawString("Zähler Nummer: " + zaehlernummer, font, PdfBrushes.Black, new PointF(0, 85)); if (theImage != null) { Stream imageStream = theImage.GetStream(); PdfBitmap imageForPdf = new PdfBitmap(imageStream); graphics.DrawImage(imageForPdf, 0, 150, 200, 200); } Stream signatureStream = await signatureView.GetImageStreamAsync(SignatureImageFormat.Jpeg); PdfBitmap imageForsignature = new PdfBitmap(signatureStream); graphics.DrawImage(imageForsignature, 250, 150, 200, 200); //Save the document to the stream MemoryStream stream = new MemoryStream(); document.Save(stream); //Close the document document.Close(true); //Save the stream as a file in the device and invoke it for viewing DependencyService.Get <ISave>().SaveAndView("Output.pdf", "application / pdf", stream); }
/// <summary> /// Create a simple PDF document /// </summary> /// <returns>Return the created PDF document as stream</returns> public MemoryStream ImageInsertionPDF() { //Create a new PDF document PdfDocument document = new PdfDocument(); // Add a new page to the newly created document. PdfPage page = document.Pages.Add(); PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold); PdfGraphics g = page.Graphics; g.DrawString("JPEG Image", font, PdfBrushes.Blue, new Syncfusion.Drawing.PointF(0, 40)); //Load JPEG image to stream. FileStream jpgImageStream = new FileStream(ResolveApplicationPath("xamarin-jpeg.jpg"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Load the JPEG image PdfImage jpgImage = new PdfBitmap(jpgImageStream); //Draw the JPEG image g.DrawImage(jpgImage, new Syncfusion.Drawing.RectangleF(0, 70, 515, 215)); g.DrawString("PNG Image", font, PdfBrushes.Blue, new Syncfusion.Drawing.PointF(0, 355)); //Load PNG image to stream. FileStream pngImageStream = new FileStream(ResolveApplicationImagePath("xamarin-png.png"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Load the PNG image PdfImage pngImage = new PdfBitmap(pngImageStream); g.DrawImage(pngImage, new Syncfusion.Drawing.RectangleF(0, 365, 199, 300)); MemoryStream stream = new MemoryStream(); //Save the PDF document document.Save(stream); stream.Position = 0; //Close the PDF document document.Close(true); return(stream); }
private bool GeneratePdf([Required] string fileName) { using (var doc = new PdfDocument(PdfConformanceLevel.None)) { doc.PageSettings.Orientation = PdfPageOrientation.Portrait; var page = doc.Pages.Add(); var y = AddPdfHeader(page); var font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); var minSize = font.MeasureString("Ag"); _minTextHeight = minSize.Height; var healthIndex = _analyzersManager.Analyze(_model, QualityPropertySchemaManager.IsFalsePositive, out var outcomes); AddSummary(doc, page, y + 10, font, healthIndex, outcomes); var analyzers = QualityAnalyzersManager.QualityAnalyzers?.ToArray(); if (analyzers?.Any() ?? false) { foreach (var analyzer in analyzers) { var outcome = outcomes?.FirstOrDefault(x => x.Id == analyzer.GetExtensionId()); if (outcome != null) { AddOutcomePage(doc, font, analyzer, outcome); } } } var schemaManager = new AnnotationsPropertySchemaManager(_model); var propertyType = schemaManager.GetAnnotationsPropertyType(); var containers = GetContainers(schemaManager, propertyType)?.ToArray(); if (containers?.Any() ?? false) { AddReviewNotesPage(doc, font, containers, schemaManager, propertyType); } AddFooters(doc, font); doc.Save(fileName); } return(true); }
/// <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 GeneratePDF_Click(object sender, RoutedEventArgs e) { PdfDocument doc = new PdfDocument(); //Add a page PdfPage page = doc.Pages.Add(); PdfSolidBrush brush = new PdfSolidBrush(System.Drawing.Color.Black); PdfPen pen = new PdfPen(System.Drawing.Color.Black, 1f); //Create font PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 11.5f); PdfFont heading = new PdfStandardFont(PdfFontFamily.TimesRoman, 12, PdfFontStyle.Bold); font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f); page.Graphics.DrawString("Create, Read, and Edit PDF Files from C#, VB.NET", heading, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, 20), new PdfStringFormat(PdfTextAlignment.Center)); string longText = "The <b> Syncfusion Essential PDF </b> is a feature-rich and high-performance .NET PDF library that allows you to add robust PDF functionalities to any .NET application." + "It allows you to create, read, and edit PDF documents programmatically without Adobe dependencies. This library also offers functionality to <font color='#0000F8'> merge, split, stamp, form-fill, compress, and secure PDF files.</font>" + "<br/><br/><font color='#FF3440'><b>1. Secure your PDF with advanced encryption, digital signatures, and redaction.</b></font>" + "<br/><br/><font color='#FF9E4D'><b>2. Extract text and images from your PDF files.</b></font>" + "<br/><br/><font color='#4F6200'><b>3. Top features: forms, tables, barcodes; stamp, split, and merge PDFs.</b></font>"; //Rendering HtmlText PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(longText, font, brush); // Formatting Layout PdfLayoutFormat format = new PdfLayoutFormat(); format.Layout = PdfLayoutType.OnePage; //Drawing htmlString richTextElement.Draw(page, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height), format); MemoryStream stream = new MemoryStream(); await doc.SaveAsync(stream); doc.Close(true); Save(stream, "Sample.pdf"); }
private void GeneratePDF_Click(object sender, RoutedEventArgs e) { //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add page to the PDF document. PdfPage page = document.Pages.Add(); //Create font with size and style. PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold); //Create PDF graphics for the page. PdfGraphics graphics = page.Graphics; //Draw text to PDF page with font and location. graphics.DrawString("JPEG Image", font, PdfBrushes.Blue, new PointF(0, 40)); //Get the image file stream from assembly. Stream jpgImageStream = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.Xamarin_JPEG.jpg"); //Create new image from stream. PdfImage jpgImage = new PdfBitmap(jpgImageStream); //Draw the JPEG image graphics.DrawImage(jpgImage, new RectangleF(0, 70, 515, 215)); //Draw text to PDF page with font and location. graphics.DrawString("PNG Image", font, PdfBrushes.Blue, new PointF(0, 355)); //Get the image file stream from assembly. Stream pngImageStream = typeof(ImageInsertion).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.Xamarin_PNG.png"); //Create new image from stream. PdfImage pngImage = new PdfBitmap(pngImageStream); //Draw the PNG image graphics.DrawImage(pngImage, new RectangleF(0, 375, 199, 300)); //Creating the stream object. using (MemoryStream stream = new MemoryStream()) { //Save the document into stream. document.Save(stream); document.Close(); stream.Position = 0; //Save the output stream as a file using file picker. PdfUtil.Save("ImageInsertion.pdf", stream); } }
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); }
public async void GeneratePdf(Promotion promotion) { if (promotion == null) { throw new ArgumentNullException(nameof(promotion)); } //Create a new PDF document. PdfDocument document = new PdfDocument(); //Document settings document.PageSettings.Orientation = PdfPageOrientation.Landscape; document.PageSettings.Margins.All = 100; //Add a page to the document. PdfPage page = document.Pages.Add(); //Create PDF graphics for the page PdfGraphics graphics = page.Graphics; //Set the title font PdfFont titleFont = new PdfStandardFont(PdfFontFamily.Helvetica, 25); //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 15); //Draw title graphics.DrawString(promotion.Title, titleFont, PdfBrushes.Black, new PointF(0, 0)); //Draw description graphics.DrawString(promotion.Description, font, PdfBrushes.Black, new PointF(0, 25)); //Load the image as stream. Stream imageStream = GetType().GetTypeInfo().Assembly.GetManifestResourceStream("GentApp.Assets.barcode.png"); PdfBitmap image = new PdfBitmap(imageStream); //Draw the image graphics.DrawImage(image, 200, 100); //Save the PDF document to stream. MemoryStream stream = new MemoryStream(); await document.SaveAsync(stream); //Close the document. document.Close(true); //Save the stream as PDF document file in local machine. Refer to PDF/UWP section for respected code samples. PdfHelper.Save(stream, promotion.Title + ".pdf"); }
/// <summary> /// Main method for running the sample. /// </summary> /// <param name="imageStream"></param> /// <param name="cmykImageStream"></param> /// <param name="softMaskStream"></param> /// <param name="stencilMaskStream"></param> public static SampleOutputInfo[] Run(Stream imageStream, Stream cmykImageStream, Stream softMaskStream, Stream stencilMaskStream) { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helveticaBoldTitle = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16); PdfStandardFont helveticaSection = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10); PdfPage page = document.Pages.Add(); DrawImages(page, imageStream, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawImageMasks(page, imageStream, softMaskStream, stencilMaskStream, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawCmykTiff(page, cmykImageStream, helveticaBoldTitle); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.images.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> /// <param name="iccStream"></param> public static SampleOutputInfo[] Run(Stream iccStream) { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helveticaBoldTitle = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16); PdfStandardFont helveticaSection = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10); PdfPage page = document.Pages.Add(); DrawLines(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawRectangles(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawRoundRectangles(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawEllipses(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawArcsAndPies(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawBezierCurves(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawAffineTransformations(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawColorsAndColorSpaces(page, helveticaBoldTitle, helveticaSection, iccStream); page = document.Pages.Add(); DrawShadings(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawPatterns(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawFormXObjects(page, helveticaBoldTitle, helveticaSection); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.vectorgraphics.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> /// <param name="iccStream"></param> public static SampleOutputInfo[] Run(Stream iccStream) { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helveticaBoldTitle = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16); PdfStandardFont helveticaSection = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10); PdfPage page = document.Pages.Add(); DrawLines(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawRectangles(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawRoundRectangles(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawEllipses(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawArcsAndPies(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawBezierCurves(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawAffineTransformations(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawColorsAndColorSpaces(page, helveticaBoldTitle, helveticaSection, iccStream); page = document.Pages.Add(); DrawShadings(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawPatterns(page, helveticaBoldTitle, helveticaSection); page = document.Pages.Add(); DrawFormXObjects(page, helveticaBoldTitle, helveticaSection); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.vectorgraphics.pdf") }; return output; }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream flashStream, Stream u3dStream) { // Create a PDF document with 10 pages. PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 12); CreateTextAnnotations(document, helvetica); CreateSquareCircleAnnotations(document, helvetica); CreateFileAttachmentAnnotations(document, helvetica); CreateInkAnnotations(document, helvetica); CreateLineAnnotations(document, helvetica); CreatePolygonAnnotations(document, helvetica); CreatePolylineAnnotations(document, helvetica); CreateRubberStampAnnotations(document, helvetica); CreateTextMarkupAnnotations(document, helvetica); CreateRichMediaAnnotations(document, helvetica, flashStream); Create3DAnnotations(document, helvetica, u3dStream); CreateRedactionAnnotations(document, helvetica, u3dStream); // 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.annotations.pdf") }; return output; }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { PdfFixedDocument document = new PdfFixedDocument(); PdfStandardFont titleFont = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16); PdfStandardFont barcodeFont = new PdfStandardFont(PdfStandardFontFace.Helvetica, 12); PdfPage page = document.Pages.Add(); DrawGenericBarcodes(page, titleFont, barcodeFont); page = document.Pages.Add(); DrawPharmaBarcodes(page, titleFont, barcodeFont); page = document.Pages.Add(); DrawEanUpcBarcodes(page, titleFont, barcodeFont); page = document.Pages.Add(); DrawPostAndTransportantionBarcodes(page, titleFont, barcodeFont); page = document.Pages.Add(); Draw2DBarcodes(page, titleFont, barcodeFont); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.barcodes.pdf") }; return output; }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PdfBrush brush = new PdfBrush(); PdfPen redPen = new PdfPen(PdfRgbColor.Red, 1); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10); PdfFixedDocument document = new PdfFixedDocument(input); PdfContentExtractor ce = new PdfContentExtractor(document.Pages[0]); PdfVisualObjectCollection voc = ce.ExtractVisualObjects(false); PdfPath contour = null; for (int i = 0; i < voc.Count; i++) { switch (voc[i].Type) { case PdfVisualObjectType.Image: PdfImageVisualObject ivo = voc[i] as PdfImageVisualObject; contour = new PdfPath(); contour.StartSubpath(ivo.Image.ImageCorners[0].X - 5, ivo.Image.ImageCorners[0].Y + 5); contour.AddLineTo(ivo.Image.ImageCorners[1].X + 5, ivo.Image.ImageCorners[1].Y + 5); contour.AddLineTo(ivo.Image.ImageCorners[2].X + 5, ivo.Image.ImageCorners[2].Y - 5); contour.AddLineTo(ivo.Image.ImageCorners[3].X - 5, ivo.Image.ImageCorners[3].Y - 5); contour.CloseSubpath(); document.Pages[0].Graphics.DrawPath(redPen, contour); document.Pages[0].Graphics.DrawString("Image", helvetica, brush, ivo.Image.ImageCorners[0].X - 5, ivo.Image.ImageCorners[0].Y + 5); break; case PdfVisualObjectType.Text: PdfTextVisualObject tvo = voc[i] as PdfTextVisualObject; contour = new PdfPath(); contour.StartSubpath(tvo.TextFragment.FragmentCorners[0].X - 5, tvo.TextFragment.FragmentCorners[0].Y + 5); contour.AddLineTo(tvo.TextFragment.FragmentCorners[1].X + 5, tvo.TextFragment.FragmentCorners[1].Y + 5); contour.AddLineTo(tvo.TextFragment.FragmentCorners[2].X + 5, tvo.TextFragment.FragmentCorners[2].Y - 5); contour.AddLineTo(tvo.TextFragment.FragmentCorners[3].X - 5, tvo.TextFragment.FragmentCorners[3].Y - 5); contour.CloseSubpath(); document.Pages[0].Graphics.DrawPath(redPen, contour); document.Pages[0].Graphics.DrawString("Text", helvetica, brush, tvo.TextFragment.FragmentCorners[0].X - 5, tvo.TextFragment.FragmentCorners[0].Y + 5); break; case PdfVisualObjectType.Path: PdfPathVisualObject pvo = voc[i] as PdfPathVisualObject; // Examine all the path points and determine the minimum rectangle that bounds the path. double minX = 999999, minY = 999999, maxX = -999999, maxY = -999999; for (int j = 0; j < pvo.PathItems.Count; j++) { PdfPathItem pi = pvo.PathItems[j]; if (pi.Points != null) { for (int k = 0; k < pi.Points.Length; k++) { if (minX >= pi.Points[k].X) { minX = pi.Points[k].X; } if (minY >= pi.Points[k].Y) { minY = pi.Points[k].Y; } if (maxX <= pi.Points[k].X) { maxX = pi.Points[k].X; } if (maxY <= pi.Points[k].Y) { maxY = pi.Points[k].Y; } } } } contour = new PdfPath(); contour.StartSubpath(minX - 5, minY - 5); contour.AddLineTo(maxX + 5, minY - 5); contour.AddLineTo(maxX + 5, maxY + 5); contour.AddLineTo(minX - 5, maxY + 5); contour.CloseSubpath(); document.Pages[0].Graphics.DrawPath(redPen, contour); document.Pages[0].Graphics.DrawString("Path", helvetica, brush, minX - 5, maxY + 5); // Skip the rest of path objects, they are the evaluation message i = voc.Count; break; } } SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pageobjects.pdf") }; return output; }
private static void DrawStandardCjkFonts(PdfPage page) { PdfStandardFont titleFont = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 22); PdfBrush blackBrush = new PdfBrush(new PdfRgbColor()); page.Graphics.DrawString("Standard CJK fonts", titleFont, blackBrush, 20, 50); page.Graphics.DrawString("(CJK fonts supported by Adobe Reader", titleFont, blackBrush, 20, 75); page.Graphics.DrawString(" using CJK language packs)", titleFont, blackBrush, 20, 100); PdfStandardFont heiseiKakuGothic = new PdfStandardFont(PdfStandardFontFace.HeiseiKakuGothicW5, 16); page.Graphics.DrawString("Heisei Kaku Gothic - サンプル日本語フォントデモテキスト.", heiseiKakuGothic, blackBrush, 20, 150); PdfStandardFont heiseiKakuGothicBold = new PdfStandardFont(PdfStandardFontFace.HeiseiKakuGothicW5Bold, 16); page.Graphics.DrawString("Heisei Kaku Gothic Bold - サンプル日本語フォントデモテキスト.", heiseiKakuGothicBold, blackBrush, 20, 175); PdfStandardFont heiseiKakuGothicItalic = new PdfStandardFont(PdfStandardFontFace.HeiseiKakuGothicW5Italic, 16); page.Graphics.DrawString("Heisei Kaku Gothic Italic - サンプル日本語フォントデモテキスト.", heiseiKakuGothicItalic, blackBrush, 20, 200); PdfStandardFont heiseiKakuGothicBoldItalic = new PdfStandardFont(PdfStandardFontFace.HeiseiKakuGothicW5BoldItalic, 16); page.Graphics.DrawString("Heisei Kaku Gothic Bold Italic - サンプル日本語フォントデモテキスト.", heiseiKakuGothicBoldItalic, blackBrush, 20, 225); PdfStandardFont heiseiMincho = new PdfStandardFont(PdfStandardFontFace.HeiseiMinchoW3, 16); page.Graphics.DrawString("Heisei Mincho - サンプル日本語フォントデモテキスト.", heiseiMincho, blackBrush, 20, 250); PdfStandardFont heiseiMinchoBold = new PdfStandardFont(PdfStandardFontFace.HeiseiMinchoW3Bold, 16); page.Graphics.DrawString("Heisei Mincho Bold - サンプル日本語フォントデモテキスト.", heiseiMinchoBold, blackBrush, 20, 275); PdfStandardFont heiseiMinchoItalic = new PdfStandardFont(PdfStandardFontFace.HeiseiMinchoW3Italic, 16); page.Graphics.DrawString("Heisei Mincho Italic - サンプル日本語フォントデモテキスト.", heiseiMinchoItalic, blackBrush, 20, 300); PdfStandardFont heiseiMinchoBoldItalic = new PdfStandardFont(PdfStandardFontFace.HeiseiMinchoW3BoldItalic, 16); page.Graphics.DrawString("Heisei Mincho Bold Italic - サンプル日本語フォントデモテキスト.", heiseiMinchoBoldItalic, blackBrush, 20, 325); PdfStandardFont hanyangSystemsGothicMedium = new PdfStandardFont(PdfStandardFontFace.HanyangSystemsGothicMedium, 16); page.Graphics.DrawString("Hanyang Systems Gothic Medium - 샘플 한국어 글꼴 데모 텍스트.", hanyangSystemsGothicMedium, blackBrush, 20, 350); PdfStandardFont hanyangSystemsGothicMediumBold = new PdfStandardFont(PdfStandardFontFace.HanyangSystemsGothicMediumBold, 16); page.Graphics.DrawString("Hanyang Systems Gothic Medium Bold - 샘플 한국어 글꼴 데모 텍스트.", hanyangSystemsGothicMediumBold, blackBrush, 20, 375); PdfStandardFont hanyangSystemsGothicMediumItalic = new PdfStandardFont(PdfStandardFontFace.HanyangSystemsGothicMediumItalic, 16); page.Graphics.DrawString("Hanyang Systems Gothic Medium Italic - 샘플 한국어 글꼴 데모 텍스트.", hanyangSystemsGothicMediumItalic, blackBrush, 20, 400); PdfStandardFont hanyangSystemsGothicMediumBoldItalic = new PdfStandardFont(PdfStandardFontFace.HanyangSystemsGothicMediumBoldItalic, 16); page.Graphics.DrawString("Hanyang Systems Gothic Medium Bold Italic - 샘플 한국어 글꼴 데모 텍스트.", hanyangSystemsGothicMediumBoldItalic, blackBrush, 20, 425); PdfStandardFont hanyangSystemsShinMyeongJoMedium = new PdfStandardFont(PdfStandardFontFace.HanyangSystemsShinMyeongJoMedium, 16); page.Graphics.DrawString("Hanyang Systems Shin Myeong Jo Medium - 샘플 한국어 글꼴 데모 텍스트.", hanyangSystemsShinMyeongJoMedium, blackBrush, 20, 450); PdfStandardFont hanyangSystemsShinMyeongJoMediumBold = new PdfStandardFont(PdfStandardFontFace.HanyangSystemsShinMyeongJoMediumBold, 16); page.Graphics.DrawString("Hanyang Systems Shin Myeong Jo Medium Bold - 샘플 한국어 글꼴 데모 텍스트.", hanyangSystemsShinMyeongJoMediumBold, blackBrush, 20, 475); PdfStandardFont hanyangSystemsShinMyeongJoMediumItalic = new PdfStandardFont(PdfStandardFontFace.HanyangSystemsShinMyeongJoMediumItalic, 16); page.Graphics.DrawString("Hanyang Systems Shin Myeong Jo Medium Italic - 샘플 한국어 글꼴 데모 텍스트.", hanyangSystemsShinMyeongJoMediumItalic, blackBrush, 20, 500); PdfStandardFont hanyangSystemsShinMyeongJoMediumBoldItalic = new PdfStandardFont(PdfStandardFontFace.HanyangSystemsShinMyeongJoMediumBoldItalic, 16); page.Graphics.DrawString("Hanyang Systems Shin Myeong Jo Medium Bold Italic - 샘플 한국어 글꼴 데모 텍스트.", hanyangSystemsShinMyeongJoMediumBoldItalic, blackBrush, 20, 525); PdfStandardFont monotypeSungLight = new PdfStandardFont(PdfStandardFontFace.MonotypeSungLight, 16); page.Graphics.DrawString("Monotype Sung Light - 中國字體樣本示範文本.", monotypeSungLight, blackBrush, 20, 550); PdfStandardFont monotypeSungLightBold = new PdfStandardFont(PdfStandardFontFace.MonotypeSungLightBold, 16); page.Graphics.DrawString("Monotype Sung Light Bold - 中國字體樣本示範文本.", monotypeSungLightBold, blackBrush, 20, 575); PdfStandardFont monotypeSungLightItalic = new PdfStandardFont(PdfStandardFontFace.MonotypeSungLightItalic, 16); page.Graphics.DrawString("Monotype Sung Light Italic - 中國字體樣本示範文本.", monotypeSungLightItalic, blackBrush, 20, 600); PdfStandardFont monotypeSungLightBoldItalic = new PdfStandardFont(PdfStandardFontFace.MonotypeSungLightBoldItalic, 16); page.Graphics.DrawString("Monotype Sung Light Bold Italic - 中國字體樣本示範文本.", monotypeSungLightBoldItalic, blackBrush, 20, 625); PdfStandardFont sinoTypeSongLight = new PdfStandardFont(PdfStandardFontFace.SinoTypeSongLight, 16); page.Graphics.DrawString("Sino Type Song Light - 中国字体样本示范文本.", sinoTypeSongLight, blackBrush, 20, 650); PdfStandardFont sinoTypeSongLightBold = new PdfStandardFont(PdfStandardFontFace.SinoTypeSongLightBold, 16); page.Graphics.DrawString("Sino Type Song Light Bold - 中国字体样本示范文本.", sinoTypeSongLightBold, blackBrush, 20, 675); PdfStandardFont sinoTypeSongLightItalic = new PdfStandardFont(PdfStandardFontFace.SinoTypeSongLightItalic, 16); page.Graphics.DrawString("Sino Type Song Light Italic - 中国字体样本示范文本.", sinoTypeSongLightItalic, blackBrush, 20, 700); PdfStandardFont sinoTypeSongLightBoldItalic = new PdfStandardFont(PdfStandardFontFace.SinoTypeSongLightBoldItalic, 16); page.Graphics.DrawString("Sino Type Song Light Bold Italic - 中国字体样本示范文本.", sinoTypeSongLightBoldItalic, blackBrush, 20, 725); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run() { string xfiniumPdfText = "XFINIUM.PDF"; string paragraph1Block2Text = " library is a .NET/Xamarin library for cross-platform PDF development. Code written for "; string paragraph1Block4Text = " can be compiled on all supported platforms without changes. The library features a " + "wide range of capabilities, for both beginers and advanced PDF developers."; string paragraph2Block1Text = "The development style is based on fixed document model, where each page is created as needed " + "and content is placed at fixed position using a grid based layout.\r\n" + "This gives you access to all PDF features, whether you want to create a simple file " + "or you want to create a transparency knockout group at COS level, and lets you build more complex models on top of the library."; string paragraph3Block2Text = " has been developed entirely in C# and it is 100% managed code."; string paragraph4Block1Text = "With "; string paragraph4Block3Text = " you can port your PDF application logic to other platforms with zero effort which means faster time to market."; string paragraph5Block1Text = "Simple licensing per developer with royalty free distribution helps you keep your costs under control."; string paragraph6Block1Text = "SUPPORTED PLATFORMS"; string paragraph7Block1Text = ".NET 2.0 to .NET 4.5"; string paragraph8Block1Text = "Windows Forms"; string paragraph9Block1Text = "ASP.NET Webforms and MVC"; string paragraph10Block1Text = "Console applications"; string paragraph11Block1Text = "Windows services"; string paragraph12Block1Text = "Mono"; string paragraph13Block1Text = "WPF 4.0 & 4.5"; string paragraph14Block1Text = "Silverlight 4 & 5"; string paragraph15Block1Text = "WinRT (Windows Store applications)"; string paragraph16Block1Text = "Windows Phone 7 & 8"; string paragraph17Block1Text = "Xamarin.iOS"; string paragraph18Block1Text = "Xamarin.Android"; PdfStandardFont textFont = new PdfStandardFont(PdfStandardFontFace.Helvetica, 10); PdfFormattedTextBlock xfiniumPdfLinkBlock = new PdfFormattedTextBlock(xfiniumPdfText); xfiniumPdfLinkBlock.Font = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 10); xfiniumPdfLinkBlock.Font.Underline = true; xfiniumPdfLinkBlock.TextColor = new PdfBrush(PdfRgbColor.Blue); xfiniumPdfLinkBlock.Action = new PdfUriAction("http://xfiniumpdf.com/"); PdfFormattedParagraph paragraph1 = new PdfFormattedParagraph(); paragraph1.LineSpacingMode = PdfFormattedParagraphLineSpacing.Multiple; paragraph1.LineSpacing = 1.2; paragraph1.SpacingAfter = 3; paragraph1.FirstLineIndent = 10; paragraph1.HorizontalAlign = PdfStringHorizontalAlign.Justified; paragraph1.Blocks.Add(xfiniumPdfLinkBlock); paragraph1.Blocks.Add(new PdfFormattedTextBlock(paragraph1Block2Text, textFont)); paragraph1.Blocks.Add(xfiniumPdfLinkBlock); paragraph1.Blocks.Add(new PdfFormattedTextBlock(paragraph1Block4Text, textFont)); PdfFormattedParagraph paragraph2 = new PdfFormattedParagraph(); paragraph2.SpacingAfter = 3; paragraph2.FirstLineIndent = 10; paragraph2.HorizontalAlign = PdfStringHorizontalAlign.Justified; paragraph2.LineSpacingMode = PdfFormattedParagraphLineSpacing.Multiple; paragraph2.LineSpacing = 1.2; paragraph2.Blocks.Add(new PdfFormattedTextBlock(paragraph2Block1Text, textFont)); PdfFormattedParagraph paragraph3 = new PdfFormattedParagraph(); paragraph3.LineSpacingMode = PdfFormattedParagraphLineSpacing.Multiple; paragraph3.LineSpacing = 1.2; paragraph3.SpacingAfter = 3; paragraph3.FirstLineIndent = 10; paragraph3.HorizontalAlign = PdfStringHorizontalAlign.Justified; paragraph3.Blocks.Add(xfiniumPdfLinkBlock); paragraph3.Blocks.Add(new PdfFormattedTextBlock(paragraph3Block2Text, textFont)); PdfFormattedParagraph paragraph4 = new PdfFormattedParagraph(); paragraph4.LineSpacingMode = PdfFormattedParagraphLineSpacing.Multiple; paragraph4.LineSpacing = 1.2; paragraph4.SpacingAfter = 3; paragraph4.FirstLineIndent = 10; paragraph4.HorizontalAlign = PdfStringHorizontalAlign.Justified; paragraph4.Blocks.Add(new PdfFormattedTextBlock(paragraph4Block1Text, textFont)); paragraph4.Blocks.Add(xfiniumPdfLinkBlock); paragraph4.Blocks.Add(new PdfFormattedTextBlock(paragraph4Block3Text, textFont)); PdfFormattedParagraph paragraph5 = new PdfFormattedParagraph(); paragraph5.FirstLineIndent = 10; paragraph5.HorizontalAlign = PdfStringHorizontalAlign.Justified; paragraph5.Blocks.Add(new PdfFormattedTextBlock(paragraph5Block1Text, textFont)); PdfFormattedParagraph paragraph6 = new PdfFormattedParagraph(); paragraph6.SpacingBefore = 10; paragraph6.Blocks.Add(new PdfFormattedTextBlock(paragraph6Block1Text, textFont)); PdfFormattedTextBlock bulletBlock = new PdfFormattedTextBlock("\x76 ", new PdfStandardFont(PdfStandardFontFace.ZapfDingbats, 10)); PdfFormattedParagraph paragraph7 = new PdfFormattedParagraph(); paragraph7.SpacingBefore = 3; paragraph7.Bullet = bulletBlock; paragraph7.LeftIndentation = 10; paragraph7.Blocks.Add(new PdfFormattedTextBlock(paragraph7Block1Text, textFont)); PdfFormattedParagraph paragraph8 = new PdfFormattedParagraph(); paragraph8.SpacingBefore = 3; paragraph8.Bullet = bulletBlock; paragraph8.LeftIndentation = 10; paragraph8.Blocks.Add(new PdfFormattedTextBlock(paragraph8Block1Text, textFont)); PdfFormattedParagraph paragraph9 = new PdfFormattedParagraph(); paragraph9.SpacingBefore = 3; paragraph9.Bullet = bulletBlock; paragraph9.LeftIndentation = 10; paragraph9.Blocks.Add(new PdfFormattedTextBlock(paragraph9Block1Text, textFont)); PdfFormattedParagraph paragraph10 = new PdfFormattedParagraph(); paragraph10.SpacingBefore = 3; paragraph10.Bullet = bulletBlock; paragraph10.LeftIndentation = 10; paragraph10.Blocks.Add(new PdfFormattedTextBlock(paragraph10Block1Text, textFont)); PdfFormattedParagraph paragraph11 = new PdfFormattedParagraph(); paragraph11.SpacingBefore = 3; paragraph11.Bullet = bulletBlock; paragraph11.LeftIndentation = 10; paragraph11.Blocks.Add(new PdfFormattedTextBlock(paragraph11Block1Text, textFont)); PdfFormattedParagraph paragraph12 = new PdfFormattedParagraph(); paragraph12.SpacingBefore = 3; paragraph12.Bullet = bulletBlock; paragraph12.LeftIndentation = 10; paragraph12.Blocks.Add(new PdfFormattedTextBlock(paragraph12Block1Text, textFont)); PdfFormattedParagraph paragraph13 = new PdfFormattedParagraph(); paragraph13.SpacingBefore = 3; paragraph13.Bullet = bulletBlock; paragraph13.LeftIndentation = 10; paragraph13.Blocks.Add(new PdfFormattedTextBlock(paragraph13Block1Text, textFont)); PdfFormattedParagraph paragraph14 = new PdfFormattedParagraph(); paragraph14.SpacingBefore = 3; paragraph14.Bullet = bulletBlock; paragraph14.LeftIndentation = 10; paragraph14.Blocks.Add(new PdfFormattedTextBlock(paragraph14Block1Text, textFont)); PdfFormattedParagraph paragraph15 = new PdfFormattedParagraph(); paragraph15.SpacingBefore = 3; paragraph15.Bullet = bulletBlock; paragraph15.LeftIndentation = 10; paragraph15.Blocks.Add(new PdfFormattedTextBlock(paragraph15Block1Text, textFont)); PdfFormattedParagraph paragraph16 = new PdfFormattedParagraph(); paragraph16.SpacingBefore = 3; paragraph16.Bullet = bulletBlock; paragraph16.LeftIndentation = 10; paragraph16.Blocks.Add(new PdfFormattedTextBlock(paragraph16Block1Text, textFont)); PdfFormattedParagraph paragraph17 = new PdfFormattedParagraph(); paragraph17.SpacingBefore = 3; paragraph17.Bullet = bulletBlock; paragraph17.LeftIndentation = 10; paragraph17.Blocks.Add(new PdfFormattedTextBlock(paragraph17Block1Text, textFont)); PdfFormattedParagraph paragraph18 = new PdfFormattedParagraph(); paragraph18.SpacingBefore = 3; paragraph18.Bullet = bulletBlock; paragraph18.LeftIndentation = 10; paragraph18.Blocks.Add(new PdfFormattedTextBlock(paragraph18Block1Text, textFont)); PdfFormattedContent formattedContent = new PdfFormattedContent(); formattedContent.Paragraphs.Add(paragraph1); formattedContent.Paragraphs.Add(paragraph2); formattedContent.Paragraphs.Add(paragraph3); formattedContent.Paragraphs.Add(paragraph4); formattedContent.Paragraphs.Add(paragraph5); formattedContent.Paragraphs.Add(paragraph6); formattedContent.Paragraphs.Add(paragraph7); formattedContent.Paragraphs.Add(paragraph8); formattedContent.Paragraphs.Add(paragraph9); formattedContent.Paragraphs.Add(paragraph10); formattedContent.Paragraphs.Add(paragraph11); formattedContent.Paragraphs.Add(paragraph12); formattedContent.Paragraphs.Add(paragraph13); formattedContent.Paragraphs.Add(paragraph14); formattedContent.Paragraphs.Add(paragraph15); formattedContent.Paragraphs.Add(paragraph16); formattedContent.Paragraphs.Add(paragraph17); formattedContent.Paragraphs.Add(paragraph18); PdfFixedDocument document = new PdfFixedDocument(); PdfPage page = document.Pages.Add(); page.Graphics.DrawFormattedContent(formattedContent, 50, 50, 500, 700); page.Graphics.CompressAndClose(); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.formattedcontent.pdf") }; return output; }
/// <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; }
void PDFButton_Clicked(object sender, EventArgs e) { PdfDocument document = new PdfDocument(); document.PageSettings.Orientation = PdfPageOrientation.Portrait; document.PageSettings.Margins.All = 50; PdfPage page = document.Pages.Add(); PdfGraphics g = page.Graphics; PdfTextElement element = new PdfTextElement(@"Syncfusion Software 2501 Aerial Center Parkway Suite 200 Morrisville, NC 27560 USA Tel +1 888.936.8638 Fax +1 919.573.0306"); element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200)); Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("XamarinIOInvoice.SyncfusionLogo.jpg"); PdfImage img = PdfImage.FromStream(imgStream); page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45)); PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 15); g.DrawRectangle(new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 30)); element = new PdfTextElement("INVOICE: " + billInfo.InvoiceNumber.ToString(), subHeadingFont); element.Brush = PdfBrushes.White; result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 48)); string currentDate = "DATE: " + billInfo.Date.ToString(); SizeF textSize = subHeadingFont.MeasureString(currentDate); g.DrawString(currentDate, subHeadingFont, element.Brush, new PointF(g.ClientSize.Width - textSize.Width - 10, result.Bounds.Y)); element = new PdfTextElement("BILL TO ", new PdfStandardFont(PdfFontFamily.TimesRoman, 14)); element.Brush = new PdfSolidBrush(new PdfColor(34, 83, 142)); result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25)); g.DrawLine(new PdfPen(new PdfColor(34, 83, 142), 0.70f), new PointF(0, result.Bounds.Bottom + 3), new PointF(g.ClientSize.Width, result.Bounds.Bottom + 3)); element = new PdfTextElement(billInfo.Name, new PdfStandardFont(PdfFontFamily.TimesRoman, 14)); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 5, g.ClientSize.Width / 2, 100)); element = new PdfTextElement(billInfo.Address, new PdfStandardFont(PdfFontFamily.TimesRoman, 14)); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 3, g.ClientSize.Width / 2, 100)); PdfGrid grid = new PdfGrid(); grid.DataSource = this.ListSource; PdfGridCellStyle cellStyle = new PdfGridCellStyle(); cellStyle.Borders.All = PdfPens.White; PdfGridRow header = grid.Headers[0]; PdfGridCellStyle headerStyle = new PdfGridCellStyle(); headerStyle.Borders.All = new PdfPen(new PdfColor(34, 83, 142)); headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(34, 83, 142)); headerStyle.TextBrush = PdfBrushes.White; headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 15f, PdfFontStyle.Regular); for (int i = 0; i < header.Cells.Count; i++) { if (i == 0) header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); else header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); } header.Cells[0].Value = "ITEM"; header.Cells[1].Value = "QUANTITY"; header.Cells[2].Value = "RATE"; header.Cells[3].Value = "TAXES (%)"; header.Cells[4].Value = "AMOUNT"; header.ApplyStyle(headerStyle); cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f); cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f); cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(0, 0, 0)); foreach (PdfGridRow row in grid.Rows) { row.ApplyStyle(cellStyle); for (int i = 0; i < row.Cells.Count; i++) { PdfGridCell cell = row.Cells[i]; if (i == 0) cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); else cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); if (i > 1 && i != 3) { //float val = float.MinValue; //float.TryParse(cell.Value.ToString(), out val); if (cell.Value.ToString().Contains("$")) { cell.Value = cell.Value.ToString(); } else { cell.Value = "$" + cell.Value.ToString(); } } } } PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Layout = PdfLayoutType.Paginate; PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat); float pos = 0.0f; for (int i = 0; i < grid.Columns.Count - 1; i++) pos += grid.Columns[i].Width; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14f,PdfFontStyle.Bold); gridResult.Page.Graphics.DrawString("TOTAL DUE", font, new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 10), new SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 14), new PdfSolidBrush(new PdfColor(0, 0, 0)), new PointF(pos -210, gridResult.Bounds.Bottom + 60)); pos += grid.Columns[4].Width; gridResult.Page.Graphics.DrawString("$" + GetNetAmount().ToString(), font, new PdfSolidBrush(new PdfColor(0, 0, 0)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 10), new Syncfusion.Drawing.SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); MemoryStream data = new MemoryStream(); document.Save(data); document.Close(); DependencyService.Get<ISave>().SaveTextAsync("Invoice.pdf", "application/pdf", data); }
private static void DrawTrueTypeFonts(PdfPage page, Stream ttfStream) { PdfStandardFont titleFont = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 22); PdfBrush blackBrush = new PdfBrush(new PdfRgbColor()); page.Graphics.DrawString("TrueType fonts", titleFont, blackBrush, 20, 50); page.Graphics.DrawString("(when embedded they should be supported", titleFont, blackBrush, 20, 75); page.Graphics.DrawString(" by any PDF viewer)", titleFont, blackBrush, 20, 100); PdfAnsiTrueTypeFont ansiVerdana = new PdfAnsiTrueTypeFont(ttfStream, 16, true); page.Graphics.DrawString("Verdana - Ansi TrueType font", ansiVerdana, blackBrush, 20, 150); page.Graphics.DrawString("Lorem ipsum dolor sit amet, consectetur adipiscing elit.", ansiVerdana, blackBrush, 20, 175); ttfStream.Position = 0; PdfUnicodeTrueTypeFont unicodeVerdana = new PdfUnicodeTrueTypeFont(ttfStream, 16, true); page.Graphics.DrawString("Verdana - Unicode TrueType font", unicodeVerdana, blackBrush, 20, 225); page.Graphics.DrawString("Russian - Пример русский текст демо шрифт.", unicodeVerdana, blackBrush, 20, 250); page.Graphics.DrawString("Greek - Δείγμα ελληνικό κείμενο demo γραμματοσειράς.", unicodeVerdana, blackBrush, 20, 275); }
private static void DrawStandardFonts(PdfPage page) { PdfStandardFont titleFont = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 22); PdfBrush blackBrush = new PdfBrush(new PdfRgbColor()); page.Graphics.DrawString("Standard fonts", titleFont, blackBrush, 20, 50); page.Graphics.DrawString("(Base 14 PDF fonts supported by any PDF viewer)", titleFont, blackBrush, 20, 75); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 16); page.Graphics.DrawString("Helvetica - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", helvetica, blackBrush, 20, 125); PdfStandardFont helveticaBold = new PdfStandardFont(PdfStandardFontFace.HelveticaBold, 16); page.Graphics.DrawString("Helvetica Bold - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", helveticaBold, blackBrush, 20, 150); PdfStandardFont helveticaItalic = new PdfStandardFont(PdfStandardFontFace.HelveticaItalic, 16); page.Graphics.DrawString("Helvetica Italic - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", helveticaItalic, blackBrush, 20, 175); PdfStandardFont helveticaBoldItalic = new PdfStandardFont(PdfStandardFontFace.HelveticaBoldItalic, 16); page.Graphics.DrawString("Helvetica Bold Italic - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", helveticaBoldItalic, blackBrush, 20, 200); PdfStandardFont timesRoman = new PdfStandardFont(PdfStandardFontFace.TimesRoman, 16); page.Graphics.DrawString("Times Roman - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", timesRoman, blackBrush, 20, 225); PdfStandardFont timesRomanBold = new PdfStandardFont(PdfStandardFontFace.TimesRomanBold, 16); page.Graphics.DrawString("Times Roman Bold - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", timesRomanBold, blackBrush, 20, 250); PdfStandardFont timesRomanItalic = new PdfStandardFont(PdfStandardFontFace.TimesRomanItalic, 16); page.Graphics.DrawString("Times Roman Italic - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", timesRomanItalic, blackBrush, 20, 275); PdfStandardFont timesRomanBoldItalic = new PdfStandardFont(PdfStandardFontFace.TimesRomanBoldItalic, 16); page.Graphics.DrawString("Times Roman Bold Italic - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", timesRomanBoldItalic, blackBrush, 20, 300); PdfStandardFont courier = new PdfStandardFont(PdfStandardFontFace.Courier, 16); page.Graphics.DrawString("Courier - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", courier, blackBrush, 20, 325); PdfStandardFont courierBold = new PdfStandardFont(PdfStandardFontFace.CourierBold, 16); page.Graphics.DrawString("Courier Bold - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", courierBold, blackBrush, 20, 350); PdfStandardFont courierItalic = new PdfStandardFont(PdfStandardFontFace.CourierItalic, 16); page.Graphics.DrawString("Courier Italic - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", courierItalic, blackBrush, 20, 375); PdfStandardFont courierBoldItalic = new PdfStandardFont(PdfStandardFontFace.CourierBoldItalic, 16); page.Graphics.DrawString("Courier Bold Italic - Lorem ipsum dolor sit amet, consectetur adipiscing elit.", courierBoldItalic, blackBrush, 20, 400); }
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); }
/// <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; }
/// <summary> /// Main method for running the sample. /// </summary> /// <param name="stream"></param> public static SampleOutputInfo[] Run() { // Create the pdf document PdfFixedDocument document = new PdfFixedDocument(); // Create a new page in the document PdfPage page = document.Pages.Add(); PdfBrush brush = new PdfBrush(PdfRgbColor.DarkRed); PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 36); page.Graphics.DrawString("Hello World", helvetica, brush, 100, 100); PdfContentStream cs = new PdfContentStream(page.Graphics); // Sets the stroke and fill colorspaces to DeviceRGB cs.SetStrokeColorSpace(new PdfRgbColorSpace()); cs.SetFillColorSpace(new PdfRgbColorSpace()); // Set stroke color to blue cs.SetStrokeColor(new double[] { 0, 0, 1 }); // Set fill color to green cs.SetFillColor(new double[] { 0, 1, 0 }); // Draw a line from (0, 0) to (page.Width/2, page.Height/2) // It will be drawn from top left corner to center of the page. cs.MoveTo(0, 0); cs.LineTo(page.Width / 2, page.Height / 2); cs.StrokePath(); // Begin a text section cs.BeginText(); cs.SetTextRendering(PdfTextRenderingMode.FillText); cs.SetTextMatrix(1, 0, 0, 1, 100, 150); cs.SetTextFontAndSize(helvetica, helvetica.Size); // This text will appear inverted because the coordinate system is in visual mode. byte[] binaryText = helvetica.EncodeString("Hello World"); cs.ShowText(new PdfCosBinaryString(binaryText)); cs.EndText(); // Reset coordinate system and the current graphics state to default PDF cs.ResetPdfCoordinateSystem(); // Sets the stroke and fill colorspaces to DeviceRGB cs.SetStrokeColorSpace(new PdfRgbColorSpace()); cs.SetFillColorSpace(new PdfRgbColorSpace()); // Set stroke color to blue cs.SetStrokeColor(new double[] { 0, 0, 1 }); // Set fill color to green cs.SetFillColor(new double[] { 0, 1, 0 }); // Draw a line from (0, 0) to (page.Width/2, page.Height/2) // It will be drawn from bottom left corner to center of the page because the coordinate system has been reset to default PDF. cs.MoveTo(0, 0); cs.LineTo(page.Width / 2, page.Height / 2); cs.StrokePath(); // Draw the text again cs.BeginText(); cs.SetTextRendering(PdfTextRenderingMode.FillText); cs.SetTextMatrix(1, 0, 0, 1, 100, 150); cs.SetTextFontAndSize(helvetica, helvetica.Size); // This text will appear ok. binaryText = helvetica.EncodeString("Hello World"); cs.ShowText(new PdfCosBinaryString(binaryText)); cs.EndText(); // Restore the visual coordinate system cs.RestoreVisualCoordinateSystem(); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.contentstream.pdf") }; return output; }
/// <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; }
void OnButtonClicked(object sender, EventArgs e) { doc = new PdfDocument(); doc.PageSettings.Margins.All = 0; page = doc.Pages.Add(); PdfGraphics g = page.Graphics; PdfFont headerFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 35); PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 16); g.DrawRectangle(new PdfSolidBrush(gray), new RectangleF(0, 0, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height)); g.DrawRectangle(new PdfSolidBrush(black), new RectangleF(0, 0, page.Graphics.ClientSize.Width, 130)); g.DrawRectangle(new PdfSolidBrush(white), new RectangleF(0, 400, page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 450)); g.DrawString("Enterprise", headerFont, new PdfSolidBrush(violet), new PointF(10, 20)); g.DrawRectangle(new PdfSolidBrush(violet), new RectangleF(10, 63, 140, 35)); g.DrawString("Reporting Solutions", subHeadingFont, new PdfSolidBrush(black), new PointF(15, 70)); PdfLayoutResult result = HeaderPoints("Develop cloud-ready reporting applications in as little as 20% of the time.", 15); result = HeaderPoints("Proven, reliable platform thousands of users over the past 10 years.", result.Bounds.Bottom + 15); result = HeaderPoints("Microsoft Excel, Word, Adobe PDF, RDL display and editing.", result.Bounds.Bottom + 15); result = HeaderPoints("Why start from scratch? Rely on our dependable solution frameworks", result.Bounds.Bottom + 15); result = BodyContent("Deployment-ready framework tailored to your needs.", result.Bounds.Bottom + 45); result = BodyContent("Our architects and developers have years of reporting experience.", result.Bounds.Bottom + 25); result = BodyContent("Solutions available for web, desktop, and mobile applications.", result.Bounds.Bottom + 25); result = BodyContent("Backed by our end-to-end product maintenance infrastructure.", result.Bounds.Bottom + 25); result = BodyContent("The quickest path from concept to delivery.", result.Bounds.Bottom + 25); PdfPen redPen = new PdfPen(PdfBrushes.Red, 2); g.DrawLine(redPen, new PointF(40, result.Bounds.Bottom + 92), new PointF(40, result.Bounds.Bottom + 145)); float headerBulletsXposition = 40; PdfTextElement txtElement = new PdfTextElement("The Experts"); txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20); txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 90, 450, 200)); PdfPen violetPen = new PdfPen(PdfBrushes.Violet, 2); g.DrawLine(violetPen, new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 92), new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 145)); txtElement = new PdfTextElement("Accurate Estimates"); txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20); result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 90, 450, 200)); txtElement = new PdfTextElement("A substantial number of .NET reporting applications use our frameworks"); txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular); result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200)); txtElement = new PdfTextElement("Given our expertise, you can expect estimates to be accurate."); txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular); result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200)); PdfPen greenPen = new PdfPen(PdfBrushes.Green, 2); g.DrawLine(greenPen, new PointF(40, result.Bounds.Bottom + 32), new PointF(40, result.Bounds.Bottom + 85)); txtElement = new PdfTextElement("Product Licensing"); txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20); txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 30, 450, 200)); PdfPen bluePen = new PdfPen(PdfBrushes.Blue, 2); g.DrawLine(bluePen, new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 32), new PointF(headerBulletsXposition + 280, result.Bounds.Bottom + 85)); txtElement = new PdfTextElement("About Syncfusion"); txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20); result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Bottom + 30, 450, 200)); txtElement = new PdfTextElement("Solution packages can be combined with product licensing for great cost savings."); txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular); result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 5, result.Bounds.Bottom + 5, 250, 200)); txtElement = new PdfTextElement("Syncfusion has more than 7,000 customers including large financial institutions and Fortune 100 companies."); txtElement.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 11, PdfFontStyle.Regular); result = txtElement.Draw(page, new RectangleF(headerBulletsXposition + 290, result.Bounds.Y, 250, 200)); Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Reporting-Edition.jpg"); g.DrawImage(PdfImage.FromStream(imgStream), 280, 600, 300, 170); g.DrawString("All trademarks mentioned belong to their owners.", new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic), PdfBrushes.White, new PointF(10, g.ClientSize.Height - 30)); PdfTextWebLink linkAnnot = new PdfTextWebLink(); linkAnnot.Url = "http://www.syncfusion.com"; linkAnnot.Text = "www.syncfusion.com"; linkAnnot.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8, PdfFontStyle.Italic); linkAnnot.Brush = PdfBrushes.White; linkAnnot.DrawTextWebLink(page, new PointF(g.ClientSize.Width - 100, g.ClientSize.Height - 30)); MemoryStream stream = new MemoryStream(); doc.Save(stream); doc.Close(true); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) Xamarin.Forms.DependencyService.Get<ISaveWindowsPhone>().Save("GettingStarted.pdf", "application/pdf", stream); else Xamarin.Forms.DependencyService.Get<ISave>().Save("GettingStarted.pdf", "application/pdf", stream); }
/// <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(); }
/// <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; }
/// <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> /// 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; }