VintaSoft Imaging .NET SDK 15.1: Документация для .NET разработчика
В этом разделе
PDF: Создание PDF документа
В этом разделе
VintaSoft Imaging .NET SDK позволяет создавать PDF документы, которые соответствуют PDF спецификациям версий 1.0-2.0 и PDF/A спецификациям. SDK позволяет создавать searchable PDF документы в векторном формате и image-only PDF документы.
Каждый из созданных PDF документов может быть защищен с помощью алгоритмов ARC4 или AES. Защищенному PDF документу можно присвоить пароли владельца и пользователя, а также применить к нему настроенные права доступа.

Вот C#/VB.NET код, который демонстрирует, как создать PDF документ версии 1.4 в памяти и сохранить его в файл:
public static void CreatePdfDocumentInMemory(Vintasoft.Imaging.ImageCollection images)
{
    // create new PDF document version 1.4 in the memory
    using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(
        new Vintasoft.Imaging.Pdf.PdfFormat("1.4")))
    {
        // create an empty image
        using (Vintasoft.Imaging.VintasoftImage image = new Vintasoft.Imaging.VintasoftImage(600, 800))
        {
            // add image to PDF document
            document.Pages.Add(image);
        }

        // save document to a file
        document.Save("doc.pdf");
    }
}
Public Shared Sub CreatePdfDocumentInMemory(images As Vintasoft.Imaging.ImageCollection)
    ' create new PDF document version 1.4 in the memory
    Using document As New Vintasoft.Imaging.Pdf.PdfDocument(New Vintasoft.Imaging.Pdf.PdfFormat("1.4"))
        ' create an empty image
        Using image As New Vintasoft.Imaging.VintasoftImage(600, 800)
            ' add image to PDF document
            document.Pages.Add(image)
        End Using

        ' save document to a file
        document.Save("doc.pdf")
    End Using
End Sub


Вот C#/VB.NET код, который демонстрирует, как создать PDF/A-1b документ и сохранить его в файл:
public static void CreatePdfADocumentInFile(string pdfFilename, string pageImage)
{
    // create new PDF document version 1.4
    using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(
        pdfFilename, Vintasoft.Imaging.Pdf.PdfFormat.Pdf_14))
    {
        // create an image
        using (Vintasoft.Imaging.VintasoftImage image = new Vintasoft.Imaging.VintasoftImage(pageImage))
        {
            // add image to PDF document
            document.Pages.Add(image);
        }

        // convert documen to PDF/A-1b
        document.ConvertDocument(Vintasoft.Imaging.Pdf.PdfDocumentConformance.PdfA_1b);
    }
}
Public Shared Sub CreatePdfADocumentInFile(pdfFilename As String, pageImage As String)
    ' create new PDF document version 1.4
    Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename, Vintasoft.Imaging.Pdf.PdfFormat.Pdf_14)
        ' create an image
        Using image As New Vintasoft.Imaging.VintasoftImage(pageImage)
            ' add image to PDF document
            document.Pages.Add(image)
        End Using

        ' convert documen to PDF/A-1b
        document.ConvertDocument(Vintasoft.Imaging.Pdf.PdfDocumentConformance.PdfA_1b)
    End Using
End Sub


Вот C#/VB.NET код, который демонстрирует, как создать защищенный PDF документ в памяти и сохранить его в файл:
public static void CreateEncryptedDocument(
    string pdfFilename, 
    Vintasoft.Imaging.ImageCollection images, 
    string password)
{
    // create encryption system 40-bit RC4, password protection
    Vintasoft.Imaging.Pdf.Security.EncryptionSystem encryption = 
        new Vintasoft.Imaging.Pdf.Security.EncryptionSystem(
            Vintasoft.Imaging.Pdf.Security.EncryptionAlgorithm.RC4, 40,
            password, password, 
            Vintasoft.Imaging.Pdf.Security.UserAccessPermissions.AllowAll);

    // create encrypted document
    using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(
        Vintasoft.Imaging.Pdf.PdfFormat.Pdf_14, encryption))
    {
        // add pages
        foreach (Vintasoft.Imaging.VintasoftImage image in images)
            document.Pages.Add(image);

        // save document
        document.SaveChanges(pdfFilename);
    }
}
Public Shared Sub CreateEncryptedDocument(pdfFilename As String, images As Vintasoft.Imaging.ImageCollection, password As String)
    ' create encryption system 40-bit RC4, password protection
    Dim encryption As New Vintasoft.Imaging.Pdf.Security.EncryptionSystem(Vintasoft.Imaging.Pdf.Security.EncryptionAlgorithm.RC4, 40, password, password, Vintasoft.Imaging.Pdf.Security.UserAccessPermissions.AllowAll)

    ' create encrypted document
    Using document As New Vintasoft.Imaging.Pdf.PdfDocument(Vintasoft.Imaging.Pdf.PdfFormat.Pdf_14, encryption)
        ' add pages
        For Each image As Vintasoft.Imaging.VintasoftImage In images
            document.Pages.Add(image)
        Next

        ' save document
        document.SaveChanges(pdfFilename)
    End Using
End Sub


Создание PDF документа с возможностью поиска (PDF документ с векторной графикой)

Для создания PDF документа с возможностью поиска необходимо создать новый PDF документ и нарисовать содержимое документа (текст, изображения, графику, диаграммы и т.д.) на PDF страницах. Подробную информацию о рисовании графики на PDF странице можно найти здесь .


Создание PDF документа, содержащего только изображения

Для создания PDF документа, который содержит только изображения, необходимо создать новый PDF документ и добавить в него PDF страницы, основанные на изображениях.

Вот C#/VB.NET код, который демонстрирует, как преобразовать растровое изображение в одностраничный image-only PDF документ с помощью класса PdfEncoder:
public void CreateImageOnlyPdf(System.IO.Stream stream, Vintasoft.Imaging.VintasoftImage image)
{
    // create new PDF document version 1.4 and use JPEG compression for image
    Vintasoft.Imaging.Codecs.Encoders.PdfEncoder encoder = 
        new Vintasoft.Imaging.Codecs.Encoders.PdfEncoder(true, 
            Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Jpeg);
    // set document Title
    encoder.Settings.DocumentTitle = "New PDF document!";
    // add image to PDF document
    encoder.SaveImage(image, stream);
}
Public Sub CreateImageOnlyPdf(stream As System.IO.Stream, image As Vintasoft.Imaging.VintasoftImage)
    ' create new PDF document version 1.4 and use JPEG compression for image
    Dim encoder As New Vintasoft.Imaging.Codecs.Encoders.PdfEncoder(True, Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Jpeg)
    ' set document Title
    encoder.Settings.DocumentTitle = "New PDF document!"
    ' add image to PDF document
    encoder.SaveImage(image, stream)
End Sub


Вот C#/VB.NET код, который демонстрирует, как преобразовать коллекцию изображений в многостраничный image-only PDF документ с помощью класса PdfEncoder:
public void CreateImageOnlyPdf(System.IO.Stream stream, Vintasoft.Imaging.ImageCollection images)
{
    // create new PDF document version 1.4 and use JPEG compression for image
    Vintasoft.Imaging.Codecs.Encoders.PdfEncoder encoder = 
        new Vintasoft.Imaging.Codecs.Encoders.PdfEncoder(true, 
            Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Jpeg);
    // set document Title
    encoder.Settings.DocumentTitle = "New PDF document!";
    // add image to PDF document
    encoder.SaveImages(images, stream);
}
Public Sub CreateImageOnlyPdf(stream As System.IO.Stream, images As Vintasoft.Imaging.ImageCollection)
    ' create new PDF document version 1.4 and use JPEG compression for image
    Dim encoder As New Vintasoft.Imaging.Codecs.Encoders.PdfEncoder(True, Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Jpeg)
    ' set document Title
    encoder.Settings.DocumentTitle = "New PDF document!"
    ' add image to PDF document
    encoder.SaveImages(images, stream)
End Sub


Вот C#/VB.NET код, который демонстрирует, как преобразовать растровое изображение в одностраничный image-only PDF документ с помощью класса PdfDocument:
public void CreateImageOnlyPdf(System.IO.Stream stream, Vintasoft.Imaging.VintasoftImage image)
{
    // create new PDF document version 1.4
    Vintasoft.Imaging.Pdf.PdfDocument document = 
        new Vintasoft.Imaging.Pdf.PdfDocument(
            stream, new Vintasoft.Imaging.Pdf.PdfFormat("1.4"));
    // set document Title
    document.DocumentInformation.Title = "New PDF document!";

    // add image to PDF document using JPEG compression
    document.Pages.Add(image, Vintasoft.Imaging.Pdf.PdfCompression.Jpeg);
    // save changes
    document.SaveChanges();

    // close document
    document.Dispose();
}
Public Sub CreateImageOnlyPdf(stream As System.IO.Stream, image As Vintasoft.Imaging.VintasoftImage)
    ' create new PDF document version 1.4
    Dim document As New Vintasoft.Imaging.Pdf.PdfDocument(stream, New Vintasoft.Imaging.Pdf.PdfFormat("1.4"))
    ' set document Title
    document.DocumentInformation.Title = "New PDF document!"

    ' add image to PDF document using JPEG compression
    document.Pages.Add(image, Vintasoft.Imaging.Pdf.PdfCompression.Jpeg)
    ' save changes
    document.SaveChanges()

    ' close document
    document.Dispose()
End Sub


Вот C#/VB.NET код, который демонстрирует, как преобразовать коллекцию изображений в многостраничный image-only PDF документ с помощью класса PdfDocument:
public void CreateImageOnlyPdf(System.IO.Stream stream, Vintasoft.Imaging.ImageCollection images)
{
    // create new PDF document version 1.4
    Vintasoft.Imaging.Pdf.PdfDocument document = 
        new Vintasoft.Imaging.Pdf.PdfDocument(
            stream, new Vintasoft.Imaging.Pdf.PdfFormat("1.4"));
    // set document Title
    document.DocumentInformation.Title = "New PDF document!";

    // for each image in image collection
    for (int i = 0; i < images.Count; i++)
    {
        // add image to PDF document using JPEG compression
        document.Pages.Add(images[i], Vintasoft.Imaging.Pdf.PdfCompression.Jpeg);
    }
    // save changes
    document.SaveChanges();

    // close document
    document.Dispose();
}
Public Sub CreateImageOnlyPdf(stream As System.IO.Stream, images As Vintasoft.Imaging.ImageCollection)
    ' create new PDF document version 1.4
    Dim document As New Vintasoft.Imaging.Pdf.PdfDocument(stream, New Vintasoft.Imaging.Pdf.PdfFormat("1.4"))
    ' set document Title
    document.DocumentInformation.Title = "New PDF document!"

    ' for each image in image collection
    For i As Integer = 0 To images.Count - 1
        ' add image to PDF document using JPEG compression
        document.Pages.Add(images(i), Vintasoft.Imaging.Pdf.PdfCompression.Jpeg)
    Next
    ' save changes
    document.SaveChanges()

    ' close document
    document.Dispose()
End Sub