Home

Bytescout.PDF for .NET



Bytescout.PDF library for .NET - marking bookmarks in outlines tree with different colors in PDF document

Download Free Trial Buy Now More Information
For HTML2PDF and XML2PDF solution check our PDFDoc Scout ActiveX library instead

How to use different colors for outlines in bookmarks in PDF document

This example teaches how to mark outlines with different colors in bookmarks tree in PDF document generated by Bytescout.PDF library

Outlines marked with different colors in PDF

Download example source code: bytescoutpdf_outlines_bookmarks_with_colors.zip (5 KB)

using System;
using System.Collections.Generic;
using System.Text;
using Bytescout.PDF;

namespace ColorizedOutlines
{
class Program
{
static void Main(string[] args)
{
PDFDocEngine engine =
new PDFDocEngine("", "");

// Add new document
Document document = engine.AddDocument();

// Add standard font
uint font = document.AddFontStandard(StandardFontType.Courier, FontEncodingType.Standard);

// Append new pages to the document
Page page = document.AddPage(PageSizeType.A4, PageOrientationType.LandScape);
Page page2 = document.AddPage(PageSizeType.A4, PageOrientationType.LandScape);

// Create new drawing
Drawing drawing = page.AddDrawing();

// Set Active Font
drawing.SetActiveFont(font, 50, false, false);

// Draw Text
drawing.PlaceText(100, 100, 0, "Hello World!");

// Close drawing
drawing.Close();

// Create new drawing
drawing = page2.AddDrawing();

// Set Active Font
drawing.SetActiveFont(font, 50, false, false);

// Draw Text
drawing.PlaceText(100, 100, 0, "Hello again, World!");

// Close drawing
drawing.Close();

// Add root outline
Outline root = document.Outlines.AddChild();
root.Title = "Root";

// Add link to page 1
Outline child = root.AddChild();
child.Title = "Page 1";
child.destination = new Destination(document, "Page1", false);
child.Color = Drawing.ToRGB(0, 0, 1); // blue color (components are 0..1 value)

// Add link to page 2
child = root.AddChild();
child.Title = "Page 2";
child.Color = Drawing.ToRGB(0, 1, 0); // red color (components are 0..1 value)
child.destination = new Destination(document, "Page2", false);

// Add NamedDestinations to document
document.AddNamedDestination("Page1", Destination.FitPage(0));
document.AddNamedDestination("Page2", Destination.FitPage(1));

// Save document
document.Save("HelloWorld.pdf");
}
}
}

Download example source code: bytescoutpdf_outlines_bookmarks_with_colors.zip (5 KB)

Download Free Trial Buy Now More Information
For HTML2PDF and XML2PDF solution check our PDFDoc Scout ActiveX library instead

"Hello, World!" quick start step-by-step tutorials:

Advanced Examples:
Products  |  Download  |  Purchase  |  Support  |  Contacts  |  Testimonials |  

ByteScout, 2003-2008. All other company and product names may be trademarks of their respective companies. Privacy Statement