LEADTOOLS画像ファイルサポート(Leadtools.Codecsアセンブリ)

フレームを表示

CodecsPdfOptionsクラス








メンバ 
PDFイメージのロードと保存についての追加のオプションを提供します。
オブジェクトモデル
構文
public class CodecsPdfOptions 
'Declaration
 
Public Class CodecsPdfOptions 
'Usage
 
Dim instance As CodecsPdfOptions
public sealed class CodecsPdfOptions 
@interface LTCodecsPdfOptions : NSObject
public class CodecsPdfOptions
function Leadtools.Codecs.CodecsPdfOptions()
public ref class CodecsPdfOptions 
解説

LEADTOOLSでラスター画像へ/からPDF文書をロードまたは保存するために、Leadtools.Pdf.dllアセンブリを使います。これは、PDF形式(ならびにPostScriptと拡張PostScript)のためのファイルフィルタです。TIFのサポートとLeadtools.Codecs.Tif.dllがサポートするBMPのためのLeadtools.Codecs.Bmp.dllなどの、LEADTOOLSの他のどのファイルフィルタとしても、このアセンブリを使います。

Leadtools.Pdf.dllに加えて、Leadtools.PdfEngine.dllアセンブリは、以下の状況で必要とされます:

Leadtools.PdfEngine.dllには、PDF画像のレンダリングに必要なテーブルやフォントなどのリソースが数多く含まれています(これらのリソースは、上記のいずれかの条件に該当する場合に必要となり、PSおよびEPSファイルに対しては常に必要となります)。このDLLは、ファイルフィルタで直接的な方向でリファレンスをつけられません;代わりに、それはダイナミックにロードされて、必要ならばプロセスの外にあります。このDLLがマシンに存在することを確実にしなければなりません。デフォルトで、それは、ファイルフィルタがある同じディレクトリにこのDLLがあるために必要です。ただし、Leadtools.PdfEngine.dllアセンブリの多数のインスタンスを複数のアプリケーション間で共有するために、CodecsPdfOptions.InitialPathプロパティを使用できます。

アプリケーションが必須のPDFエンジンをしないならば、たとえば、アプリケーションがラスター画像としてPDFファイルをロードして保存しているだけである点に注意します。その後、Leadtools.PdfEngine.dllはマシンに存在するために必要でありません。Leadtools.Pdf.dllは、常に気にせずに必要とされます。

サンプル
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs

      
Public Sub CodecsPdfOptionsExample()
   Dim codecs As New RasterCodecs()
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "PDFSegmentation.pdf")
   Dim destFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "PdfOptions.pdf")
   Dim destFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "PdfOptions.bmp")

   codecs.Options.Pdf.InitialPath = "C:\MyApp\Bin"

   ' Check if the PDF engine is installed then get the load and save options of the PDF files.
   If codecs.Options.Pdf.IsEngineInstalled Then
      ' Resulting image pixel depth.
      codecs.Options.Pdf.Load.DisplayDepth = 24
      codecs.Options.Pdf.Load.GraphicsAlpha = 4
      codecs.Options.Pdf.Load.Password = ""

      ' Type of font anti-aliasing to use.
      codecs.Options.Pdf.Load.TextAlpha = 1
      codecs.Options.Pdf.Load.UseLibFonts = True

      ' Horizontal,vertical  display resolution in dots per inch.
      codecs.Options.RasterizeDocument.Load.XResolution = 150
      codecs.Options.RasterizeDocument.Load.YResolution = 150

      Using image As RasterImage = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
         ' Set access rights for the user when he\she opens the file we create
         codecs.Options.Pdf.Save.AssembleDocument = True
         codecs.Options.Pdf.Save.ExtractText = True
         codecs.Options.Pdf.Save.ExtractTextGraphics = True
         codecs.Options.Pdf.Save.PrintDocument = False
         codecs.Options.Pdf.Save.FillForm = True
         codecs.Options.Pdf.Save.ModifyAnnotation = True
         codecs.Options.Pdf.Save.ModifyDocument = True
         codecs.Options.Pdf.Save.OwnerPassword = "LEAD Technologies"
         codecs.Options.Pdf.Save.PrintFaithful = False
         codecs.Options.Pdf.Save.TextEncoding = CodecsPdfTextEncoding.Hex
         codecs.Options.Pdf.Save.Use128BitEncryption = True
         codecs.Options.Pdf.Save.UserPassword = "LEAD"
         ' Set the PDF version to be v1.4
         codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V14

         ' Save the image back as PDF
         codecs.Save(image, destFileName1, RasterImageFormat.RasPdf, 24)
      End Using

      ' And load it back before saving it as BMP
      Using image As RasterImage = codecs.Load(destFileName1)
         codecs.Save(image, destFileName2, RasterImageFormat.Bmp, image.BitsPerPixel)
      End Using
   Else
      Console.WriteLine("PDF Engine is not found!")
   End If

   ' Clean up
   codecs.Dispose()
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;

      
public void CodecsPdfOptionsExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "PDFSegmentation.pdf");
   string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "PdfOptions.pdf");
   string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "PdfOptions.bmp");

   codecs.Options.Pdf.InitialPath = @"C:\MyApp\Bin";

   // Check if the PDF engine is installed then get the load and save options of the PDF files.
   if (codecs.Options.Pdf.IsEngineInstalled)
   {
      // Resulting image pixel depth.
      codecs.Options.Pdf.Load.DisplayDepth = 24;
      codecs.Options.Pdf.Load.GraphicsAlpha = 4;
      codecs.Options.Pdf.Load.Password = "";

      // Type of font anti-aliasing to use.
      codecs.Options.Pdf.Load.TextAlpha = 1;
      codecs.Options.Pdf.Load.UseLibFonts = true;

      // Horizontal,vertical  display resolution in dots per inch.
      codecs.Options.RasterizeDocument.Load.XResolution = 150;
      codecs.Options.RasterizeDocument.Load.YResolution = 150;

      using (RasterImage image = codecs.Load(srcFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
      {
         // Set access rights for the user when he\she opens the file we create
         codecs.Options.Pdf.Save.AssembleDocument = true;
         codecs.Options.Pdf.Save.ExtractText = true;
         codecs.Options.Pdf.Save.ExtractTextGraphics = true;
         codecs.Options.Pdf.Save.PrintDocument = false;
         codecs.Options.Pdf.Save.FillForm = true;
         codecs.Options.Pdf.Save.ModifyAnnotation = true;
         codecs.Options.Pdf.Save.ModifyDocument = true;
         codecs.Options.Pdf.Save.OwnerPassword = "LEAD Technologies";
         codecs.Options.Pdf.Save.PrintFaithful = false;
         codecs.Options.Pdf.Save.TextEncoding = CodecsPdfTextEncoding.Hex;
         codecs.Options.Pdf.Save.Use128BitEncryption = true;
         codecs.Options.Pdf.Save.UserPassword = "LEAD";
         // Set the PDF version to be v1.4
         codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V14;

         // Save the image back as PDF
         codecs.Save(image, destFileName1, RasterImageFormat.RasPdf, 24);
      }

      // And load it back before saving it as BMP
      using (RasterImage image = codecs.Load(destFileName1))
      {
         codecs.Save(image, destFileName2, RasterImageFormat.Bmp, image.BitsPerPixel);
      }
   }
   else
   {
      Console.WriteLine("PDF Engine is not found!");
   }

   // Clean up
   codecs.Dispose();
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
CodecsOptionsExamples.prototype.CodecsPdfOptionsExample = function () {
   Tools.SetLicense();
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();

         var srcFileName = "Assets\\PDFSegmentation.pdf";
         var destFileName1 = "PdfOptions.pdf";
         var destFileName2 = "PdfOptions.bmp";

         var srcImage;

         // Resulting image pixel depth.
         codecs.options.pdf.load.displayDepth = 24;
         //codecs.options.pdf.load.GraphicsAlpha = 4;
         codecs.options.pdf.load.password = "";

         // Type of font anti-aliasing to use.
         //codecs.options.pdf.load.TextAlpha = 1;
         //codecs.options.pdf.load.UseLibFonts = true;

         // Horizontal,vertical  display resolution in dots per inch.
         codecs.options.rasterizeDocument.load.xresolution = 150;
         codecs.options.rasterizeDocument.load.yresolution = 150;

         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile), 0, CodecsLoadByteOrder.bgr, 1, 1)
         })
            .then(function (img) {
               srcImage = img;
               // Set access rights for the user when he\she opens the file we create
               codecs.options.pdf.save.assembleDocument = true;
               codecs.options.pdf.save.extractText = true;
               codecs.options.pdf.save.extractTextGraphics = true;
               codecs.options.pdf.save.printDocument = false;
               codecs.options.pdf.save.fillForm = true;
               codecs.options.pdf.save.modifyAnnotation = true;
               codecs.options.pdf.save.modifyDocument = true;
               codecs.options.pdf.save.ownerPassword = "LEAD Technologies";
               codecs.options.pdf.save.printFaithful = false;
               codecs.options.pdf.save.textEncoding = CodecsPdfTextEncoding.None;
               codecs.options.pdf.save.use128BitEncryption = true;
               codecs.options.pdf.save.userPassword = "LEAD";
               // Set the PDF version to be v1.4
               codecs.options.pdf.save.version = CodecsRasterPdfVersion.v14;

               // Save the image back as PDF
               var destFileName = destFileName1;
               return Tools.AppLocalFolder().createFileAsync(destFileName)
            })
            .then(function (saveFile) {
               return codecs.saveAsync(srcImage, LeadStreamFactory.create(saveFile), RasterImageFormat.rasPdf, 24)
            })
            .then(function () {
               srcImage.close();
               // And load it back before saving it as BMP
               codecs.options.pdf.load.password = "LEAD";
               return Tools.AppLocalFolder().getFileAsync(destFileName1)
            })
            .then(function (loadFile) {
               return codecs.loadAsync(LeadStreamFactory.create(loadFile))
            })
            .then(function (img2) {
               srcImage = img2;
               return Tools.AppLocalFolder().createFileAsync(destFileName2)
            })
            .then(function (saveFile) {
               return codecs.saveAsync(srcImage, LeadStreamFactory.create(saveFile), RasterImageFormat.bmp, srcImage.bitsPerPixel)
            })
            .then(function () {
               // Clean up
               srcImage.close();
               codecs.close();
            });
      }
   }
}
using Leadtools;
using Leadtools.Codecs;

      
public async Task CodecsPdfOptionsExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\PDFSegmentation.pdf";
   string destFileName1 = "PdfOptions.pdf";
   string destFileName2 = "PdfOptions.bmp";

   // Resulting image pixel depth.
   codecs.Options.Pdf.Load.DisplayDepth = 24;
   //codecs.Options.Pdf.Load.GraphicsAlpha = 4;
   codecs.Options.Pdf.Load.Password = "";

   // Type of font anti-aliasing to use.
   //codecs.Options.Pdf.Load.TextAlpha = 1;
   //codecs.Options.Pdf.Load.UseLibFonts = true;

   // Horizontal,vertical  display resolution in dots per inch.
   codecs.Options.RasterizeDocument.Load.XResolution = 150;
   codecs.Options.RasterizeDocument.Load.YResolution = 150;

   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   using (RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 0, CodecsLoadByteOrder.Bgr, 1, 1))
   {
      // Set access rights for the user when he\she opens the file we create
      codecs.Options.Pdf.Save.AssembleDocument = true;
      codecs.Options.Pdf.Save.ExtractText = true;
      codecs.Options.Pdf.Save.ExtractTextGraphics = true;
      codecs.Options.Pdf.Save.PrintDocument = false;
      codecs.Options.Pdf.Save.FillForm = true;
      codecs.Options.Pdf.Save.ModifyAnnotation = true;
      codecs.Options.Pdf.Save.ModifyDocument = true;
      codecs.Options.Pdf.Save.OwnerPassword = "LEAD Technologies";
      codecs.Options.Pdf.Save.PrintFaithful = false;
      codecs.Options.Pdf.Save.TextEncoding = CodecsPdfTextEncoding.None;
      codecs.Options.Pdf.Save.Use128BitEncryption = true;
      codecs.Options.Pdf.Save.UserPassword = "LEAD";
      // Set the PDF version to be v1.4
      codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V14;

      // Save the image back as PDF
      string destFileName = destFileName1;
      StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
      try
      {
         await codecs.SaveAsync(srcImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.RasPdf, 24);
      }
      catch (Exception ex)
      {
         string error = "";
         RasterException rasterException = RasterException.FromHResult(ex.HResult);
         if (rasterException != null)
            error = rasterException.Message;
         else
            error = ex.Message;
         Debug.WriteLine(error);
         Assert.Fail(error);
      }
   }

   // And load it back before saving it as BMP
   codecs.Options.Pdf.Load.Password = "LEAD";
   loadFile = await Tools.AppLocalFolder.GetFileAsync(destFileName1);
   using (RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)))
   {
      StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName2);
      await codecs.SaveAsync(srcImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, srcImage.BitsPerPixel);
   }

   // Clean up
   codecs.Dispose();
}
必要条件

ターゲットプラットホーム

参照

参照

CodecsPdfOptionsメンバ
Leadtools.Codecs名前空間
PDF機能の実装