Класс PdfEmbeddedGotoAction
В этом разделе
Определяет действие перехода, позволяющее переходить к файлу PDF, встроенному в другой PDF файл, или из него.
Объектная модель
Синтаксис
Пример
Вот пример, показывающий, как добавить встроенный PDF документ в указанный PDF документ и создать закладку со ссылкой на встроенный PDF документ.
''' <summary>
''' Adds the embedded PDF document to the specified PDF document and creates bookmark with link to the embedded PDF document.
''' </summary>
''' <param name="sourceDocumentFilename">The filename of source PDF document.</param>
''' <param name="embeddingDocumentFilename">The filename of PDF document that should be embedded.</param>
Public Shared Sub AddEmbeddedDocument(sourceDocumentFilename As String, embeddingDocumentFilename As String)
' open PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(sourceDocumentFilename)
' if document does not have embedded files
If document.EmbeddedFiles Is Nothing Then
' create EmbeddedFiles dictionary
document.EmbeddedFiles = New Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecificationDictionary(document)
End If
' name of embedded document
Dim embeddedDocumentName As String = System.IO.Path.GetFileName(embeddingDocumentFilename)
' create embedded file, use ZIP compression
Dim embeddedFile As New Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFile(document, embeddingDocumentFilename, Vintasoft.Imaging.Pdf.PdfCompression.Zip)
' add embedded file to EmbeddedFiles
document.EmbeddedFiles.Add(embeddedDocumentName, New Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification(System.IO.Path.GetFileName(embeddingDocumentFilename), embeddedFile))
' if document does not have bookmarks
If document.Bookmarks Is Nothing Then
' create document bookmarks
document.Bookmarks = New Vintasoft.Imaging.Pdf.Tree.PdfBookmarkCollection(document)
End If
' create destination to the first page of document
Dim destination As Vintasoft.Imaging.Pdf.Tree.PdfDestinationBase = New Vintasoft.Imaging.Pdf.Tree.PdfDestinationFit(document, 0)
' create target that goes to the embedded PDF document
Dim actionTarget As New Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedGotoActionTarget(document, embeddedDocumentName)
' create embedded action that opens the first page in embedded PDF document
Dim action As New Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedGotoAction(destination, actionTarget)
' create bookmark
Dim bookmark As New Vintasoft.Imaging.Pdf.Tree.PdfBookmark(document)
' set the bookmark title
bookmark.Title = embeddedDocumentName
' set the bookmark action
bookmark.Action = action
' add bookmark to the document bookmarks
document.Bookmarks.Add(bookmark)
' save changes in PDF document
document.SaveChanges()
End Using
End Sub
/// <summary>
/// Adds the embedded PDF document to the specified PDF document and creates bookmark with link to the embedded PDF document.
/// </summary>
/// <param name="sourceDocumentFilename">The filename of source PDF document.</param>
/// <param name="embeddingDocumentFilename">The filename of PDF document that should be embedded.</param>
public static void AddEmbeddedDocument(string sourceDocumentFilename, string embeddingDocumentFilename)
{
// open PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(sourceDocumentFilename))
{
// if document does not have embedded files
if (document.EmbeddedFiles == null)
// create EmbeddedFiles dictionary
document.EmbeddedFiles = new Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecificationDictionary(document);
// name of embedded document
string embeddedDocumentName = System.IO.Path.GetFileName(embeddingDocumentFilename);
// create embedded file, use ZIP compression
Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFile embeddedFile =
new Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFile(document, embeddingDocumentFilename, Vintasoft.Imaging.Pdf.PdfCompression.Zip);
// add embedded file to EmbeddedFiles
document.EmbeddedFiles.Add(
embeddedDocumentName,
new Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification(System.IO.Path.GetFileName(embeddingDocumentFilename), embeddedFile));
// if document does not have bookmarks
if (document.Bookmarks == null)
// create document bookmarks
document.Bookmarks = new Vintasoft.Imaging.Pdf.Tree.PdfBookmarkCollection(document);
// create destination to the first page of document
Vintasoft.Imaging.Pdf.Tree.PdfDestinationBase destination =
new Vintasoft.Imaging.Pdf.Tree.PdfDestinationFit(document, 0);
// create target that goes to the embedded PDF document
Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedGotoActionTarget actionTarget =
new Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedGotoActionTarget(document, embeddedDocumentName);
// create embedded action that opens the first page in embedded PDF document
Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedGotoAction action =
new Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedGotoAction(destination, actionTarget);
// create bookmark
Vintasoft.Imaging.Pdf.Tree.PdfBookmark bookmark = new Vintasoft.Imaging.Pdf.Tree.PdfBookmark(document);
// set the bookmark title
bookmark.Title = embeddedDocumentName;
// set the bookmark action
bookmark.Action = action;
// add bookmark to the document bookmarks
document.Bookmarks.Add(bookmark);
// save changes in PDF document
document.SaveChanges();
}
}
Иерархия наследования
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также