Aspose.Pdf for.NET18.2での質問

Pdfファイルの結合についてFacadesクラスを使用した処理から
Documentクラスを使用した処理への変更を考えております。

Facadesクラスの場合、Pdfファイルの結合を行うPdfFileEditorクラスの
Appends、Concatenateメソッドは(inputstream)パラメータとして
Stream配列をとることができますがDocumentクラスの
Pdfファイルの結合を行うメソッドでStream配列を扱えるものはありますでしょうか。
(結合を行うメソッドはAddメソッドのみで
Stream配列はパラメータとしてとることができない認識です)

よろしくお願いします。

@yuji.takashima,

PdfFileEditorクラスのConcatenateメソッド以外のPDFドキュメントを連結するストリーム配列を渡す方法はありません。 PageCollectionクラスのAddメソッドは、2番目のPDFドキュメントのページコレクションのみを取ります。複数のPDFドキュメントをDocumentクラスと連結するには、ストリーム配列を反復処理し、ストリームインスタンスをDocumentクラスにロードし、ページコレクションを取得して、対象のPDFドキュメントのAddメソッドに渡します。

対応できました。ご回答ありがとうございました。

すみません、追加で質問があります。

TextStampクラスのインスタンスにスタンプするテキストをセットしてテキストの高さを取得する場合、下記のコードでテキスト高さを取得することは可能でしょうか。

Dim txt_style As Aspose.Pdf.Text.TextState = New Aspose.Pdf.Text.TextState(“Times New Roman”, 12)
Dim txt_stamp As Aspose.Pdf.TextStamp = New Aspose.Pdf.TextStamp(“TEST STRING”, text_style)
MsgBox(txt_stamp.Height)

上記の実行したところ結果は“0”となっておりました。
コンストラクタでNewした場合には高さは値としてセットされない認識でよろしいでしょうか。
その場合、下記のFacadesクラスのものと同様の値を取得できる属性はTextStampクラスには存在しないでしょうか。

Dim fmtd_txt As Aspose.Pdf.Facades.FormattedText = New Aspose.Pdf.Facades.FormattedText(“TEST STRING”, ~省略~, 12)
MsgBox(fmtd_txt.TextHeight)

よろしくお願いします。

@yuji.takashima,

PageインスタンスのAddStampメソッドを呼び出した後、TextFragmentAbsorberクラスで同じテキストを取得し、絶対矩形座標を取得できます。
C#

// Open document
Document pdfDocument = new Document(dataDir + "EmptyPDF.pdf");            
// Create text stamp
TextStamp textStamp = new TextStamp("Sample Stamp");
// Set whether stamp is background
textStamp.Background = true;
// Set origin
textStamp.XIndent = 100;
textStamp.YIndent = 100;
// Rotate stamp
textStamp.Rotate = Rotation.on90;
// Set text properties
textStamp.TextState.Font = FontRepository.FindFont("Arial");
textStamp.TextState.FontSize = 14.0F;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.FontStyle = FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua);
// Add stamp to particular page
pdfDocument.Pages[1].AddStamp(textStamp);

// Create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Sample Stamp");
// Accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorber);
// Get the extracted text fragments
TextFragment textFragment = textFragmentAbsorber.TextFragments[1];
Console.WriteLine(textFragment.Rectangle.Height);
Console.WriteLine(textFragment.Rectangle.Width);

TextFragmentAbsorberクラスのコンストラクタは、カスタマイズ方法でテキストを取得できます。テキストフレーズと正規表現を使用します。このヘルプトピックを参照してください:PDFドキュメントのページからのテキストの検索と取得

すみません、また追加で質問があります。
Documentクラスのリソースの開放について以下の質問をさせてください。

DocumentクラスはIDisposableインターフェイスを実装しており、
リソースの開放はDisposeの呼び出しで行う認識ですが
明示的にDisposeの呼び出しを行わなかった場合、リソースの開放は
Finalizeメソッドにより行われる認識でよろしいでしょうか。

例えば下記のようなコードの場合、
パラメータ内でNewされたインスタンスのリソースは
インスタンスがガベージコレクションに収集される前にFinalizeメソッドにより
解放される認識でよろしいでしょうか。

Dim pdf As Aspose.Pdf.Document = New Aspose.Pdf.Document(pdf_file_path_array(0))
‘pdf_file_path_array はPDFファイルのパスを格納したString型配列です
For i As Integer = 1 To pdf_file_path_array.Length - 1
pdf.Pages.Add(New Aspose.Pdf.Document(pdf_file_path_array(i).Pages))
Next
pdf.Save(out_put_pdf_file_path)
‘out_put_pdf_file_path はPDFファイルの保存先パスを格納したString型変数です
pdf.Dispose()

よろしくお願いします。

@yuji.takashima,

Documentクラスインスタンスですべての操作を処理した後、クライアントがDisposeメソッドを呼び出すことをお勧めします。操作の間、リソースを保持します。ストレージ。リソースを解放するには、Disposeメソッドを呼び出す必要があります。