PackAllFonts(IActionProgressController) Метод (PdfFontManager)
В этом разделе
Упаковывает все шрифты PDF документа.
Синтаксис
Parameters
- progressController
- Контроллер хода выполнения.
Return Value
True - программы шрифтов упакованы успешно;
false - программы шрифтов НЕ упакованы.
Пример
Вот пример, показывающий, как упаковать все шрифты PDF документа и вывести подробную информацию о ходе выполнения на консоль:
''' <summary>
''' Stores current action description of level 1.
''' </summary>
Shared _currentActionDescriptionLevel1 As String = Nothing
''' <summary>
''' Stores current action description of level 2.
''' </summary>
Shared _currentActionDescriptionLevel2 As String = Nothing
''' <summary>
''' Stores current action description of level 3.
''' </summary>
Shared _currentActionDescriptionLevel3 As String = Nothing
''' <summary>
''' Removes all unused characters from fonts of PDF document
''' and outputs detailed progress info to the console.
''' </summary>
''' <param name="pdfFilename">The filename of PDF document.</param>
''' <param name="resultFilename">The filename of resulting PDF document.</param>
Public Shared Sub PackAllFontsOfDocumentWithDetailedInfo(pdfFilename As String, resultFilename As String)
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
' create progress handler which handles 3 levels of progress
Dim actionProgressHandler As Vintasoft.Imaging.Utils.IActionProgressHandler = Vintasoft.Imaging.Utils.ActionProgressHandlers.CreateActionProgressHandler(AddressOf OnPackProgressLevel1, AddressOf OnPackProgressLevel2, AddressOf OnPackProgressLevel3)
' create progress controller
Dim progressController As New Vintasoft.Imaging.Utils.ActionProgressController(actionProgressHandler)
' pack all fonts using progress controller
document.FontManager.PackAllFonts(progressController)
' pack and save document to new location
document.Pack(resultFilename)
End Using
End Sub
''' <summary>
''' Outputs description of level 1 actions of font packing.
''' </summary>
Private Shared Sub OnPackProgressLevel1(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
Dim actionDescription As String = e.Description
' if action is finished
If e.Progress = 100 Then
' output action description with small indent
System.Console.WriteLine(" Finished ({0}).", actionDescription)
' if action is started
ElseIf actionDescription <> _currentActionDescriptionLevel1 Then
' remember action description
_currentActionDescriptionLevel1 = actionDescription
' output action description with small indent
System.Console.WriteLine("{0}...", actionDescription)
End If
End Sub
''' <summary>
''' Outputs description of level 2 actions of font packing.
''' </summary>
Private Shared Sub OnPackProgressLevel2(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
Dim actionDescription As String = e.Description
' if action is finished
If e.Progress = 100 Then
' output action description with medium indent
System.Console.WriteLine(" Finished ({0}).", actionDescription)
' if action is started
ElseIf actionDescription <> _currentActionDescriptionLevel2 Then
' remember action description
_currentActionDescriptionLevel2 = actionDescription
' output action description with medium indent
System.Console.WriteLine(" {0}...", actionDescription)
End If
End Sub
''' <summary>
''' Outputs description of level 3 actions of font packing.
''' </summary>
Private Shared Sub OnPackProgressLevel3(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
Dim actionDescription As String = e.Description
' if action is finished
If e.Progress = 100 Then
' output action description with large indent
System.Console.WriteLine(" Finished ({0}).", actionDescription)
' if action is started
ElseIf actionDescription <> _currentActionDescriptionLevel3 Then
' remember action description
_currentActionDescriptionLevel3 = actionDescription
' output action description with large indent
System.Console.WriteLine(" {0}...", actionDescription)
End If
End Sub
/// <summary>
/// Stores current action description of level 1.
/// </summary>
static string _currentActionDescriptionLevel1 = null;
/// <summary>
/// Stores current action description of level 2.
/// </summary>
static string _currentActionDescriptionLevel2 = null;
/// <summary>
/// Stores current action description of level 3.
/// </summary>
static string _currentActionDescriptionLevel3 = null;
/// <summary>
/// Removes all unused characters from fonts of PDF document
/// and outputs detailed progress info to the console.
/// </summary>
/// <param name="pdfFilename">The filename of PDF document.</param>
/// <param name="resultFilename">The filename of resulting PDF document.</param>
public static void PackAllFontsOfDocumentWithDetailedInfo(string pdfFilename, string resultFilename)
{
using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
{
// create progress handler which handles 3 levels of progress
Vintasoft.Imaging.Utils.IActionProgressHandler actionProgressHandler =
Vintasoft.Imaging.Utils.ActionProgressHandlers.CreateActionProgressHandler(
OnPackProgressLevel1, OnPackProgressLevel2, OnPackProgressLevel3);
// create progress controller
Vintasoft.Imaging.Utils.ActionProgressController progressController =
new Vintasoft.Imaging.Utils.ActionProgressController(actionProgressHandler);
// pack all fonts using progress controller
document.FontManager.PackAllFonts(progressController);
// pack and save document to new location
document.Pack(resultFilename);
}
}
/// <summary>
/// Outputs description of level 1 actions of font packing.
/// </summary>
private static void OnPackProgressLevel1(object sender, Vintasoft.Imaging.ProgressEventArgs e)
{
string actionDescription = e.Description;
// if action is finished
if (e.Progress == 100)
{
// output action description with small indent
System.Console.WriteLine(" Finished ({0}).", actionDescription);
}
// if action is started
else if (actionDescription != _currentActionDescriptionLevel1)
{
// remember action description
_currentActionDescriptionLevel1 = actionDescription;
// output action description with small indent
System.Console.WriteLine("{0}...", actionDescription);
}
}
/// <summary>
/// Outputs description of level 2 actions of font packing.
/// </summary>
private static void OnPackProgressLevel2(object sender, Vintasoft.Imaging.ProgressEventArgs e)
{
string actionDescription = e.Description;
// if action is finished
if (e.Progress == 100)
{
// output action description with medium indent
System.Console.WriteLine(" Finished ({0}).", actionDescription);
}
// if action is started
else if (actionDescription != _currentActionDescriptionLevel2)
{
// remember action description
_currentActionDescriptionLevel2 = actionDescription;
// output action description with medium indent
System.Console.WriteLine(" {0}...", actionDescription);
}
}
/// <summary>
/// Outputs description of level 3 actions of font packing.
/// </summary>
private static void OnPackProgressLevel3(object sender, Vintasoft.Imaging.ProgressEventArgs e)
{
string actionDescription = e.Description;
// if action is finished
if (e.Progress == 100)
{
// output action description with large indent
System.Console.WriteLine(" Finished ({0}).", actionDescription);
}
// if action is started
else if (actionDescription != _currentActionDescriptionLevel3)
{
// remember action description
_currentActionDescriptionLevel3 = actionDescription;
// output action description with large indent
System.Console.WriteLine(" {0}...", actionDescription);
}
}
Требования
Целевые платформы: .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также