activePDF Toolkit 2011 API リファレンス
インメモリ生成
チュートリアル > インメモリ生成

Glossary Item Box

Toolkit を使用して PDF を "インメモリ" で生成できます。インメモリでのPDF の生成は、処理中にハードディスク上のファイルへのアクセスやファイルを保存する必要がありません。また出力結果を直接クライアントのブラウザに提供できるため非常に便利です。

このチュートリアルでは、Toolkit を使用した 2 つの方法を紹介します。最初のサンプルでは、PDF を "インメモリ" で生成します。2 つ目のサンプルでは、PDF の出力ファイルを生成して、ブラウザに提供します。

このサンプルでは、activePDF Toolkit の "インメモリ" 生成機能を使用します。次のスクリプトは、結果出力の PDF を作成するために、どのように "インメモリ" 入力ストリームを使用するかを説明します。

サンプル - インメモリの生成

'Instantiate Toolkit object
Set objTK = CreateObject("APToolkit.Object")

'Open output file
varReturn = objTK.OpenOutputFile ("MEMORY")
If varReturn <> 0 Then Error("OpenoutputFile") End If

For i = 1 To 15
    objTK.SetFont "Helvetica", 15
    objTK.NewPage
Next

'Close the output file
objTK.CloseOutputFile

'Write this output to a variable
x = objTK.OutputByteStream
r = objTK.OpenOutputFile("output.pdf")

'Retrieve the output bytestream
objTK.InputByteStream = x
r = objTK.OpenInputFile("MEMORY")
objTK.SetHeaderTextColorCMYK 0, 100, 10, 0

'Let's load a font from disk
objTK.SetHeaderFont "Verdana Bold Italic", 20
objTK.SetHeaderText 300, 600, "activePDF Toolkit"

'Copy Memory to the output file
varReturn = objTK.CopyForm(0, 0)
If varReturn <> 1 Then Error("CopyForm") End If
'Close Output File
objTK.CloseOutputFile

'Release Toolkit Object
Set objTK = Nothing

'Done
Msgbox "Success!"

' Error Handling
Sub Error(Method)
    Msgbox "'" & Method & "' failed with a '" & varReturn & _
            "'" & VBCRLF & "TK Return Codes:" & VBCRLF & _
            "http://www.activepdf.com/support/kb/?id=10670&tk=ts"
    Set objTK = Nothing
    Wscript.Quit
End Sub


サンプル - ブラウザへのコンテンツ配信

このチュートリアルでは、Toolkit を使用して PDF 文書を "インメモリ" で生成し、ブラウザに配信します。

注意: このサンプル スクリプトは ASP で記述されています。



<%
'Tell ASP not to serve the page until entire page is processed
'Very Important
response.buffer = True

Set objTK = Server.CreateObject("APToolkit.Object")

'Tell Toolkit to create the PDF in memory
r = objTK.OpenOutputFile("MEMORY")

'SetFont will generate a new blank page and set the font to be used
'PrintText adds text to our new page
objTK.SetFont "Helvetica", 15
objTK.PrintText 15, 760, "activePDF Memory Example"

'Close our generated PDF
objTK.CloseOutputFile

'Write the output to memory as a BinaryImage
zz = objTK.binaryImage

'Tell the browser not to cache PDF
response.expires = 0

'Clear response buffer
response.Clear

'Tell browser what type of file it is opening
response.ContentType = "application/pdf"
response.AddHeader "Content-Type", "application/pdf"
response.AddHeader "Content-Disposition", "inline;filename=Example.pdf"

'Write the PDF in memory to the browser
response.BinaryWrite zz 'now let's write to the browser

Set objTK = Nothing

%>