Posted by a ceTe Software moderator
Hello,
It is not efficient to call the DrawToWeb and DrawToFile methods on the same Document object as it generates the PDF twice. A better approach would be to call the Draw method to generate the document once and take the PDF byte array and save it to file and send it to browser using the BinaryWrite method. See the sample code below.
<!-- METADATA TYPE="typelib" UUID="{DF9225FE-94A4-490D-8CAD-E8366CE621D3}"-->
<%
'The METADATA tag above was added to import the constants (i.e. DPDF_Font_Helvetica).
Option Explicit
Dim MyDocument, MyPage
Dim MyStrText
' Create Document object and set properties
Set MyDocument = Server.CreateObject( "DynamicPDF.Document" )
MyDocument.Creator = "HelloWorld.asp"
MyDocument.Author = "test"
MyDocument.Title = "Hello World"
' Add a page to the document
Set MyPage = MyDocument.AddPage()
' Add a textarea to the page
MyStrText = "Hello ASP World..." & vbCrLf & "From DynamicPDF™ Generator for COM/ActiveX" & vbCrLf & "DynamicPDF.com"
MyPage.AddTextArea MyStrText, 0, 0, 504, 100, DPDF_TextAlign_Center, DPDF_Font_Helvetica, 18
' use the Draw method of output the PDF as byte array.
Dim MyDocByte
MyDocByte = MyDocument.Draw()
'create a stream object to save the PDF byte array to disk
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - save binary data.
BinaryStream.Type = 1
'Open the stream And write the PDF byte array
BinaryStream.Open
BinaryStream.Write MyDocByte
'Call to save the PDF to disk
BinaryStream.SaveToFile Server.MapPath("test123.pdf"), 2
' take the PDF byte array and stream it to the browser.
Response.Clear()
Response.ContentType = "application/pdf"
Response.Buffer = True
Response.BinaryWrite( MyDocByte )
Set Mypage = Nothing
Set MyDocument = Nothing
Set BinaryStream = Nothing
%>
We were unable to reproduce the error you were getting with DrawToWeb on our end but it could be due to calling the DrawToFile right after or it could be due to the product build you are using which might have an issue with that method, in which case please download and use the latest build from the
customer area.
Thanks,
ceTe Software Support Team.