Knowledgebase (2311)
Children categories
A Sound action is used to embed and play a sound file in PDF document. In Spire.PDF, we can create a sound action by using the PdfSoundAction class. Attributes like sound, volume and repeat can be specified for the sound action.
Refer below code example:
Step 1: Create a new PDF document and add a page to it.
PdfDocument document = new PdfDocument(); PdfPageBase page = document.Pages.Add();
Step 2: Create a sound action and set its attributes.
PdfSoundAction soundAction = new PdfSoundAction(@"C:\Users\Administrator\Desktop\because of you.wav"); soundAction.Sound.Bits = 15; soundAction.Sound.Channels = PdfSoundChannels.Stereo; soundAction.Sound.Encoding = PdfSoundEncoding.Signed; soundAction.Volume = 0.8f; soundAction.Repeat = true;
Step 3: Set the sound action to be executed when the PDF document is opened.
document.AfterOpenAction = soundAction;
Step 4: Save and close the PDF document.
document.SaveToFile("Output.pdf");
document.Close();
Full code:
using Spire.Pdf;
using Spire.Pdf.Actions;
using Spire.Pdf.General;
namespace PDF_Sound_Action
{
class Program
{
static void Main(string[] args)
{
//Create a new PDF document
PdfDocument document = new PdfDocument();
//Add a page
PdfPageBase page = document.Pages.Add();
//Create a sound action
PdfSoundAction soundAction = new PdfSoundAction(@"C:\Users\Administrator\Desktop\because of you.wav");
soundAction.Sound.Bits = 15;
soundAction.Sound.Channels = PdfSoundChannels.Stereo;
soundAction.Sound.Encoding = PdfSoundEncoding.Signed;
soundAction.Volume = 0.8f;
soundAction.Repeat = true;
// Set the sound action to be executed when the PDF document is opened
document.AfterOpenAction = soundAction;
//Save and close the PDF document
document.SaveToFile("Output.pdf");
document.Close();
}
}
}
When designing magazines or newspapers, you may need to display content in multiple columns on a single page to improve readability. In this article, you will learn how to programmatically create a two-column PDF from scratch using Spire.PDF for .NET.
Install Spire.PDF for .NET
To begin with, you need to add the DLL files included in the Spire.PDF for .NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.PDF
Create a Two-Column PDF from Scratch in C# and VB.NET
Spire.PDF for .NET allows you to create a two-column PDF by drawing text at two separate rectangle areas in a PDF page. Below are the detailed steps to achieve the task.
- Create a PdfDocument instance.
- Add a new page in the PDF using PdfDocument.Pages.Add() method.
- Define paragraph text, then set the text font and text alignment.
- Draw text at two separate rectangle areas in the PDF using PdfPageBase.Canvas.DrawString (String, PdfFontBase, PdfBrush, RectangleF, PdfStringFormat) method.
- Save the result file using PdfDocument.SaveToFile() method.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace CreateTwoColumnPDF
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument instance
PdfDocument doc = new PdfDocument();
//Add a new page
PdfPageBase page = doc.Pages.Add();
//Define paragraph text
string s1 = "Spire.PDF for .NET is a professional PDF component applied to creating, writing, "
+ "editing, handling and reading PDF files without any external dependencies within "
+ ".NET application. Using this .NET PDF library, you can implement rich capabilities "
+ "to create PDF files from scratch or process existing PDF documents entirely through "
+ "C#/VB.NET without installing Adobe Acrobat.";
string s2 = "Many rich features can be supported by the .NET PDF API, such as security setting "
+ "(including digital signature), PDF text/ attachment/ image extract, PDF merge/ split "
+ ", metadata update, section, graph/ image drawing and inserting, table creation and "
+ "processing, and importing data etc.Besides, Spire.PDF for .NET can be applied to easily "
+ "converting Text, Image and HTML to PDF with C#/VB.NET in high quality.";
//Get width and height of page
float pageWidth = page.GetClientSize().Width;
float pageHeight = page.GetClientSize().Height;
//Create a PdfSolidBrush instance
PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.Black));
//Create a PdfFont instance
PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 14f);
//Set the text alignment via PdfStringFormat class
PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);
//Draw text
page.Canvas.DrawString(s1, font, brush, new RectangleF(0, 20, pageWidth / 2 - 8f, pageHeight),format);
page.Canvas.DrawString(s2, font, brush, new RectangleF(pageWidth / 2 + 8f, 20, pageWidth / 2, pageHeight), format);
//Save the result document
doc.SaveToFile("CreateTwoColumnPDF.pdf.pdf");
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Whether to display the additional information for presentation slides on header and footer area
2017-03-09 07:15:10 Written by KoohjiWhen we operate the Microsoft PowerPoint documents, we can set whether to show some additional information of slides to readers, such as “Date and Time”, “Slide number” and footer. This article will demonstrate how to set whether to show these information to readers in C# with the help of Spire.Presentation.
Firstly, view the screenshot of the property of slide appearance on the header and footer area.

Step 1: Create a presentation instance and load the document from file.
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);
Step 2: Set the appearance property for slide number, footer and date time.
ppt.SlideNumberVisible = true; ppt.FooterVisible = false; ppt.DateTimeVisible = false;
Step 3: Save the document to file.
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);
Effective screenshot of the slide appearance on header and footer area.

Full codes of how to set the additional information of presentation slides’ header and footer area:
using Spire.Presentation;
using Spire.Xls;
namespace AdditionalInfo
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);
ppt.SlideNumberVisible = true;
ppt.FooterVisible = false;
ppt.DateTimeVisible = false;
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);
}
}
}