Solution to Remove PDF Attachment in C# and Visual Basic

PDF attachment can be taken as assistant or supplement of document contents and help readers to learn more useful additional information. For example, one PDF document presents a famous novel and the attachment may be authors’ biography or the poster and review of film which is adapted from this novel. Of course, some attachments have nothing to do with document contents and these attachments can be removed in case readers will be confused about why the attachment appears. In this post, I want to introduce solutions to remove PDF attachment in C# and Visual Basic.

At the beginning, I prepare a PDF document with four attachments and a .NET PDF component, Spire.PDF for .NET to realize the function much easier and faster. So, before coding, I add its dll file as reference in my project.

Load PDF

Initialize a new PdfDocument instance and invoke LoadFromFile method of PdfDocument class to load the prepared PDF.


            PdfDocument document = new PdfDocument();

            document.LoadFromFile(@”E:\Work\Documents\PDF\Attachment Sample.pdf”);

Visual Basic

            Dim document As New PdfDocument()

            document.LoadFromFile(“E:\Work\Documents\PDF\Attachment Sample.pdf”)

Remove Attachment

We can choose to remove specified one or all attachments of PDF.

Remove One: invoke RemoveAt(int index) method of PdfAttachmentCollection class to remove. The following code presents to remove the first attachment.



Visual Basic


Remove All: invoke Clear() method of PdfAttachmentCollection class to remove all PDF attachments.



Visual Basic


Save PDF

Invoke SaveToFile method of PdfDocument class to save the document whose attachment has been removed and launch it.




Visual Basic




Download Spire.PDF for .NET

P.S The .NET Office component, Spire.Office for .NET can be used to realize this function as well.


What’s New of Acrobat XI

Adobe Acrobat, developed by Adobe, is the most frequently-used PDF editor. It is powerful on creating, editing and converting PDF documents. Through a long development, the latest version Acrobat XI had been released.

The featured new added function of Acrobat XI is to convert PDF to PowerPoint.

  • With Acrobat XI, PDF document can be quickly converted to PowerPoint (.pptx) for editing and updating with high-quality.
  • During conversion, the formats of original PDF will be saved as well, such as bullets, tables, layout and other objects.
  • You can select and export the needed information in PDF to PowerPoint quickly and easily.
  • You can copy and paste parts of PDF files into a new or existing PowerPoint presentation.

Other New Added:


Acrobat XI enables you to edit text and image much more conveniently.

For text, firstly, editing tools will appear immediately when you click the text you can to edit. Secondly, you can easily correct a typo, change a date or font and add new text in PDF. Thirdly, text can be simply added and deleted in existing paragraphs. Also, the paragraph box can be resized by dragging. Fourthly, just one step, you can find and replace text in PDF.

For image, the most appropriate editing tools will be automatically presented when you click the image. Also, the external editor like Photoshop can be used to edit image in PDF and image will be automatically updated once revised.


Acrobat XI is enables you to email the signed PDFs which can be signed, saved and sent back. And the online service, Adobe EchoSign is very helpful for collecting and tracking signatures.


Acrobat XI enables you to protect PDFs to prevent others from editing by checking Protect PDF box in Microsoft Office applications. And Encrypt tool and new Restrict Editing tool enables you to prevent others from opening, printing, commenting PDF and copying and editing contents.


Acrobat XI enables you to email, archive PDF which is merged from spreadsheets, web pages and photos, and send out for review. Before merging, you can arrange and preview files and individual pages to have a better organization.

Store and Access

Acrobat XI enables you to store PDFs on by activating your free account. These PDFs can be simply searched, filtered and sorted. Also, you can access these PDFs from your computer or mobile device.

Distribute, Collect and Analyze

Acrobat XI enables you to distribute PDF or web forms with FormsCentral. Once the PDF form is published for sharing, you can collect responses in tables so that you can search, sort, filter and even export data to spreadsheet or database application. Also, results will be automatically updated and presented in a summary report with symbols every time a recipient clicks Submit. You can save the report as PDF to analyze the result.

Besides new features, Acrobat XI was improved existing functions a lot. Please click here for more information:

Recommendation for developers: Professional and powerful .NET PDF component to manipulate PDF documents.

Manipulate (Remove/Edit/Extract) Excel Comments in C# and Visual Basic

I will add comment for cells with special data information in Excel. For example, the cell with manager name will be commented with “He/She is department manager” in staff information file. As is known, data will be changed at anytime, so it is necessary to edit comments to be in correspondence with the changed data. Now, this post focuses on presenting solution about how to manipulate existing Excel comments in C# and Visual Basic, containing to remove, edit and extract comment from Excel.

Solution I will introduce is based on a .NET Excel component, Spire.XLS for .NET. Therefore, I have downloaded, installed this component and add its dll file as reference in my project before programming. And the following screenshot presents original Excel file with comments.

Following, let’s code step by step.

Firstly, initialize a Workbook class instance and invoke LoadFromFile(string fileName) method to load the Excel file with comments. Then, initialize a Worksheet class instance.


            Workbook workbook = new Workbook();

            workbook.LoadFromFile(@”E:\Work\Documents\ExcelFiles\Staff Contact Info.xlsx”);

            Worksheet sheet = workbook.Worksheets[0];

Visual Basic

            Dim workbook As New Workbook()

            workbook.LoadFromFile(“E:\Work\Documents\ExcelFiles\Staff Contact Info.xlsx”)

            Dim sheet As Worksheet = workbook.Worksheets(0)

Remove Comment

Get the first comment of this sheet instance and then invoke ExcelCommentObject.Remove() method to delete the first comment.



Visual Basic


Edit Comment

Because the first comment has been moved, the original second becomes the first. Get it and assign string value which the new comment content for ExcelCommentObject.Text property to edit original comment.


            sheet.Comments[0].Text = “He will come back to company in May”;

Visual Basic

            sheet.Comments(0).Text = “He will come back to company in May”

Extract Comment

Initialize a StringBuilder class instance and invoke Append method of StringBuilder class to append a copy of specified string to the end of this instance. The parameter passed to this method is string which is text of the second comment (original third). Finally, invoke WriteAllTextmethod of System.IO.File class with parameters string path and string contents which are are saved in StringBuilder instance to save extracted comments in a TEXT file.


            StringBuilder SB = new StringBuilder();


            File.WriteAllText(“ExcelComment.txt”, SB.ToString());

Visual Basic

            Dim SB As New StringBuilder()


            File.WriteAllText(“ExcelComment.txt”, SB.ToString())

Finally, we need to invoke SaveToFile method of Workbook class with parameters string fileName and ExcelVersion version to save the Excel with changed comments. Then launch it for viewing the result.


            workbook.SaveToFile(“EditComment.xlsx”, ExcelVersion.Version2010);


Visual Basic

            workbook.SaveToFile(“EditComment.xlsx”, ExcelVersion.Version2010)


Result of Excel file with Removed and Edited Comments

Result of TEXT file with Extracted Comment

Download Spire.XLS for .NET Here

P.S The .NET Office component, Spire.Office for .NET can be used to realize this function as well.

Save and Open .Docm Document in C# and Visual Basic

What is Word Macro?

It is a batch processing commander which enables users to program for realizing some functions to operate Word document more easily and efficiently.

How to create Word Macro?

Take Microsoft Office 2010 as example. Open a document and click View tab to find Macros. Select View Macros and then a dialog box named Macros pops up. Give the macro a name and click Create button. Then, a Visual Basic editor appears and you can program to realize functions what you want. Of course, you can run, edit and delete existing macros.

How to open and save a Word document with macros (.docm) programmatically?

In following solutions, a .NET Word component is used for realizing functions to load and save .docm document quickly and easily.


Initialize a Document class instance and invoke LoadFromFile(string filename, FileFormat fileFormat) method to load .docm document.


            Document document = new Document();

            document.LoadFromFile(@”E:\Work\Documents\.NET Framework.docm”,FileFormat.Docm);

Visual Basic

            Dim document As New Document()

            document.LoadFromFile(“E:\Work\Documents\.NET Framework.docm”, FileFormat.Docm)


Invoke SaveToFile(string fileName, FileFormat fileFormat) of Document class to save loaded .docm document. Of course, you can save this file as .doc, .docx format as well.


            document.SaveToFile(“x.docm”, FileFormat.Docm);

Visual Basic

            document.SaveToFile(“x.docm”, FileFormat.Docm)

Clear Macros

Invoke ClearMacros() method of Document class directly to remove macros from document.


            //Clear Macros


Visual Basic


Download Spire.Doc for .NET Here

P.S The .NET Office component, Spire.Office for .NET can be used to realize this function as well.

Powerful Data Analysis of Excel 2013

The cleaner new look of Excel 2013 is quite attractive at the first glance. Following, let’s explore what’s more in Excel 2013.


Excel 2013 will recommend the most appropriate chart with data information when you are confused with which type of chart should be used. After inserting chart, you can design and format chart with Design and Format tab of Chart Tools ribbon. Also, three new chart buttons enable you to pick and preview changes to chart elements, the look and style of your chart, or to the data that is shown.

Pivot Table

Excel 2013 will recommend several ways to summarize data and show a quick preview of the field layouts after a Pivot Table is created. Each Pivot Table will be followed by a Field List, which enables you to filter fields easily to present in your Pivot Table layout. Also, you can create Pivot Tables based on multiple tables in Excel and analyze data with results by importing different tables and creating relationships between them. What’s more, Pivot Chart is standalone instead of being associated with Pivot Table. With Drill Down and Drill up, you can get the data details in Pivot Chart.

Online Functions

Excel 2013 can be easily saved to your own online location, as SkyDrive and worksheets can be simply embed on your web page. What’s more, the worksheets can be shared in an online meeting so that every attendants can learn data details.

Other New Features

Excel 2013 adds several new functions in the math and trigonometry, statistical, engineering, date and time, lookup and reference, logical, and text function categories.

Excel 2013 opens each workbook in its own window to make it easier to work on two workbooks at once.

Excel 2013 can save to and open files in the new Strict Open XML Spreadsheet (*.xlsx) file format. This file format lets you read and write ISO8601 dates to resolve a leap year issue for the year 1900.

To sum up, Excel 2013 is much more powerful on data analysis and provides more conveniences for users to present, calculate and analyze data information.

More Details about Excel 2013

Recommendation: .NET Excel Library to Manipulate Excel