PUB file opener

Read PUB files. Open Publisher with API for .NET

 

Microsoft® Publisher document file format is used for creating various publication types such as newsletters, brochures, flyers, and postcards and is used in Emails and Websites. Pub files contain text, tables as well as bitmap and vector graphics data.

Even though the format is quite popular it is not as popular as such formats as PDF or DOCX. MS Publisher application is not free itself.

So sometimes it is required to open PUB files without this program. This is needed when you want to show the document's content, without editing or manipulating it any other way, like when you have a presentation or review. For such purposes, you may use a cross-platform PUB Viewer application.

Here you will get the .NET API Solution that lets you view the MS Publisher document's properties such as size, width, height, names of the used fonts, the number of fields, and colors.

Read Publisher files on .NET

To view .pub files properties you will need to take the next steps:

  1. Integrate .NET PUB API, which works not only with single-page documents but also supports multipage .pub files.
  2. Upload your PUB file using CreateParser() Method of PubFactory Class.
  3. Parse the document via Parse() Method of IPubParser Interface.
  4. Print document properties .

Get Started with .NET PUB API

There are two ways to get the product installed:

  1. Install from the command line as nuget install Aspose.PUB or via Package Manager Console of Visual Studio with Install-Package Aspose.PUB.
  2. Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads .

.NET Code to Read PUB files properties

    // Load PUB file
    var parser = PubFactory.CreateParser("sample.pub");
    // Parse file 
    var doc = parser.Parse();
    // Print document properties
    Console.WriteLine($"Page width: {GetInchesString(doc.Width)}");            
    Console.WriteLine($"Page height: {GetInchesString(doc.Height)}");
    Console.WriteLine($"Field count: {doc.FieldCount}");
    string fontNames = GetCollectionString(doc.FontNames);
    if (!string.IsNullOrEmpty(fontNames))
    {
        Console.WriteLine($"Fonts used in document: {fontNames}");
    }
    string colors = GetCollectionString(doc.Colors);
    if (!string.IsNullOrEmpty(colors))
    {
        Console.WriteLine($"Colors used in document: {colors}");
    }

To see the full code ReadPubDocument.cs example go the Aspose.PUB.Examples.sln solution, in the net-examples of the Aspose.PUB Documentation where you can also find other examples on how to use the library.

    // Description of invoked methods:
    
        private string GetInchesString(uint size)
        {
            double value = (double)size / EMUsesInOneInch;
            return Convert.ToString(value) + " inches";
        }

        private string GetCollectionString(ICollection array)
        {
            if (array.Count == 0)
            {
                return null;
            }

            StringBuilder sb = new StringBuilder();
            int num = -1;
            IEnumerator enumerator = array.GetEnumerator();

            while (enumerator.MoveNext())
            {
                num++;
                sb.Append(GetObjectStirng(enumerator.Current));
                if (num < (array.Count - 1))
                {
                    sb.Append(", ");
                }
            }

            return sb.ToString();
        }

        private string GetObjectStirng(object value)
        {
            if (value is Color)
            {
                Color colorVal = (Color)value;
                return $"RGB({colorVal.R}, {colorVal.G}, {colorVal.B})"; 
            }

            return value.ToString();
        }



FAQ

1. How can I view Microsoft Publisher files?

Publisher files can be opened by little software that is not free. But to view the content of the file online you can use a cross-platform Viewer application.

2. Can I open a Publisher File in Word?

To open PUB files in MS Word you need to them. You can do it online using the web Converter application.

3. Is the functionality free?

The cross-platform app is free, when for the API solution you can get a free Trial and then buy the product if needed.

  

Support and Learning Resources