VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.Pdf.BasicTypes Namespace / PdfBasicObject Class
Members Object Syntax Example Hierarchy Requirements SeeAlso
In This Topic
PdfBasicObject Class
In This Topic
Represents an abstract base class of PDF basic types hierarchy (low-level PDF tree).
Object Model
PdfBasicObject
Syntax
'Declaration

Public MustInherit Class PdfBasicObject

public abstract class PdfBasicObject

Example

Here is an example that shows how to create a single page PDF document using PDF basic types only:


''' <summary>
''' Creates a single page PDF document using only PDF basic types (basic PDF tree).
''' </summary>
''' <param name="outputPdfFilename">The output PDF filename.</param>
Public Shared Sub CreatePdfDocumentUseBasicTypes(outputPdfFilename As String)
    Using document As New Vintasoft.Imaging.Pdf.PdfDocument(Vintasoft.Imaging.Pdf.PdfFormat.Pdf_14)
        Dim catalog As Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary = GetBasicObject(Of Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary)(document.Catalog.BasicObject)

        Dim pages As Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary = GetBasicObject(Of Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary)(catalog("Pages"))

        pages("Count") = New Vintasoft.Imaging.Pdf.BasicTypes.PdfIntegerNumber(1)
        Dim page As New Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary(document)
        pages("Kids") = New Vintasoft.Imaging.Pdf.BasicTypes.PdfArray(document, Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject.Create(document, page).GetReference())

        page("Type") = New Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Page")
        page("Parent") = catalog("Pages")
        page("MediaBox") = New Vintasoft.Imaging.Pdf.BasicTypes.PdfArray(document, Vintasoft.Imaging.Pdf.BasicTypes.PdfNumber.Create(0), Vintasoft.Imaging.Pdf.BasicTypes.PdfNumber.Create(0), Vintasoft.Imaging.Pdf.BasicTypes.PdfNumber.Create(300), Vintasoft.Imaging.Pdf.BasicTypes.PdfNumber.Create(400))

        Dim font As New Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary(document)
        font("Type") = New Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Font")
        font("Subtype") = New Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Type1")
        font("BaseFont") = New Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Times-Roman")
        font("Encoding") = New Vintasoft.Imaging.Pdf.BasicTypes.PdfName("WinAnsiEncoding")

        Dim fontResources As New Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary(document)
        fontResources("F1") = Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject.Create(document, font).GetReference()
        Dim pageResources As New Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary(document)
        pageResources("Font") = fontResources
        page("Resources") = pageResources

        Dim content As String = "q /F1 20 Tf BT 100 200 Td (Hello World!) Tj ET Q"
        Dim contentStream As New Vintasoft.Imaging.Pdf.BasicTypes.PdfStream(document)
        contentStream.SetBytes(System.Text.Encoding.ASCII.GetBytes(content), Vintasoft.Imaging.Pdf.PdfCompression.None, Vintasoft.Imaging.Pdf.PdfCompressionSettings.DefaultSettings)
        page("Contents") = Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject.Create(document, contentStream).GetReference()

        document.Save(outputPdfFilename)
    End Using
End Sub

''' <summary>
''' Gets the basic object of specified type.
''' </summary>
''' <typeparam name="T">Type of basic object.</typeparam>
''' <param name="obj">The basic object.</param>
Private Shared Function GetBasicObject(Of T As Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject)(obj As Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject) As T
    If TypeOf obj Is T Then
        Return DirectCast(obj, T)
    End If
    If TypeOf obj Is Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectReference Then
        Return GetBasicObject(Of T)(Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject.GetByReference(DirectCast(obj, Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectReference)))
    End If
    If TypeOf obj Is Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject Then
        Return GetBasicObject(Of T)(DirectCast(obj, Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject).Value)
    End If
    If TypeOf obj Is Vintasoft.Imaging.Pdf.BasicTypes.PdfStream Then
        Return GetBasicObject(Of T)(DirectCast(obj, Vintasoft.Imaging.Pdf.BasicTypes.PdfStream).Dictionary)
    End If
    Return DirectCast(obj, T)
End Function 


/// <summary>
/// Creates a single page PDF document using only PDF basic types (basic PDF tree).
/// </summary>
/// <param name="outputPdfFilename">The output PDF filename.</param>
public static void CreatePdfDocumentUseBasicTypes(string outputPdfFilename)
{
    using (Vintasoft.Imaging.Pdf.PdfDocument document = 
        new Vintasoft.Imaging.Pdf.PdfDocument(Vintasoft.Imaging.Pdf.PdfFormat.Pdf_14))
    {
        Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary catalog = 
            GetBasicObject<Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary>(document.Catalog.BasicObject);

        Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary pages = 
            GetBasicObject<Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary>(catalog["Pages"]);

        pages["Count"] = new Vintasoft.Imaging.Pdf.BasicTypes.PdfIntegerNumber(1);
        Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary page = 
            new Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary(document);
        pages["Kids"] = new Vintasoft.Imaging.Pdf.BasicTypes.PdfArray(document, 
            Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject.Create(document, page).GetReference());

        page["Type"] = new Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Page");
        page["Parent"] = catalog["Pages"];
        page["MediaBox"] = new Vintasoft.Imaging.Pdf.BasicTypes.PdfArray(document,
            Vintasoft.Imaging.Pdf.BasicTypes.PdfNumber.Create(0),
            Vintasoft.Imaging.Pdf.BasicTypes.PdfNumber.Create(0),
            Vintasoft.Imaging.Pdf.BasicTypes.PdfNumber.Create(300),
            Vintasoft.Imaging.Pdf.BasicTypes.PdfNumber.Create(400));

        Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary font = 
            new Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary(document);
        font["Type"] = new Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Font");
        font["Subtype"] = new Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Type1");
        font["BaseFont"] = new Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Times-Roman");
        font["Encoding"] = new Vintasoft.Imaging.Pdf.BasicTypes.PdfName("WinAnsiEncoding");

        Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary fontResources = 
            new Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary(document);
        fontResources["F1"] = Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject.Create(document, font).GetReference();
        Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary pageResources = 
            new Vintasoft.Imaging.Pdf.BasicTypes.PdfDictionary(document);
        pageResources["Font"] = fontResources;
        page["Resources"] = pageResources;

        string content = "q /F1 20 Tf BT 100 200 Td (Hello World!) Tj ET Q";
        Vintasoft.Imaging.Pdf.BasicTypes.PdfStream contentStream = 
            new Vintasoft.Imaging.Pdf.BasicTypes.PdfStream(document);
        contentStream.SetBytes(
            System.Text.Encoding.ASCII.GetBytes(content), 
            Vintasoft.Imaging.Pdf.PdfCompression.None,
            Vintasoft.Imaging.Pdf.PdfCompressionSettings.DefaultSettings);
        page["Contents"] = Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject.Create(document, contentStream).GetReference();

        document.Save(outputPdfFilename);
    }
}

/// <summary>
/// Gets the basic object of specified type.
/// </summary>
/// <typeparam name="T">Type of basic object.</typeparam>
/// <param name="obj">The basic object.</param>
private static T GetBasicObject<T>(Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject obj)
    where T : Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject
{
    if (obj is T)
        return (T)obj;
    if (obj is Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectReference)
        return GetBasicObject<T>(
            Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject.GetByReference(((
                Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectReference)obj)));
    if (obj is Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject)
        return GetBasicObject<T>(((Vintasoft.Imaging.Pdf.BasicTypes.PdfIndirectObject)obj).Value);
    if (obj is Vintasoft.Imaging.Pdf.BasicTypes.PdfStream)
        return GetBasicObject<T>(((Vintasoft.Imaging.Pdf.BasicTypes.PdfStream)obj).Dictionary);
    return (T)obj;
} 

Inheritance Hierarchy
Requirements

Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also