Page 1 of 1

PXC_WriteDocumentToIStream

Posted: Mon May 23, 2005 1:54 pm
by dblwizard
Hello,

I am evaluating your product for use in our websites to convert Tiffs to PDF's.

I am trying to use the PXC_WriteDocumentToIStream. I have found a way to have access to the IStream object in VB through a 3rd party TLB and thus here is the Declare that I have come up with.

Public Declare Function PXC_WriteDocumentToIStream Lib "pxclib30.dll" (ByVal pdf As Long, ByVal stream As IStream) As Long

But I can not get this to work. I have tried using the WindowsAPI CreateStreamOnHGlobal as well as VarPtr but when I call PXC_WriteDocumentToIStream the stream object has no data in it. If I call the PXC_WriteDocumentA it creates a PDF just fine.

Here is the code that I am using:

Dim lPDF As Long
Dim lRC As Long
Dim sBuffer As String
Dim oBuffer As IUnknown
Dim objStream As IStream

lRC = PXC_NewDocument(lPDF, "<YOUR REG KEY>", "<YOUR DEV CODE>")

If (IS_DS_FAILED(lRC)) Then
Set GetPDF = Nothing
Exit Function
End If

Call PXC_EnableLinkAnalyzer(lPDF, True)
Call PXC_SetCompression(lPDF, False, False, ComprType_C_Auto, 75, _
ComprType_I_Auto, ComprType_M_Auto)

Dim images() As Long
Dim pages_count As Long
Dim lImage As Long
Dim page As Long
Dim iw As Double
Dim ih As Double
Dim w As Double
Dim h As Double
Dim x As Double
Dim y As Double
Dim fl As Integer
Dim k As Integer
Dim buf As Long


Dim l_hGlobal As Long
Dim l_Ptr As Long
Dim l_Size As Long
Dim p_aBytes() As Byte

lRC = PXC_AddImageExA(lPDF, sFileNameA, 0, 0)

If (IS_DS_FAILED(lRC)) Then
Set GetPDF = Nothing
Exit Function
End If

If (lRC <> 0) Then
pages_count = lRC
ReDim images(pages_count - 1)
buf = VarPtr(images(0))
lRC = PXC_AddImageA(lPDF, sFileNameA, lImage)

If (IS_DS_FAILED(lRC)) Then
Set GetPDF = Nothing
Exit Function
End If

lRC = PXC_GetImageDimension(lPDF, lImage, iw, ih)

If (IS_DS_FAILED(lRC)) Then
Set GetPDF = Nothing
Exit Function
End If

x = I2L(0)
y = I2L(11)
w = I2L(8.5)
h = I2L(11)

Call MakeProportionalSize(w, h, iw, ih)

lRC = PXC_AddPage(lPDF, PW, PH, page)

If (IS_DS_FAILED(lRC)) Then
Set GetPDF = Nothing
Exit Function
End If

lRC = PXC_PlaceImage(page, lImage, x, y, w, h)

If (IS_DS_FAILED(lRC)) Then
Set GetPDF = Nothing
Exit Function
End If

lRC = PXC_CloseImage(lPDF, lImage)
buf = VarPtr(sBuffer)
' Set objStream = CreateStreamOnHGlobal(0, True)
lRC = PXC_WriteDocumentToIStream(lPDF, oBuffer)

PXC_ReleaseDocument (lPDF)
GetPDF = oBuffer

Can somebody tell me what I am doing wrong?

Thanks


dblwizard

Posted: Tue May 24, 2005 3:53 pm
by John - Tracker Supp
Hi,

please find attached revised DLL - there was an issue with the required function and also have made some small modifications to your code - please see that also.

PXC_WriteDocumentToIStream

Posted: Wed May 25, 2005 7:34 am
by dblwizard
Ok,

I do that and now I get a value for the long pointer. But I need access to the byte array. I'm not seeing anyway to get that from this pointer. I had a better understanding with the IStream object but all I get from that is Zeros when I do the Read. How can I get access to the Byte array?

Thanks

dbl

Posted: Wed May 25, 2005 9:33 am
by John - Tracker Supp
HI,

I suspect the issue is because after writing data to IStream the internal pointer is at the end of this stream and to read the full data set it is necessary to re-set the pointer to the beginning of the IStream object (using it's Seek function).

Hope that helps

PXC_WriteDocumentToIStream

Posted: Wed May 25, 2005 4:43 pm
by dblwizard
Yep that was the problem. I did a seek to the beginning of the stream and it is working fine now. Thanks

Posted: Thu May 26, 2005 9:29 am
by John - Tracker Supp
Pleasure - pleased all is well ;)