public IActionResult CreateDocument() { //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("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.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 = "Sample.pdf"; return(fileStreamResult); //return View(); }
private void Draw(PdfGraphics g, PdfObjects.Image image) { using (var stream = new FileStream(image.ImagePath, FileMode.Open)) { using (var bitmap = new PdfBitmap(stream)) { float x = (float)image.Layout.X; float y = (float)image.Layout.Y; float width = (float)image.Layout.Width; float height = (float)image.Layout.Height; if (image.PreserveRatio) { height = bitmap.Height * (width / bitmap.Width); // If we went the wrong way if (height > image.Layout.Height) { height = (float)image.Layout.Height; width = bitmap.Width * (height / bitmap.Height); } } g.DrawImage(bitmap, new PointF(x, y), new SizeF(width, height)); } } }
private void Print_Click(object sender, RoutedEventArgs e) { try { foreach (Product product in dataBase.Products) { getAllProducts += $"{product.Barcode,-25}{product.Price,-22}{product.CountOnShelf,-22}{product.CountInStorage,-22}{product.Name} \n"; } using (PdfDocument document = new PdfDocument()) { PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); graphics.DrawString(getAllProducts, font, PdfBrushes.Black, new PointF(0, 0)); document.Save("Products State.pdf"); } System.Diagnostics.Process.Start("Products State.pdf"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void createPDF() { 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("Estatistica Baliza Facil \n\n" + GetStatistics(), font, PdfBrushes.Black, new PointF(0, 0)); 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 email.SaveAndView("Estatisticas.pdf", "application/pdf", stream, Storage.Username, Storage.Car.Name + " " + Storage.Car.Style); }
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); } }
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(); }
/// <summary> /// Create a simple PDF document /// </summary> /// <returns>Return the created PDF document as stream</returns> public MemoryStream CreatePdfDocument() { //Create a new PDF document PdfDocument document = new PdfDocument(); //Add a page 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)); //Set the font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36); //Draw the text g.DrawString("Hello world!", font, brush, new PointF(20, 20)); //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); }
private void DrawRectangles(PointF startPoint, PdfGraphics g, PdfFont font, PdfBrush brush, PdfPen pen, PdfDocument doc) { PdfBrush textBrush = new PdfSolidBrush(Color.Black); RectangleF rect = new RectangleF(startPoint.X, startPoint.Y, 100, 100); g.Save(); g.DrawString("Default: " + doc.ColorSpace.ToString(), font, textBrush, rect.Location); rect.Y += 20; g.DrawRectangle(pen, brush, rect); rect.Y += 106; doc.ColorSpace = PdfColorSpace.RGB; g.DrawString("RGB color space.", font, textBrush, rect.Location); rect.Y += 20; g.DrawRectangle(pen, brush, rect); rect.Y += 106; doc.ColorSpace = PdfColorSpace.CMYK; g.DrawString("CMYK color space.", font, textBrush, rect.Location); rect.Y += 20; g.DrawRectangle(pen, brush, rect); rect.Y += 106; doc.ColorSpace = PdfColorSpace.GrayScale; g.DrawString("Gray scale color space.", font, textBrush, rect.Location); rect.Y += 20; g.DrawRectangle(pen, brush, rect); rect.Y += 106; g.Restore(); }
// funcion que genera el pdf de la factura // Entrada: la entrada son los datos de la factura a generar // Salida: como saida es un memoryStream con el documento // Restricciones: la factura no puede ser nula public static MemoryStream crearPDFFactura(Factura factura) { 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 FechaCompra = DateTime.Now.ToString("yyy-MM-dd"); Dispositivo disp = usuarioActual.lista_Disp_Usuario[usuarioActual.lista_Disp_Usuario.Count - 1]; graphics.DrawString("Factura SmartHomeTEC", font, PdfBrushes.Black, new PointF(0, 0)); graphics.DrawString("Numero de Factura: 1254875966541231485" + numeroFacturas, font2, PdfBrushes.Black, new PointF(0, 40)); graphics.DrawString("Fecha de compra: " + FechaCompra, font2, PdfBrushes.Black, new PointF(0, 80)); graphics.DrawString("Tipo Dispositivo: " + disp.tipo.nombre + ".", font2, PdfBrushes.Black, new PointF(0, 120)); graphics.DrawString("Precio: " + disp.precio + " Colones.", font2, PdfBrushes.Black, new PointF(0, 160)); graphics.DrawString("Datos Factura: ", font2, PdfBrushes.Black, new PointF(0, 200)); graphics.DrawString(" Nombre: " + factura.nombre + " " + factura.apellido + ".", font2, PdfBrushes.Black, new PointF(0, 240)); graphics.DrawString(" Direccion: " + factura.direccionfacturacion + ".", font2, PdfBrushes.Black, new PointF(0, 280)); graphics.DrawString(" Codigo Postal: " + factura.codigoPostal, font2, PdfBrushes.Black, new PointF(0, 320)); graphics.DrawString(" Celular: " + factura.celular, font2, PdfBrushes.Black, new PointF(0, 360)); MemoryStream stream = new MemoryStream(); document.Save(stream); stream.Position = 0; document.Close(true); return(stream); }
public ActionResult CreateDocument() { //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("Hello World!!!", 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; Console.WriteLine("LALA"); //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); fileStreamResult.FileDownloadName = "Output.pdf"; return(fileStreamResult); }
public ActionResult HelloWorld(string Browser) { document = new PdfDocument(); //Add a page PdfPage page = document.Pages.Add(); //Create Pdf graphics for the page PdfGraphics g = page.Graphics; //Create a solid brush PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.Black); //Set the font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36); //Draw the text g.DrawString("Hello world!", font, brush, new PointF(20, 20)); //Stream the output to the browser. if (Browser == "Browser") { return(document.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(document.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
async void ValidateSignatureAndUpload() { Dialog.ShowLoading(""); if (Contract.SignImageSource != null) { PdfDocument duplicate = (PdfDocument)Contract.Document.Clone(); var addPage = duplicate.Pages.Add(); var width = addPage.GetClientSize().Width; PdfGraphics graphics = addPage.Graphics; PdfBitmap image = new PdfBitmap(new MemoryStream(contract.SignImageSource)); graphics.DrawImage(image, new RectangleF(20, 40, width / 2, 60)); MemoryStream m = new MemoryStream(); duplicate.Save(m); var document = await StoreManager.DocumentStore.GetItemByContractId(Contract.Id, "saleContract"); if (document == null) { var documentItem = new Document() { Path = Contract.Id + '/' + "saleContract.pdf", Name = contract.Id + ".pdf", InternalName = "saleContract", ReferenceKind = "contract", ReferenceId = contract.Id, MimeType = "application/pdf" }; var uploaded = await StoreManager.DocumentStore.InsertImage(m.ToArray(), documentItem); } else { await PclStorage.SaveFileLocal(m.ToArray(), document.Id); document.ToUpload = true; await StoreManager.DocumentStore.UpdateAsync(document); await StoreManager.DocumentStore.OfflineUploadSync(); } Contract.ToSend = true; var isSent = await StoreManager.ContractStore.UpdateAsync(Contract); if (isSent) { await CoreMethods.DisplayAlert(AppResources.Alert, AppResources.EmailSent, AppResources.Ok); BackButton.Execute(null); } } Dialog.HideLoading(); }
/// <summary> /// Draws footer to the document. /// </summary> private PdfPageTemplateElement AddFooter(float width, string footerText) { RectangleF rect = new RectangleF(0, 0, width, 50); //Create a new instance of PdfPageTemplateElement class. PdfPageTemplateElement footer = new PdfPageTemplateElement(rect); PdfGraphics g = footer.Graphics; // Draw footer text. PdfSolidBrush brush = new PdfSolidBrush(Color.Gray); PdfFont font = new PdfTrueTypeFont(new Font("Helvetica", 6, FontStyle.Bold), true); float x = (width / 2) - (font.MeasureString(footerText).Width) / 2; g.DrawString(footerText, font, brush, new RectangleF(x, g.ClientSize.Height - 10, font.MeasureString(footerText).Width, font.Height)); //Create page number field PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); //Create page count field PdfPageCountField count = new PdfPageCountField(font, brush); PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count); compositeField.Bounds = footer.Bounds; compositeField.Draw(g, new PointF(470, 40)); return(footer); }
static SizeF PrepareGraphics(PdfPage page, PdfGraphics graphics) { PdfRectangle cropBox = page.CropBox; float cropBoxWidth = (float)cropBox.Width; float cropBoxHeight = (float)cropBox.Height; switch (page.Rotate) { case 90: graphics.RotateTransform(-90); graphics.TranslateTransform(-cropBoxHeight, 0); return(new SizeF(cropBoxHeight, cropBoxWidth)); case 180: graphics.RotateTransform(-180); graphics.TranslateTransform(-cropBoxWidth, -cropBoxHeight); return(new SizeF(cropBoxWidth, cropBoxHeight)); case 270: graphics.RotateTransform(-270); graphics.TranslateTransform(0, -cropBoxWidth); return(new SizeF(cropBoxHeight, cropBoxWidth)); } return(new SizeF(cropBoxWidth, cropBoxHeight)); }
private void ticketsList_DoubleClick(object sender, EventArgs e) { if (ticketsList.SelectedItems.Count != 0) { Ticket ticket = (Ticket)ticketsList.SelectedItems[0].Tag; DialogResult confirmResult = MessageBox.Show(ticket.ToString(), "Save ticket to Pdf?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirmResult == DialogResult.Yes) { // create pdf ticket using (PdfDocument document = new PdfDocument()) { PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); graphics.DrawString(ticket.ToString(), font, PdfBrushes.Black, new PointF(0, 0)); if (saveFileDialog1.ShowDialog() == DialogResult.OK) { if (saveFileDialog1.FileName != "") { System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile(); document.Save(fs); fs.Close(); } } } } } }
public void SaveToPDF(string fileName) { RenderTargetBitmap renderBitmap = new RenderTargetBitmap( (int)GraphCanvas.ActualWidth, (int)GraphCanvas.ActualHeight, 96d, 96d, PixelFormats.Pbgra32); GraphCanvas.Measure(new Size((int)GraphCanvas.ActualWidth, (int)GraphCanvas.ActualHeight)); GraphCanvas.Arrange(new Rect(new Size((int)GraphCanvas.ActualWidth, (int)GraphCanvas.ActualHeight))); renderBitmap.Render(GraphCanvas); using (PdfDocument document = new PdfDocument()) { PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; using (var ms = new MemoryStream()) { PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(renderBitmap)); encoder.Save(ms); PdfBitmap image = new PdfBitmap(ms); graphics.DrawImage(image, 0, 0); document.Save(fileName); } } }
public PrintBill(ObservableCollection <printBillData> finalBillOrderPrint, string name, string total) { PdfDocument doc = new PdfDocument(); PdfPage page = doc.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20); PdfFont font2 = new PdfStandardFont(PdfFontFamily.TimesRoman, 10); PdfFont font3 = new PdfStandardFont(PdfFontFamily.Courier, 7); PdfPen pen = new PdfPen(System.Drawing.Color.Black); graphics.DrawString("High on Flavours", font, PdfBrushes.Black, new PointF(190, 0)); graphics.DrawString("experience India ...", font2, PdfBrushes.Black, new PointF(300, 20)); graphics.DrawString("Bonhoefferstraße 4/1, 69123 Heidelberg", font3, PdfBrushes.Black, new PointF(185, 40)); graphics.DrawString("Ph no: +49 12345678910 Email: [email protected]", font3, PdfBrushes.Black, new PointF(150, 50)); graphics.DrawLine(pen, new PointF(0, 60), new PointF(950, 60)); graphics.DrawLine(pen, new PointF(0, page.Graphics.ClientSize.Height - 100), new PointF(950, page.Graphics.ClientSize.Height - 100)); graphics.DrawString("Total: " + total + " EURO", font2, PdfBrushes.Black, new PointF(400, page.Graphics.ClientSize.Height - 80)); PdfGrid grid = new PdfGrid(); grid.DataSource = finalBillOrderPrint; PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Layout = PdfLayoutType.OnePage; PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, 75), new SizeF(page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 100)), layoutFormat); doc.Save(name + ".pdf"); System.Diagnostics.Process.Start(name + ".pdf"); doc.Close(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) { //Create a new document. PdfDocument doc = new PdfDocument(); //Add a page PdfPage page = doc.Pages.Add(); //Create Pdf graphics for the page PdfGraphics g = page.Graphics; //Create a solid brush PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.FromArgb(255, 0, 0, 0)); //Set the font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 36); //Draw the text g.DrawString("Hello world!", font, brush, new PointF(20, 20)); MemoryStream stream = new MemoryStream(); await doc.SaveAsync(stream); doc.Close(true); Save(stream, "GettingStarted.pdf"); }
public byte[] TiffToPDF(Stream file) { _logger.LogDebug($"Start convert tiff file"); byte[] buff; try { using (MemoryStream memoryStream = new MemoryStream()) using (PdfDocument document = new PdfDocument()) { document.PageSettings.Margins.All = 0; PdfTiffImage tiffImage = new PdfTiffImage(file); int frameCount = tiffImage.FrameCount; for (int i = 0; i < frameCount; i++) { PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; tiffImage.ActiveFrame = i; graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height); } document.Save(memoryStream); memoryStream.Position = 0; buff = memoryStream.ToArray(); _logger.LogDebug("FileInfoPDFService.TiffToPDF....OK"); return(buff); } } catch (Exception ex) { _logger.LogError(ex.Message); } return(null); }
private void printClients_Click(object sender, RoutedEventArgs e) { int countClients = 0; try { foreach (Client client in dataBase.Clients) { getAllClients += $"{client.ClientId,-35}{client.FirstName,-22}{client.LastName,-22}{client.Email} \n"; countClients++; } countClients--; getAllClients += $"\nThe Number of Clients is: " + countClients; using (PdfDocument document = new PdfDocument()) { PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); graphics.DrawString(getAllClients, font, PdfBrushes.Black, new PointF(0, 0)); document.Save("Clients State.pdf"); } System.Diagnostics.Process.Start("Clients State.pdf"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public byte[] ImageToPDF(Stream file) { _logger.LogDebug($"Start convert image files"); byte[] buff; try { using (MemoryStream memoryStream = new MemoryStream()) using (PdfDocument document = new PdfDocument()) { PdfPage page = document.Pages.Add(); PdfGraphics pdfGraphics = page.Graphics; PdfBitmap image = new PdfBitmap(file); pdfGraphics.DrawImage(image, 0, 0); document.Save(memoryStream); memoryStream.Position = 0; buff = memoryStream.ToArray(); _logger.LogDebug("FileInfoPDFService.ImageToPDF....OK"); return(buff); } } catch (Exception ex) { _logger.LogError(ex.Message); } return(null); }
static void DrawImage(PdfGraphics graphics, PdfRectangle rect, double x, double y) { Bitmap image = new Bitmap("..\\..\\AddressFormField.png"); double aspectRatio = image.Width / image.Height; double scaleX = image.Width / rect.Width; double scaleY = image.Height / rect.Height; double width; double height; if (scaleX < scaleY) { width = rect.Width; height = width / aspectRatio; } else { height = rect.Height; width = height * aspectRatio; } RectangleF imageRect = new RectangleF((float)x, (float)(y - height), (float)width, (float)height); graphics.DrawImage(image, imageRect); }
public void DrawImage(Bitmap image, string noi_luu) { using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) { documentProcessor.LoadDocument(fileName); DevExpress.Pdf.PdfPage page = documentProcessor.Document.Pages[pdfViewer1.CurrentPageNumber - 1]; using (PdfGraphics graphics = documentProcessor.CreateGraphics()) { float width = (float)Math.Abs(startPosition.Point.X - endPosition.Point.X); float height = (float)Math.Abs(startPosition.Point.Y - endPosition.Point.Y); PdfRectangle cropbox = page.CropBox; // MessageBox.Show(cropbox.Height.ToString()); float Y = (float)(cropbox.Height - startPosition.Point.Y); RectangleF rec = new RectangleF((float)startPosition.Point.X, Y, width, height); // RectangleF test = new RectangleF(10, 30, width, height); graphics.DrawImage(image, rec); graphics.AddToPageForeground(page, 72, 72); } documentProcessor.SaveDocument(noi_luu); LoadPDFFile(noi_luu); } }
private static void DrawHorizontalLines(PdfGraphics g, PdfPen pen, double x, double y, double width, double height) { for (double i = 0; i < height; i = i + 5) { g.DrawLine(pen, x, y + i, x + width, y + i); } }
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 Confirm_Report_Form_Click(object sender, RoutedEventArgs e) { using (PdfDocument document = new PdfDocument()) { //Add a page to the document PdfPage page = document.Pages.Add(); //Create PDF graphics for a page PdfGraphics graphics = page.Graphics; //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); //Save the document document.Save("Output.pdf"); } MedicationList medPage = new MedicationList(); medPage.Show(); this.Close(); }
static void DrawFormFields(PdfGraphics graphics) { // Create a text box field and specify its location on the page. PdfGraphicsAcroFormTextBoxField textBox = new PdfGraphicsAcroFormTextBoxField("text box", new RectangleF(30, 10, 200, 30)); // Specify text box text, and appearance. textBox.Text = "Text Box"; textBox.Appearance.FontSize = 12; textBox.Appearance.BackgroundColor = Color.AliceBlue; // Add the text box field to graphics. graphics.AddFormField(textBox); // Create a radio group field. PdfGraphicsAcroFormRadioGroupField radioGroup = new PdfGraphicsAcroFormRadioGroupField("First Group"); // Add the first radio button to the group and specify its location using a RectangleF object. radioGroup.AddButton("button1", new RectangleF(30, 60, 20, 20)); // Add the second radio button to the group. radioGroup.AddButton("button2", new RectangleF(30, 90, 20, 20)); // Specify radio group selected index, and appearance. radioGroup.SelectedIndex = 0; radioGroup.Appearance.BorderAppearance = new PdfGraphicsAcroFormBorderAppearance() { Color = Color.Red, Width = 3 }; // Add the radio group field to graphics. graphics.AddFormField(radioGroup); }
private static void AddWaterMark(PdfGraphics graphics, DrawText drawText, PointF pointF) { SizeF waterTextSize = graphics.MeasureString(drawText.Text, drawText.FontText, PdfStringFormat.GenericDefault, DrawIngDpi, DrawIngDpi); graphics.RotateTransform(degree);//55 vertical letter//40horizontar letter//65LegarV//30 LegalH graphics.DrawString(drawText.Text, drawText.FontText, drawText.SolidBrush, pointF); }
public MemoryStream GenerateGuide(int id) { using (MemoryStream ms = new MemoryStream()) { //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("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0)); //Saving the PDF to the MemoryStream document.Save(ms); //Set the position as '0'. ms.Position = 0; //Download the PDF document in the browser return(ms); } }