How to Create Barcode in PDF Barcode is an optical machine-readable representation of data, which shows data about the object to which it attaches. Sometimes, we may have requirements on drawing barcode into different files like PDF, Word. The first use of barcodes was to label railroad cars, but they were not commercially successful until they were used to automate supermarket checkout systems, a task for which they have become almost universal. Their use has spread to many other tasks that are generically referred to as Auto ID Data Capture (AIDC). The very first scanning of the now ubiquitous Universal Product Code (UPC) barcode was on a pack of Wrigley Company chewing gum in June 1974. PDF, as one of the most popular file formats, allows barcode embedded in. This post will show you how to create barcode in PDF document via C#. Tools We Need: - Spire.PDF - Visual Studio Tool Introduction: Spire.PDF is a PDF document creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Download Spire.PDF Here. Make sure Spire.PDF and Visual Studio are correctly installed on system. Follow the instructions below to create barcode in PDF via C#. Step 1 Create Project Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under “C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. using System.Drawing; using Spire.Pdf; using Spire.Pdf.Graphics; using Spire.Pdf.Barcode; namespace Barcode { class Program { static void Main(string[] args) { } } } Step 2 Create a PDF Document Spire.PDF allows users to create PDF with content. Here we can create a PDF for later usage on creating barcode. //Create a pdf document. PdfDocument doc = new PdfDocument(); //margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; PdfSection section = doc.Sections.Add(); section.PageSettings.Margins = margin; section.PageSettings.Size = PdfPageSize.A4; // Create one page PdfPageBase page = section.Pages.Add(); float y = 10; PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold), true); RectangleF rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize); PdfLinearGradientBrush brush2 = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vert ical); Step 3 Create Barcode in PDF With Spire.PDF, users can create different barcodes in PDF document. Follow the samples below. //Create Codebar PdfTextWidget text = new PdfTextWidget(); text.Font = font1; text.Text = "Codabar:"; PdfLayoutResult result = text.Draw(page, 0, y); page = result.Page; y = result.Bounds.Bottom + 2; PdfCodabarBarcode barcode1 = new PdfCodabarBarcode("00:12-3456/7890"); barcode1.BarcodeToTextGapHeight = 1f; barcode1.EnableCheckDigit = true; barcode1.ShowCheckDigit = true; barcode1.TextDisplayLocation = TextLocation.Bottom; barcode1.TextColor = Color.Blue; barcode1.Draw(page, new PointF(0, y)); y = barcode1.Bounds.Bottom + 5; //Create Code11Barcode text.Text = "Code11:"; result = text.Draw(page, 0, y); page = result.Page; y = result.Bounds.Bottom + 2; PdfCode11Barcode barcode2 = new PdfCode11Barcode("123-4567890"); barcode2.BarcodeToTextGapHeight = 1f; barcode2.TextDisplayLocation = TextLocation.Bottom; barcode2.TextColor = Color.Blue; barcode2.Draw(page, new PointF(0, y)); y = barcode2.Bounds.Bottom + 5; //Create Code128-A text.Text = "Code128-A:"; result = text.Draw(page, 0, y); page = result.Page; y = result.Bounds.Bottom + 2; PdfCode128ABarcode barcode3 = new PdfCode128ABarcode("HELLO 00-123"); barcode3.BarcodeToTextGapHeight = 1f; barcode3.TextDisplayLocation = TextLocation.Bottom; barcode3.TextColor = Color.Blue; barcode3.Draw(page, new PointF(0, y)); y = barcode3.Bounds.Bottom + 5; //Create Code128-B text.Text = "Code128-B:"; result = text.Draw(page, 0, y); page = result.Page; y = result.Bounds.Bottom + 2; PdfCode128BBarcode barcode4 = new PdfCode128BBarcode("Hello 00-123"); barcode4.BarcodeToTextGapHeight = 1f; barcode4.TextDisplayLocation = TextLocation.Bottom; barcode4.TextColor = Color.Blue; barcode4.Draw(page, new PointF(0, y)); y = barcode4.Bounds.Bottom + 5; //Create Code32 text.Text = "Code32:"; result = text.Draw(page, 0, y); page = result.Page; y = result.Bounds.Bottom + 2; PdfCode32Barcode barcode5 = new PdfCode32Barcode("16273849"); barcode5.BarcodeToTextGapHeight = 1f; barcode5.TextDisplayLocation = TextLocation.Bottom; barcode5.TextColor = Color.Blue; barcode5.Draw(page, new PointF(0, y)); y = barcode5.Bounds.Bottom + 5; page = section.Pages.Add(); y = 10; //Create Code39 text.Text = "Code39:"; result = text.Draw(page, 0, y); page = result.Page; y = result.Bounds.Bottom + 2; PdfCode39Barcode barcode6 = new PdfCode39Barcode("16-273849"); barcode6.BarcodeToTextGapHeight = 1f; barcode6.TextDisplayLocation = TextLocation.Bottom; barcode6.TextColor = Color.Blue; barcode6.Draw(page, new PointF(0, y)); y = barcode6.Bounds.Bottom + 5; //Create Code39-E text.Text = "Code39-E:"; result = text.Draw(page, 0, y); page = result.Page; y = result.Bounds.Bottom + 2; PdfCode39ExtendedBarcode barcode7 = new PdfCode39ExtendedBarcode("16-273849"); barcode7.BarcodeToTextGapHeight = 1f; barcode7.TextDisplayLocation = TextLocation.Bottom; barcode7.TextColor = Color.Blue; barcode7.Draw(page, new PointF(0, y)); y = barcode7.Bounds.Bottom + 5; //Create Code93 text.Text = "Code93:"; result = text.Draw(page, 0, y); page = result.Page; y = result.Bounds.Bottom + 2; PdfCode93Barcode barcode8 = new PdfCode93Barcode("16-273849"); barcode8.BarcodeToTextGapHeight = 1f; barcode8.TextDisplayLocation = TextLocation.Bottom; barcode8.TextColor = Color.Blue; barcode8.QuietZone.Bottom = 5; barcode8.Draw(page, new PointF(0, y)); y = barcode8.Bounds.Bottom + 5; //Create Code93-E text.Text = "Code93-E:"; result = text.Draw(page, 0, y); page = result.Page; y = result.Bounds.Bottom + 2; PdfCode93ExtendedBarcode barcode9 = new PdfCode93ExtendedBarcode("16-273849"); barcode9.BarcodeToTextGapHeight = 1f; barcode9.TextDisplayLocation = TextLocation.Bottom; barcode9.TextColor = Color.Blue; barcode9.Draw(page, new PointF(0, y)); y = barcode9.Bounds.Bottom + 5; Step 4 Save and Preview //Save pdf file doc.SaveToFile("Barcode.pdf"); doc.Close(); //Launching the Pdf file System.Diagnostics.Process.Start("Barcode.pdf"); Effective Screenshot More about Spire.PDF
Spire.PDF can be used on the server-side (ASP.NET or any other environment) or with Windows Forms applications.Click to learn more... How to Extract Text from PDF Compare with other popular file formats, PDF is secure to protect document from unauthorized using. But sometimes, if the author wants to use the content from his/her PDF document, it will be some kind of difficult because he/she can not simply copy PDF content and past out into clipboard. Here in this article, you will find a solution to extract text from PDF by easily using C#. How to Extract Text from PDF via C# Through the help of Spire.PDF, a powerful and professional PDF document creation component, users can easily use C# to extract text from PDF. Download Spire.PDF and install on system. Follow the simple steps below to extract PDF text. Step 1 Create Project Create a C# windows form project in visual studio. Drag a button on and add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. using System; using System.IO; using System.Drawing; using System.Collections.Generic; using System.Text; using Spire.Pdf; namespace ExtractPDFIMG { class Program { static void Main(string[] args) { } } } Step 2 Load PDF File Put the PDF file which we need extract text content out from into the project folder and use the code below to load it into the project. //Create a pdf document PdfDocument doc = new PdfDocument(); doc.LoadFromFile(@"..\..\Sample.pdf"); Step 3 Extract Text from PDF Spire.PDF presents an easy solution to extract text from PDF. Use the simple code below, we can do this job effortlessly. StringBuilder buffer = new StringBuilder(); foreach (PdfPageBase page in doc.Pages) { buffer.Append(page.ExtractText()); } Step 4 Save Text Content After finish extracting PDF text, Spire.PDF can help us save the text content into a .text file. //save text String fileName = "TextInPdf.txt"; File.WriteAllText(fileName, buffer.ToString()); Press F5 to start the project. A text file will be generated in project folder bin -> debug. Original text: Output Text: Spire.PDF can also easily extract images from PDF. And it supports saving output images as most of popular image formats including PNG, JPEG, BMP, Tiff, etc.
More about Spire.PDF: Spire.PDF can be used on the server-side (ASP.NET or any other environment) or with Windows Forms applications. Click to learn more... How to Extract Images from PDF As one of the most popular file formats, PDF is great for exchanging formatted files across platforms and between folks who don't use the same software. But sometimes we may have the requirements to extract images from PDF and use them in Web pages or word processing documents. This article will show you a solution to extract images from PDF document by using C#. How to Extract Image from PDF via C# Spire.PDF, an all-ine-one PDF document creation component can help us easily use C# to extract image from PDF. Download Spire.PDF and install on system. Follow the simple instruction below to extract image from PDF. Step 1 Create a Project Create a C# windows form project in visual studio. Drag a button on and add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. using System; using System.IO; using System.Drawing; using System.Drawing.Imaging; using System.Collections.Generic; using System.Text; using Spire.Pdf; namespace ExtractPDFIMG { class Program { static void Main(string[] args) { } } } Step 2 Load PDF File Put the PDF file which we need extract images out from into the project folder and use the code below to load it into the project. //Create a pdf document PdfDocument doc = new PdfDocument(); doc.LoadFromFile(@"..\..\Sample.pdf"); Step 3 Extract Images The simple following code can help us easily extract images from PDF. StringBuilder buffer = new StringBuilder(); IList<Image> images = new List<Image>(); foreach (PdfPageBase page in doc.Pages) { foreach (Image image in page.ExtractImages()) { images.Add(image); } } Step 4 Save Images After Extract images from PDF, we need save and name the output images. //save image int index = 0; foreach (Image image in images) { String imageFileName = String.Format("Image-{0}.png", index++); image.Save(imageFileName, ImageFormat.Png); } Spire.PDF enables users to extract images from PDF and save as popular image format including PNG, JPEG, BMP, Tiff, etc. Press F5 to start the project. Then the images in PDF will be extracted and can be found at project folder bin ->debug. There are 7 images in original PDF file and we can find 7 images are all extracted. One Image from Original PDF: Output Image: Besides extracting images from PDF, Spire.PDF can also allow developers to extract text content from PDF with a few simple steps. Spire.PDF is a PDF document creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more...
How to Insert PDF Header Insert PDF a header can help readers to get more information about the whole content with a fast speed. PDF header can be simply a title, author’s name, file’s name, a date, page numbering, short description or other text content or even an image. This post will show you how to insert PDF header in .NET with C#. This sample will show you insert PDF header with text and image both. Tools We Need:
Tool Introduction: Spire.PDF is a PDF document creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Download Spire.PDF Here How to Insert PDF Header with Spire.Doc by Using C# Step 1 Create a Project Create a C# project in Visual Studio and add Spire.PDF.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. using System; using Spire.Pdf; namespace SplitPDF { class Program { static void Main(string[] args) { } } } Step 2 Create a PDF Document Spire.PDF enables developers to create PDF documents at will. Here we can create a PDF document as a text document. //create a pdfDocument PdfDocument doc = new PdfDocument(); //set the margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; Step 3 Insert PDF Header Spire.PDF allows users to insert PDF header with both text and image. Use the code below we can easily insert PDF header with text and image. Furthermore, we can use Spire.PDF to set the text styles. //insert text header in PDF PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic)); PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right); String label = "Demo of Spire.Pdf"; SizeF size = font.MeasureString(label, format); PdfPageTemplateElement topSpace = new PdfPageTemplateElement(PdfPageSize.A4.Width, margin.Top); topSpace.Foreground = true; doc.Template.Top = topSpace; float y = topSpace.Height - font.Height - 1; PdfPen pen = new PdfPen(Color.Black, 0.75f); topSpace.Graphics.SetTransparency(0.5f); topSpace.Graphics.DrawLine(pen, margin.Left, y, PdfPageSize.A4.Width - margin.Right, y); y = y - 1 - size.Height; topSpace.Graphics.DrawString(label, font, PdfBrushes.Black, PdfPageSize.A4.Width - margin.Right, y, format); doc.Template.Stamps.Add(topSpace); //insert image header in PDF PdfImage headerImage = PdfImage.FromFile(@"..\..\Header.png"); PointF pageLeftTop = new PointF(-margin.Left, -margin.Top); PdfPageTemplateElement header = new PdfPageTemplateElement(pageLeftTop, headerImage.PhysicalDimension); header.Foreground = false; header.Graphics.SetTransparency(0.5f); header.Graphics.DrawImage(headerImage, 0, 0); doc.Template.Stamps.Add(header); Step 4 Save and Launch At last, we can use the code below to save the PDF file with PDF header and launch the project to check the effect. //save file doc.SaveToFile("Sample.pdf"); doc.Close(); //Launching the Pdf file. System.Diagnostics.Process.Start("FromHTML.pdf"); Effective Screenshot More about Spire.PDF
Spire.PDF can be used on the server-side (ASP.NET or any other environment) or with Windows Forms applications. Click to learn more... How to Split PDF to Multiple Documents PDF is recognized as the most secure and dependable format around the world. Most of us keep many of our files in the PDF format especially those that we need to send over the internet. Once a file saved as PDF format, it can not be edited. Layout, formatting, images and everything else are protected. However sometimes we have to face a problem that we may just want to share a part of a PDF to others. So people who use PDF frequently may often meet questions like how to split a PDF file into multiple documents. Adobe Acrobat supports splitting PDF document into multiple documents. But here we will introduce another solution to split PDF document - C# split PDF. How to Use C# to Split PDF into Multiple Documents Spire.PDF can help us easily merge multiple PDF documents into one. Vice versa it can help us split PDF into multiple documents effortlessly either. Download Spire.PDF Here Make sure Spire.PDF and Visual Studio are correctly installed on system. Follow the simple guide below to split PDF into multiple documents. Step 1 Create Project Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. using System; using Spire.Pdf; namespace SplitPDF { class Program { static void Main(string[] args) { } } } Step 2 Open PDF Document Open the PDF document which we need spilt to multiple PDF documents //open pdf document PdfDocument doc = new PdfDocument(@"..\..\Sample.pdf"); Step 3 Split PDF Document We can split PDF document according to PDF pages. If a PDF document has 7 pages, we can split the PDF into 7 PDF documents. String pattern = "SplitDocument-{0}.pdf"; doc.Split(pattern); String lastPageFileName = String.Format(pattern, doc.Pages.Count - 1); doc.Close(); Step 4 Preview The code below can help us preview the last PDF document which was split out from the original PDF file. //Launching the Pdf file. System.Diagnostics.Process.Start(lastPageFileName); After start the project we will find out the split PDF documents in the project bin-> debug folder. More about Spire.PDF:
Spire.PDF can be used on the server-side (ASP.NET or any other environment) or with Windows Forms applications. Click to learn more… How to Add PDF Attachment Why Add PDF Attachment? This article for PDF developers is showing a method to add attachment in PDF via C#. PDF as one of the most popular file formats owns the ability to add attachments like e-mail message can carry attached files. PDF attachments are for electronic filing. They are mostly used for "hybrid files". For a PDF document previously created from a different application or a scanned document, such as a pay stub or legal property description, PDF developers can create a PDF attachment. In addition, sometimes users can use PDF attachment to make PDF as a file folder. How to Add PDF Attachment via C#? Use C# to add PDF attachment can be very easy through Spire.PDF a professional .NET/Silverlight PDF component. Download Spire.PDF and make sure Spire.PDF and Visual Studio are correctly installed on system. Follow the instructions below to add PDF attachment via C#. Step 1 Create a Project Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. using System; using Spire.Pdf; namespace attachment { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { } } } Step 2 Create PDF Document Use Spire.PDF to create a PDF document and generate a PDF page for adding PDF attachment. We can use Spire.PDF to set margin, title, etc. //Create a pdf document. PdfDocument doc = new PdfDocument(); //margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; //create section PdfSection section = doc.Sections.Add(); section.PageSettings.Size = PdfPageSize.A4; section.PageSettings.Margins = margin; // Create one page PdfPageBase page = section.Pages.Add(); float y = 10; //title PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold)); PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center); page.Canvas.DrawString("Attachment", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1); y = y + font1.MeasureString("Attachment", format1).Height;y = y + 5; Step 3 Add PDF Attachment with Annotation The code below will guide you to add images as attachment with annotation. //attachment PdfAttachment attachment = new PdfAttachment("Header.png"); attachment.Data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Header.png"); attachment.Description = "Page header picture of demo."; attachment.MimeType = "image/png"; doc.Attachments.Add(attachment); attachment = new PdfAttachment("Footer.png"); attachment.Data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Footer.png"); attachment.Description = "Page footer picture of demo."; attachment.MimeType = "image/png"; doc.Attachments.Add(attachment); PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold)); PointF location = new PointF(0, y); String label = "Sales Report Chart"; byte[] data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\SalesReportChart.png"); SizeF size = font2.MeasureString(label); RectangleF bounds = new RectangleF(location, size); page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds); bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height); PdfAttachmentAnnotation annotation1 = new PdfAttachmentAnnotation(bounds, "SalesReportChart.png", data); annotation1.Color = Color.Teal; annotation1.Flags = PdfAnnotationFlags.ReadOnly; annotation1.Icon = PdfAttachmentIcon.Graph; annotation1.Text = "Sales Report Chart"; (page as PdfNewPage).Annotations.Add(annotation1); y = y + size.Height + 2; location = new PointF(0, y); label = "Science Personification Boston"; data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\SciencePersonificationBoston.jpg"); size = font2.MeasureString(label); bounds = new RectangleF(location, size); page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds); bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height); PdfAttachmentAnnotation annotation2 = new PdfAttachmentAnnotation(bounds, "SciencePersonificationBoston.jpg", data); annotation2.Color = Color.Orange; annotation2.Flags = PdfAnnotationFlags.NoZoom; annotation2.Icon = PdfAttachmentIcon.PushPin; annotation2.Text = "SciencePersonificationBoston.jpg, from Wikipedia, the free encyclopedia"; (page as PdfNewPage).Annotations.Add(annotation2); y = y + size.Height + 2; location = new PointF(0, y); label = "Picture of Science"; data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Wikipedia_Science.png"); size = font2.MeasureString(label); bounds = new RectangleF(location, size); page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds); bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height); PdfAttachmentAnnotation annotation3 = new PdfAttachmentAnnotation(bounds, "Wikipedia_Science.png", data); annotation3.Color = Color.SaddleBrown; annotation3.Flags = PdfAnnotationFlags.Locked; annotation3.Icon = PdfAttachmentIcon.Tag; annotation3.Text = "Wikipedia_Science.png, from Wikipedia, the free encyclopedia"; (page as PdfNewPage).Annotations.Add(annotation3); y = y + size.Height + 2; location = new PointF(0, y); label = "Hawaii Killer Font"; data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Hawaii_Killer.ttf"); size = font2.MeasureString(label); bounds = new RectangleF(location, size); page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds); bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height); PdfAttachmentAnnotation annotation4 = new PdfAttachmentAnnotation(bounds, "Hawaii_Killer.ttf", data); annotation4.Color = Color.CadetBlue; annotation4.Flags = PdfAnnotationFlags.NoRotate; annotation4.Icon = PdfAttachmentIcon.Paperclip; annotation4.Text = "Hawaii Killer Font, from http://www.1001freefonts.com"; (page as PdfNewPage).Annotations.Add(annotation4); y = y + size.Height + 2; Step 4 Save and Preview After finish adding PDF attachment coding, use the code below to save and preview. Then, start the project and a PDF document will be generated with attachment. //Save pdf file doc.SaveToFile("Attachment.pdf"); doc.Close(); //Launching the Pdf file PDFDocumentViewer("Attachment.pdf"); private void PDFDocumentViewer(string fileName) { try { System.Diagnostics.Process.Start(fileName); } catch { } } Effective Screenshot: More about Spire.PDF:
Spire.PDF can be used on the server-side (ASP.NET or any other environment) or with Windows Forms applications. Click to learn more… How to Merge PDF Files Why Merge PDF Files
PDF developers or normal office workers may handle tons of PDF documents in a single day. With a large number of PDF files, they need an efficient way to work with the PDF files. When document management becomes an issue, merging selective PDFs together can make it easier to control the content of file folders. And this gives us an option of creating more organized PDF documents. In addition, we can maintain and improve our level of proficiency and decrease the amount of separate individual tasks by working with merged-and fewer PDF documents. How to Merge PDF Files Through Adobe Acrobat, users can merge PDF files together by opening all the PDF files which need to be merged and clicking the ‘Combine Files’ icon on the top left portion of the screen. However, we can merge PDF files without opening PDF files and Adobe Acrobat installed on system. By using Spire.PDF, we can easily use C# to merge PDF files. Download Spire.PDF Here Ensure Spire.PDF and Visual Studio correctly installed on system. Follow the simple steps below to merge PDF files into one. Step 1 Create a Project Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. using System; using Spire.Pdf; namespace MergePDF { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { } } } Step 2 Make PDF Document List Put all the PDF files into the project folder. List them in the project like the code below. //pdf document list String[] files = new String[] { @"Sample3.pdf", @"Sample2.pdf", @"Sample1.pdf" }; Step 3 Merge PDF Files Open all the PDF files in a New PDF document and import the pages into the new one. //open pdf documents PdfDocument[] docs = new PdfDocument[files.Length]; for (int i = 0; i < files.Length; i++) { docs[i] = new PdfDocument(files[i]); } //append document docs[0].AppendPage(docs[1]); //import page for (int i = 0; i < docs[2].Pages.Count; i = i + 2) { docs[0].InsertPage(docs[2], i); } Step 4 Save and Preview Use the code below to save and preview what we did. //Save pdf file. docs[0].SaveToFile("MergeDocuments.pdf"); //close foreach (PdfDocument doc in docs) { doc.Close(); } //Launching the Pdf file. System.Diagnostics.Process.Start("MergeDocuments.pdf"); After finish coding the whole project, press F5 to launch the project. Then, you can find the merged PDF document in the project bin->debug folder. More about Spire.PDF Spire.PDF is a PDF document creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more… How to Add Image Watermark in PDF Document Watermarks can help secure different documents like PDF. Text watermark is directly and easy to add. Image watermark can give readers nice impressions. Fortunately, the watermark feature in PDF does not limit to Text. Users can use this feature to add images such as a family crest or company logo to the document. And Spire.PDF, enables developers to use C# add both text watermarks and image watermarks. Here we will discuss how to use C# add Image watermarks in PDF document. (Click to consult how to se C# add text watermark) Tools: Visual Studio, Spire.PDF, basic programming knowledge Main Tool Introduction: Spire.PDF is a PDF document creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. It does not use any external libraries and is built from scratch in C#. Friendly Reminder: Please make sure Spire.PDF and Visual Studio are correctly installed on your system. Instructions: Step 1 Create a Project Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project. using System; using Spire.Pdf; namespace Imagewatermark { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { } } } Step 2 Create PDF Document Spire.PDF enables to create PDF documents with customized content. We can create a PDF document and set margins for later using on watermarks. //Create a pdf document. PdfDocument doc = new PdfDocument(); //margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; Step 3 C# Add Image Watermark in PDF After created a PDF document, create a PDF page and then add an image to be background image and this is the image watermark. // Create one page PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin); Image img = Image.FromFile(@"Background.png"); page.BackgroundImage = img; Step 4 Save and Preview The code below can help us save the file as .pdf format and preview after start the project. //Save pdf file. doc.SaveToFile("ImageWaterMark.pdf"); doc.Close(); //Launching the Pdf file. System.Diagnostics.Process.Start("ImageWaterMark.pdf"); Now, press F5 to start the project and an PDF document will be automatically generated. Effective Screenshot: More about Spire.PDF
Spire.PDF is a PDF document creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more… How to Export Data from DataTable to PDF Sometimes we may have the requirements to export data from Datatable to PDF. This post will describe how to export data information from Datatable to PDF. Download “Datatable to PDF” tool (100% Free, No Virus, No harm ware). Follow the simple instructions to Export Datatable to PDF. Step 1 Input Data Source In the below Connection String and Command Text boxes, input your data source and SQL command. Step 2 Load data source and preview in dataGridView Area Click “Load” button to load data source from Datatable and preview the data information in dataGridView area. Step 3 Check and Modify Data Information In the dataGridView Area, you can modify the information by double-clicking cell content. For example, we can change the cell (column gender, row 2) to female. Step 4 Export Datatable to PDF After make sure the all data information is correct, click “Run” button to export data to Excel. Check what we get: The “Datatable to PDF” tool is designed and created through the help of a Free Data Export Component. If you dislike my program, you can create one by yourself. To create a Data Export tool can be very easy by using that Free Data Export Component. Follow the guides below you can make one in a few minutes. Step1, Download the Free Data Export Component. This can help you save tons of time on programming. (The website requires register a member to download files) Step2, Create a WindowsFormsApplication via Visual Studio. Use Free Data Export Component (Spire.DataExport for .NET). Step3, Design windows components by yourself Step4, You can use this free data export component to create Datatable to PDF, Datatable to Excel, Datatable to HTML, Datatable to Word, Datatable to CSV, etc. |