private void DrawSpiro(PdfPageBase page) { //save graphics state PdfGraphicsState state = page.Canvas.Save(); //Draw shap - spiro PdfPen pen = PdfPens.DeepSkyBlue; int nPoints = 1000; double r1 = 30; double r2 = 25; double p = 35; double x1 = r1 + r2 - p; double y1 = 0; double x2 = 0; double y2 = 0; page.Canvas.TranslateTransform(100, 100); for (int i = 0; i < nPoints; i++) { double t = i * Math.PI / 90; x2 = (r1 + r2) * Math.Cos(t) - p * Math.Cos((r1 + r2) * t / r2); y2 = (r1 + r2) * Math.Sin(t) - p * Math.Sin((r1 + r2) * t / r2); page.Canvas.DrawLine(pen, (float)x1, (float)y1, (float)x2, (float)y2); x1 = x2; y1 = y2; } //restor graphics page.Canvas.Restore(state); }
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)); g.Restore(state); } 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); } }
public ActionResult ImportAndStamp(string Browser, string Stamptext, HttpPostedFileBase file) { PdfLoadedDocument ldoc = null; if (file != null && file.ContentLength > 0) { ldoc = new PdfLoadedDocument(file.InputStream); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f); foreach (PdfPageBase lPage in ldoc.Pages) { PdfGraphics graphics = lPage.Graphics; PdfGraphicsState state = graphics.Save(); graphics.SetTransparency(0.25f); graphics.RotateTransform(-40); graphics.DrawString(Stamptext, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); graphics.Restore(state); } } else { ViewBag.lab = "NOTE: Please select PDF document."; return(View()); } //Stream the output to the browser. if (Browser == "Browser") { return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
void OnButtonClicked(object sender, EventArgs e) { Stream docStream = typeof(Stamping).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Product Catalog.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.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(); ldoc.Save(stream); ldoc.Close(true); if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save("Stamping.pdf", "application/pdf", stream, m_context); } }
private void DrawLineFunc(PdfPageBase page) { state = page.Canvas.Save(); //Draw Rectagle PdfPen pen = PdfPens.DeepSkyBlue; PdfBrush brush = new PdfSolidBrush(Color.Red);//画刷,颜色为red PdfPath path = new PdfPath(); float offset = 50; PointF[] points = new PointF[] { new PointF(0, 0), new PointF(0, 80), new PointF(80, 80), new PointF(80, 0) }; for (int i = 0; i < points.Length; i++) { points[i].X += offset; points[i].Y += offset; } path.AddLine(points[0], points[1]); path.AddLine(points[1], points[2]); path.AddLine(points[2], points[3]); path.AddLine(points[3], points[0]); page.Canvas.DrawPath(pen, path); page.Canvas.TranslateTransform(280, 0); path.FillMode = PdfFillMode.Winding; page.Canvas.DrawPath(pen, brush, path); //drawing line PdfPath Linepath = new PdfPath(); Linepath.AddLine(new PointF(70, 270), new PointF(96, 192)); page.Canvas.DrawPath(pen, Linepath); //restor graphics page.Canvas.Restore(state); }
private void button1_Click(object sender, EventArgs e) { PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile(@"..\..\..\..\..\..\Data\DrawingTemplate.pdf"); //Create one page PdfPageBase page = pdf.Pages[0]; //save graphics state PdfGraphicsState state = page.Canvas.Save(); //Set rectangle display location and size int x = 200; int y = 300; int width = 200; int height = 120; //Create one page and brush PdfPen pen = new PdfPen(Color.Black, 1f); PdfBrush brush = new PdfSolidBrush(Color.OrangeRed); //Draw a filled rectangle page.Canvas.DrawRectangle(pen, brush, new Rectangle(new Point(x, y), new Size(width, height))); //restor graphics page.Canvas.Restore(state); String result = "DrawFilledRectangles_out.pdf"; //Save the document pdf.SaveToFile(result); //Launch the Pdf file PDFDocumentViewer(result); }
private void DrawStrightLine(PdfPageBase page) { PointF[] points = new PointF[4]; points[0] = new PointF(-1, -1); points[1] = new PointF(-1, 1); points[2] = new PointF(1, 1); points[3] = new PointF(1, -1); PdfPath path = new PdfPath(); path.AddLine(points[0], points[1]); path.AddLine(points[1], points[2]); path.AddLine(points[2], points[3]); path.AddLine(points[3], points[0]); //save graphics state PdfGraphicsState state = page.Canvas.Save(); PdfPen pen = new PdfPen(Color.DeepSkyBlue, 0.02f); // PdfBrush brush1 = new PdfSolidBrush(Color.CadetBlue); page.Canvas.ScaleTransform(80f, 80f); page.Canvas.TranslateTransform(5f, 1.2f); page.Canvas.DrawPath(pen, path); PdfPath path2 = new PdfPath(); path2.AddLine(new PointF(-3, 0), new PointF(-3, 3)); page.Canvas.DrawPath(pen, path2); }
private async void Button_Click_1(object sender, RoutedEventArgs e) { Stream docStream = typeof(StampDocument).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Essential_Studio.pdf"); PdfLoadedDocument ldoc = new PdfLoadedDocument(docStream); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f); foreach (PdfPageBase lPage in ldoc.Pages) { PdfGraphics g = lPage.Graphics; PdfGraphicsState state = g.Save(); g.SetTransparency(0.25f); g.RotateTransform(-40); g.DrawString(stampText.Text, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); if (imagewatermark.IsChecked.Value) { Stream imagestream = typeof(StampDocument).GetTypeInfo().Assembly.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.Pdf.Pdf.Assets.Ani.gif"); PdfImage image = new PdfBitmap(imagestream); g.Restore(state); g.SetTransparency(0.25f); g.DrawImage(image, 0, 0, lPage.Graphics.ClientSize.Width, lPage.Graphics.ClientSize.Height); imagestream.Dispose(); } } MemoryStream stream = new MemoryStream(); await ldoc.SaveAsync(stream); ldoc.Close(true); Save(stream, "StampDocument.pdf"); docStream.Dispose(); }
private void TransformImage(PdfPageBase page) { PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SalesReportChart.png"); int skewX = 20; int skewY = 20; float scaleX = 0.2f; float scaleY = 0.6f; int width = (int)((image.Width + image.Height * Math.Tan(Math.PI * skewX / 180)) * scaleX); int height = (int)((image.Height + image.Width * Math.Tan(Math.PI * skewY / 180)) * scaleY); PdfTemplate template = new PdfTemplate(width, height); template.Graphics.ScaleTransform(scaleX, scaleY); template.Graphics.SkewTransform(skewX, skewY); template.Graphics.DrawImage(image, 0, 0); //save graphics state PdfGraphicsState state = page.Canvas.Save(); page.Canvas.TranslateTransform(page.Canvas.ClientSize.Width - 50, 260); float offset = (page.Canvas.ClientSize.Width - 100) / 12; for (int i = 0; i < 12; i++) { page.Canvas.TranslateTransform(-offset, 0); page.Canvas.SetTransparency(i / 12.0f); page.Canvas.DrawTemplate(template, new PointF(0, 0)); } //restor graphics page.Canvas.Restore(state); }
private async void StampingSample() { //Load PDF document to stream. Stream docStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Samples.PDF.Assets.Syncfusion_Windows8_whitepaper.pdf"); MemoryStream stream = new MemoryStream(); //Load the PDF document into the loaded document object. using (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.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)); g.Restore(state); } //Save the PDF document ldoc.Save(stream); } stream.Position = 0; if (IsToggled) { //Open in Essential PDF viewer. PdfViewerUI pdfViewer = new SampleBrowser.PdfViewerUI(); pdfViewer.PdfDocumentStream = stream; if (Device.Idiom != TargetIdiom.Phone && Device.OS == TargetPlatform.Windows) { await PDFViewModel.Navigation.PushModalAsync(new NavigationPage(pdfViewer)); } else { await PDFViewModel.Navigation.PushAsync(pdfViewer); } } else { //Open in default system viewer. 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); } } }
private void DrawPath(PdfPageBase page) { PointF[] points = new PointF[5]; for (int i = 0; i < points.Length; i++) { float x = (float)Math.Cos(i * 2 * Math.PI / 5); float y = (float)Math.Sin(i * 2 * Math.PI / 5); points[i] = new PointF(x, y); } PdfPath path = new PdfPath(); path.AddLine(points[2], points[0]); path.AddLine(points[0], points[3]); path.AddLine(points[3], points[1]); path.AddLine(points[1], points[4]); path.AddLine(points[4], points[2]); //save graphics state PdfGraphicsState state = page.Canvas.Save(); PdfPen pen = new PdfPen(Color.DeepSkyBlue, 0.02f); PdfBrush brush1 = new PdfSolidBrush(Color.CadetBlue); page.Canvas.ScaleTransform(50f, 50f); page.Canvas.TranslateTransform(5f, 1.2f); page.Canvas.DrawPath(pen, path); page.Canvas.TranslateTransform(2f, 0f); path.FillMode = PdfFillMode.Alternate; page.Canvas.DrawPath(pen, brush1, path); page.Canvas.TranslateTransform(2f, 0f); path.FillMode = PdfFillMode.Winding; page.Canvas.DrawPath(pen, brush1, path); PdfLinearGradientBrush brush2 = new PdfLinearGradientBrush(new PointF(-2, 0), new PointF(2, 0), Color.Red, Color.Blue); page.Canvas.TranslateTransform(-4f, 2f); path.FillMode = PdfFillMode.Alternate; page.Canvas.DrawPath(pen, brush2, path); PdfRadialGradientBrush brush3 = new PdfRadialGradientBrush(new PointF(0f, 0f), 0f, new PointF(0f, 0f), 1f, Color.Red, Color.Blue); page.Canvas.TranslateTransform(2f, 0f); path.FillMode = PdfFillMode.Winding; page.Canvas.DrawPath(pen, brush3, path); PdfTilingBrush brush4 = new PdfTilingBrush(new RectangleF(0, 0, 4f, 4f)); brush4.Graphics.DrawRectangle(brush2, 0, 0, 4f, 4f); page.Canvas.TranslateTransform(2f, 0f); path.FillMode = PdfFillMode.Winding; page.Canvas.DrawPath(pen, brush4, path); //restor graphics page.Canvas.Restore(state); }
// Abgrenzungen Einzeichnen public void drawRectangle(int positionXChange, int positionYChange, int sizeXChange, int sizeYChange) { PdfGraphicsState state = page.Canvas.Save(); page.Canvas.DrawRectangle(pen, new Rectangle(new Point(rectangleKoordinateX + positionXChange, rectangleKoordinateY + positionYChange), new Size(intSizeX + sizeXChange, intSizeY + sizeYChange))); //page.Canvas.DrawRectangle(pen, new Rectangle(new Point(300, 450), new Size(269, 60))); page.Canvas.Restore(state); }
public void ConvertToPdf(CardModel Card, EmailModel PersonalMail, string Font, Color color) { // Converting string to memorystream byte[] imgpth = Encoding.ASCII.GetBytes(Card.Image.ImagePath.Remove(0, 23)); MemoryStream imgStream = new MemoryStream(imgpth); // converting string to memorystream byte[] Fontpth = Encoding.ASCII.GetBytes(Font); MemoryStream FontStream = new MemoryStream(Fontpth); //creating new Pdf file and page. PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); PdfBitmap image = new PdfBitmap(imgStream); PdfGraphicsState state = page.Graphics.Save(); // drawing the picture on the background of the Pdf page.Graphics.SetTransparency(0.0f); page.Graphics.DrawImage(image, new PointF(0, 0), new SizeF(page.GetClientSize().Width, page.GetClientSize().Height)); page.Graphics.Restore(state); // creating the brush and font type for the text PdfFont font = new PdfTrueTypeFont(FontStream, 0, 0); PdfSolidBrush brush = new PdfSolidBrush(color); page.Graphics.DrawString($"{Card.Message}", font, brush, new PointF(0, 0)); MemoryStream stream = new MemoryStream(); document.Save(stream); document.Close(true); stream.Position = 0; // Sending the email Attachment file = new Attachment(stream, $"{Card.Id}", $"Christmas_Cards/pdf"); using (SmtpClient smtp = new SmtpClient($"{}")) { MailMessage message = new MailMessage(); message.From = new MailAddress("*****@*****.**"); message.To.Add($"{PersonalMail.Email}"); message.Subject = $"Some one send you an X-Mas Card {PersonalMail.FullName()}"; message.Attachments.Add(file); message.IsBodyHtml = false; smtp.Send(message); } }
private void btnImport_Click(object sender, System.EventArgs e) { PdfLoadedDocument lDoc = new PdfLoadedDocument(txtUrl.Tag.ToString()); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f); foreach (PdfPageBase lPage in lDoc.Pages) { PdfGraphics g = lPage.Graphics; PdfGraphicsState state = g.Save(); g.SetTransparency(0.25f); g.RotateTransform(-40); g.DrawString(txtStamp.Text, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); g.Restore(state); if (chbWatermark.Checked) { g.Save(); #if NETCORE PdfImage image = new PdfBitmap(@"..\..\..\..\..\..\..\..\Common\Images\PDF\Ani.gif"); #else PdfImage image = new PdfBitmap(@"..\..\..\..\..\..\..\Common\Images\PDF\Ani.gif"); #endif g.SetTransparency(0.25f); g.DrawImage(image, 0, 0, lPage.Graphics.ClientSize.Width, lPage.Graphics.ClientSize.Height); g.Restore(); } } lDoc.Save("Sample.pdf"); //Message box confirmation to view the created PDF document. if (MessageBox.Show("Do you want to view the PDF file?", "PDF File Created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the PDF file using the default Application.[Acrobat Reader] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.pdf"); #endif this.Close(); } else { // Exit this.Close(); } }
private void DrawPie(PdfPageBase page) { //Save graphics state PdfGraphicsState state = page.Canvas.Save(); PdfPen pen = new PdfPen(System.Drawing.Color.DarkRed, 2f); page.Canvas.DrawPie(pen, 220, 320, 100, 90, 360, 360); //Restore graphics page.Canvas.Restore(state); }
private void DrawEllipse(PdfPageBase page) { //Save graphics state PdfGraphicsState state = page.Canvas.Save(); PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.CadetBlue); page.Canvas.DrawEllipse(brush, 380, 325, 80, 80); //Restore graphics page.Canvas.Restore(state); }
private void DrawRectangle(PdfPageBase page) { //Save graphics state PdfGraphicsState state = page.Canvas.Save(); PdfPen pen = new PdfPen(System.Drawing.Color.Chocolate, 1f); page.Canvas.DrawRectangle(pen, new System.Drawing.Rectangle(new System.Drawing.Point(20, 310), new System.Drawing.Size(150, 120))); //Restore graphics page.Canvas.Restore(state); }
private void DrawCircleFunc(PdfPageBase page) { state = page.Canvas.Save(); PdfPen pen = new PdfPen(Color.DeepSkyBlue, 3); //边框的厚度3 PdfBrush brush1 = new PdfSolidBrush(Color.Red); //画刷,颜色为red page.Canvas.ScaleTransform(5f, 5f); //缩放操作 page.Canvas.TranslateTransform(5f, 1.2f); //平移 page.Canvas.DrawEllipse(pen, brush1, 0, 0, 20, 20); //drawCircle //restor graphics page.Canvas.Restore(state); }
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")); } }
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); } }
private void button1_Click(object sender, EventArgs e) { PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile(@"..\..\..\..\..\..\Data\DrawingTemplate.pdf"); //Create one page PdfPageBase page = pdf.Pages[0]; //Save graphics state PdfGraphicsState state = page.Canvas.Save(); //Draw rectangles //Set rectangle display location and size int x = 130; int y = 100; int width = 300; int height = 400; //Create one page PdfPen pen = new PdfPen(Color.Black, 0.1f); page.Canvas.DrawRectangle(pen, new Rectangle(new Point(x, y), new Size(width, height))); y = y + height - 50; width = 100; height = 50; //Initialize an instance of PdfSeparationColorSpace PdfSeparationColorSpace cs = new PdfSeparationColorSpace("MyColor", Color.FromArgb(0, 100, 0, 0)); PdfPen pen1 = new PdfPen(Color.Red, 1f); //Create a brush with spot color PdfBrush brush = new PdfSolidBrush(new PdfSeparationColor(cs, 0.1f)); page.Canvas.DrawRectangle(pen1, brush, new Rectangle(new Point(x, y), new Size(width, height))); //Restor graphics page.Canvas.Restore(state); String result = "DrawRectangles_out.pdf"; //Save the document pdf.SaveToFile(result); //Launch the Pdf file PDFDocumentViewer(result); }
private void TransformText(PdfPageBase page) { //save graphics state PdfGraphicsState state = page.Canvas.Save(); //Draw the text - transform PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f); PdfSolidBrush brush1 = new PdfSolidBrush(Color.Blue); PdfSolidBrush brush2 = new PdfSolidBrush(Color.CadetBlue); PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center); page.Canvas.TranslateTransform(page.Canvas.ClientSize.Width / 2, 20); page.Canvas.DrawString("Sales Report Chart", font, brush1, 0, 0, format); page.Canvas.ScaleTransform(1f, -0.8f); page.Canvas.DrawString("Sales Report Chart", font, brush2, 0, -2 * 18 * 1.2f, format); //restor graphics page.Canvas.Restore(state); }
public ActionResult ImportAndStamp(string Browser, string Stamptext, IFormFile file) { PdfLoadedDocument ldoc = null; if (file != null && file.Length > 0) { ldoc = new PdfLoadedDocument(file.OpenReadStream()); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f); foreach (PdfPageBase lPage in ldoc.Pages) { PdfGraphics graphics = lPage.Graphics; PdfGraphicsState state = graphics.Save(); graphics.SetTransparency(0.25f); graphics.RotateTransform(-40); graphics.DrawString(Stamptext, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); graphics.Restore(state); } } else { ViewBag.lab = "NOTE: Please select PDF document."; return(View()); } MemoryStream stream = new MemoryStream(); //Save the PDF document ldoc.Save(stream); stream.Position = 0; //Close the PDF document ldoc.Close(true); //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); fileStreamResult.FileDownloadName = "Stamp.pdf"; return(fileStreamResult); }
private void DrawText(PdfPageBase page) { //save graphics state PdfGraphicsState state = page.Canvas.Save(); //Draw text - brush String text = "Go! Turn Around! Go! Go! Go!"; PdfPen pen = PdfPens.DeepSkyBlue; PdfSolidBrush brush = new PdfSolidBrush(Color.White); PdfStringFormat format = new PdfStringFormat(); PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 18f, PdfFontStyle.Italic); SizeF size = font.MeasureString(text, format); RectangleF rctg = new RectangleF(page.Canvas.ClientSize.Width / 2 + 10, 180, size.Width / 3 * 2, size.Height * 2); page.Canvas.DrawString(text, font, pen, brush, rctg, format); //restor graphics page.Canvas.Restore(state); }
/// <summary> /// https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Convert-HTML-to-PDF-Customize-HTML-to-PDF-Conversion-by-Yourself.html /// </summary> public void pdf() { PdfDocument doc = new PdfDocument(); PdfPageBase page = doc.Pages.Add(); PdfGraphicsState state = page.Canvas.Save(); PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f); PdfSolidBrush brush = new PdfSolidBrush(Color.Blue); PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); float x = page.Canvas.ClientSize.Width / 2; float y = 380; page.Canvas.TranslateTransform(x, y); for (int i = 0; i < 12; i++) { page.Canvas.RotateTransform(30); page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, 20, 0, centerAlignment); } page.Canvas.Restore(state); doc.SaveToFile("DrawText.pdf"); doc.Close(); }
private void button1_Click(object sender, EventArgs e) { //Create a pdf document and load file from disk PdfDocument doc = new PdfDocument(); doc.LoadFromFile(@"../../../../../../Data/PDFTemplate_N.pdf"); //Get the first page PdfPageBase page = doc.Pages[0]; //Define Pdf pen PdfPen pen = new PdfPen(Color.Gray); //Save graphics state PdfGraphicsState state = page.Canvas.Save(); //Rotate page canvas page.Canvas.RotateTransform(-20); PdfStringFormat format = new PdfStringFormat(); format.CharacterSpacing = 5f; //Draw the string on page page.Canvas.DrawString("E-ICEBLUE", new PdfFont(PdfFontFamily.Helvetica, 45f), pen, 0, 500f, format); //Restore graphics page.Canvas.Restore(state); //Save the Pdf file string output = "FillStrokeText_out.pdf"; doc.SaveToFile(output); doc.Close(); //Launch the Pdf file PDFDocumentViewer(output); }
private void Button_Click(object sender, RoutedEventArgs e) { //Get the template PDF file stream from assembly. Stream documentStream = typeof(PdfWatermark).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.pdf_succinctly.pdf"); //Load the PDF document from stream. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream); //Create a new font instance. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36f); //Adding a watermark text to all the PDF pages. foreach (PdfPageBase loadedPage in loadedDocument.Pages) { //Get the PDF page graphics. PdfGraphics graphics = loadedPage.Graphics; //Save the current graphics state. PdfGraphicsState state = graphics.Save(); //Set transparency to add a watermark text. graphics.SetTransparency(0.25f); //Rotate the graphics to add a watermark text with 40 degree. graphics.RotateTransform(-40); //Draw a watermark text to PDF page graphics. graphics.DrawString(stampText.Text, font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); //Restore the graphics state. graphics.Restore(state); } //Creating the stream object. using (MemoryStream stream = new MemoryStream()) { //Save the document into stream. loadedDocument.Save(stream); loadedDocument.Close(); stream.Position = 0; //Save the output stream as a file using file picker. PdfUtil.Save("PdfWatermark.pdf", stream); } }
private void button1_Click(object sender, EventArgs e) { PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile(@"..\..\..\..\..\..\Data\DrawingTemplate.pdf"); //Create one page PdfPageBase page = pdf.Pages[0]; //Save graphics state PdfGraphicsState state = page.Canvas.Save(); //Draw rectangles int x = 200; int y = 300; int width = 200; int height = 100; PdfPen pen = new PdfPen(Color.Black, 1f); PdfBrush brush = new PdfSolidBrush(Color.Red); PdfBlendMode mode = new PdfBlendMode(); page.Canvas.SetTransparency(0.5f, 0.5f, mode); page.Canvas.DrawRectangle(pen, brush, new Rectangle(new Point(x, y), new Size(width, height))); x = x + width / 2; y = y - height / 2; page.Canvas.SetTransparency(0.2f, 0.2f, mode); page.Canvas.DrawRectangle(pen, brush, new Rectangle(new Point(x, y), new Size(width, height))); //Restor graphics page.Canvas.Restore(state); String result = "SetRectangleTransparency_out.pdf"; //Save the document pdf.SaveToFile(result); //Launch the Pdf file PDFDocumentViewer(result); }
private void button1_Click(object sender, EventArgs e) { PdfDocument pdf = new PdfDocument(); pdf.LoadFromFile(@"..\..\..\..\..\..\Data\DrawingTemplate.pdf"); //Create one page PdfPageBase page = pdf.Pages[0]; //Save graphics state PdfGraphicsState state = page.Canvas.Save(); //Draw line //Set location and size float x = 95; float y = 95; float width = 400; float height = 500; //Create pens PdfPen pen = new PdfPen(Color.Black, 0.1f); PdfPen pen1 = new PdfPen(Color.Red, 0.1f); //Draw a rectangle page.Canvas.DrawRectangle(pen, x, y, width, height); //Draw two crossed lines page.Canvas.DrawLine(pen1, x, y, x + width, y + height); page.Canvas.DrawLine(pen1, x + width, y, x, y + height); //Restore graphics page.Canvas.Restore(state); String result = "DrawLine_out.pdf"; //Save the document pdf.SaveToFile(result); //Launch the Pdf file PDFDocumentViewer(result); }
private void RotateText(PdfPageBase page) { //save graphics state PdfGraphicsState state = page.Canvas.Save(); //Draw the text - transform PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 10f); PdfSolidBrush brush = new PdfSolidBrush(Color.Blue); PdfStringFormat centerAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); float x = page.Canvas.ClientSize.Width / 2; float y = 380; page.Canvas.TranslateTransform(x, y); for (int i = 0; i < 12; i++) { page.Canvas.RotateTransform(30); page.Canvas.DrawString("Go! Turn Around! Go! Go! Go!", font, brush, 20, 0, centerAlignment); } //restor graphics page.Canvas.Restore(state); }