Tiff Image Reversed/Flipped

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics.

Moderators: Tracker Support, TrackerSupp-Daniel, Chris - Tracker Supp, Vasyl-Tracker Dev Team, Sean - Tracker, Andrew - Tracker Support, Tracker - Clarion Support, John - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software, Support Staff, moderators

Post Reply
dblwizard
User
Posts: 43
Joined: Fri May 20, 2005 5:39 pm
Location: Conifer, CO USA

Tiff Image Reversed/Flipped

Post by dblwizard » Tue Jun 17, 2008 7:31 pm

Howdy all,

I have some tiff images that when imported and saved to a PDF the images are flipped over or reversed. By this I dont mean that black is white and white is black. I mean that its like you are looking at the image from the back side of the paper. Is there any demo app or anything that I can use to make sure its not me doing something wrong with the API's? I was going to attach a tiff but it won't let me.

Thanks

dbl

Here is the code that I use to create the pdf and add images to it.

Private Function TiffsToPDFPXC(asFileNamesTiffA() As String) As Variant
On Error GoTo errHandler

Const appMethodName = "TiffsToPDFPXC"

Dim lpPDF As Long
Dim lRC As Long
Dim i As Long

UpdateLog appModuleName & ":" & appMethodName & " Entering", Logging

lpPDF = PXCPDF_Create()

UpdateLog appModuleName & ":" & appMethodName & " Logging - PXCPDF_Create - lpPDF:" & lpPDF, Logging
For i = LBound(asFileNamesTiffA) To UBound(asFileNamesTiffA)
Call PXCPDF_AddImage(lpPDF, asFileNamesTiffA(i), 0)
UpdateLog appModuleName & ":" & appMethodName & " Logging - PXCPDF_AddImage - lpPDF:" & lpPDF, Logging
Next i

TiffsToPDFPXC = PXCPDF_GetBuffer(lpPDF)

lRC = PXC_ReleaseDocument(lpPDF)

UpdateLog appModuleName & ":" & appMethodName & " Exiting", Logging
Exit Function

errHandler:
Err.Record appModuleName, appMethodName, errRaise
Exit Function
Resume
End Function



Private Function PXCPDF_AddImage(lpPDF_A As Long, sFileNameTiffA As String, lpImageA As Long) As Long
On Error GoTo errHandler

Const appMethodName = "PXCPDF_AddImage"

Dim lRC As Long

Dim lDPIX As Long
Dim lDPIY As Long
Dim lpPage As Long

Dim dImageWidth As Double
Dim dImageHeight As Double
Dim dPageWidth As Double
Dim dPageHeight As Double
Dim dPositionX As Double
Dim dPositionY As Double

UpdateLog appModuleName & ":" & appMethodName & " Entering. Parameter: lpPDF(" & lpPDF_A & "), " & _
"sFileNameTiffA(" & sFileNameTiffA & "), lpImageA(" & lpImageA & ")", Logging

lRC = PXC_AddImageA(lpPDF_A, sFileNameTiffA, lpImageA)

If (IS_DS_FAILED(lRC)) Then
PXCPDF_AddImage = -1
Err.Raise lRC, appModuleName & ":" & appMethodName, " Error - PXC_AddImageA: IS_DS_FAILED(). lRC = " & lRC & " Msg:" & GetDSErrorString(lRC)
Exit Function
End If

lRC = PXC_GetImageDimension(lpPDF_A, lpImageA, dImageWidth, dImageHeight)
UpdateLog appModuleName & ":" & appMethodName & " Logging - ImageName:" & sFileNameTiffA & " lpPDF_A=" & lpPDF_A & "* lpImageA=" & lpImageA & "* dImageWidth=" & dImageWidth & "* dImageHeight=" & dImageHeight, Logging

If (IS_DS_FAILED(lRC)) Then
PXCPDF_AddImage = -1
Err.Raise lRC, appModuleName & ":" & appMethodName, " Error - PXC_GetImageDimension: IS_DS_FAILED(). lRC = " & lRC & " Msg:" & GetDSErrorString(lRC)
Exit Function
End If

lRC = PXC_GetImageDPI(lpPDF_A, lpImageA, lDPIX, lDPIY)

If (IS_DS_FAILED(lRC)) Then
PXCPDF_AddImage = -1
Err.Raise lRC, appModuleName & ":" & appMethodName, " Error - PXC_GetImageDPI: IS_DS_FAILED(). lRC = " & lRC & " Msg:" & GetDSErrorString(lRC)
Exit Function
End If

dPositionX = 0
dPositionY = I2L(dImageHeight / lDPIY)
dPageWidth = I2L(dImageWidth / lDPIX)
dPageHeight = I2L(dImageHeight / lDPIY)
Call MakeProportionalSize(dPageWidth, dPageHeight, dImageWidth, dImageHeight)
lRC = PXC_AddPage(lpPDF_A, dPageWidth, dPageHeight, lpPage)

If (IS_DS_FAILED(lRC)) Then
PXCPDF_AddImage = -1
Err.Raise lRC, appModuleName & ":" & appMethodName, " Error - PXC_AddPage: IS_DS_FAILED(). lRC = " & lRC & " Msg:" & GetDSErrorString(lRC)
UpdateLog appModuleName & ":" & appMethodName & " Error - PXC_AddPage: IS_DS_FAILED(). lRC = " & lRC & " Msg:" & GetDSErrorString(lRC), True
Exit Function
End If

lRC = PXC_PlaceImage(lpPage, lpImageA, dPositionX, dPositionY, dPageWidth, dPageHeight)

If (IS_DS_FAILED(lRC)) Then
PXCPDF_AddImage = -1
Err.Raise lRC, appModuleName & ":" & appMethodName, " Error - PXC_PlaceImage: IS_DS_FAILED(). lRC = " & lRC & " Msg:" & GetDSErrorString(lRC)
Exit Function
End If

Call UpdateLog(appModuleName & ":" & appMethodName & " - Exiting.", Logging)
Exit Function

errHandler:
Err.Record appModuleName, appMethodName, errRaise
Exit Function
Resume
End Function

Private Function PXCPDF_Create() As Long
On Error GoTo errHandler

Const appMethodName = "PXCPDF_Create"

Dim lRC As Long
Dim lpPDF As Long

UpdateLog appModuleName & ":" & appMethodName & " Entering", Logging

lRC = PXC_NewDocument(lpPDF, "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", "XXXXXXXXXXXXXXXXXXXX")

If (IS_DS_FAILED(lRC)) Then
On Error GoTo 0
PXCPDF_Create = -1
Err.Raise lRC, appModuleName & ":" & appMethodName, " Error - PXC_NewDocument: IS_DS_FAILED(). lRC = " & lRC & " Msg:" & GetDSErrorString(lRC)
End If

Call PXC_EnableLinkAnalyzer(lpPDF, True)
Call PXC_SetCompression(lpPDF, False, False, ComprType_C_Auto, 100, _
ComprType_I_Auto, ComprType_M_Auto)
PXCPDF_Create = lpPDF
Call UpdateLog(appModuleName & ":" & appMethodName & " - Exiting. lpPDF:" & lpPDF, Logging)
Exit Function

errHandler:
Err.Record appModuleName, appMethodName, errRaise
Exit Function
Resume
End Function

Private Function PXCPDF_GetBuffer(lpPDF_A As Long) As Byte()
On Error GoTo errHandler

Const appMethodName = "PXCPDF_GetBuffer"

Dim lRC As Long
Dim lStreamLength As Long

UpdateLog appModuleName & ":" & appMethodName & " Entering. lpPDF_A:" & lpPDF_A, Logging

Set mobjStream = CreateStreamOnHGlobal(0, -1)
lRC = PXC_WriteDocumentToIStream(lpPDF_A, mobjStream)

If (IS_DS_FAILED(lRC)) Then
UpdateLog appModuleName & ":" & appMethodName & " Error - PXC_WriteDocumentToIStream: IS_DS_FAILED(). lRC = " & lRC & " Msg:" & GetDSErrorString(lRC), Logging
Err.Raise lRC, appModuleName & ":" & appMethodName, " Error - PXC_WriteDocumentToIStream: IS_DS_FAILED(). lRC = " & lRC & " Msg:" & GetDSErrorString(lRC)
Exit Function
End If

Call UpdateLog(appModuleName & ":" & appMethodName & " - Getting Stream Stats. lRC:" & lRC, Logging)
Call mobjStream.Stat(mobjStreamStat)
Call UpdateLog(appModuleName & ":" & appMethodName & " - Stream size:" & mobjStreamStat.cbSize, Logging)
lStreamLength = CLng(mobjStreamStat.cbSize * 10000)
ReDim mabtBuffer(lStreamLength + 2)
mobjStream.Seek 0, STREAM_SEEK_SET
lRC = mobjStream.Read(mabtBuffer(0), lStreamLength)
PXCPDF_GetBuffer = mabtBuffer
Set mobjStream = Nothing

Call UpdateLog(appModuleName & ":" & appMethodName & " - Exiting.", Logging)

Exit Function

errHandler:
Err.Record appModuleName, appMethodName, errRaise
Exit Function
Resume
End Function

Ivan - Tracker Software
Site Admin
Posts: 3587
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Tiff Image Reversed/Flipped

Post by Ivan - Tracker Software » Wed Jun 18, 2008 3:44 pm

Unfortunately - because your serial/registration info was published in your post, we have now had to add it to the black list!

Before you can therefore use any updates published - you will need to request a new serial number from upgrads@tracker-software.com and provide your proof of purchase info - this cannot be done via the forum - only by contacting us by email direct.

Also - with regards your image conversion issues specifically :

It is because within this TIFF file (supplied in your mail) there is embedded information (TIFF Tag ID 0x112) that the image should be rotated and flipped - hence when converting - PDF-Tools is doing just that.

Only in reasonably simple Image viewers is this Tag ignored - if you open with something like: Photoshop, IrfanView, XnView, or our own Image-Xchange - this tag is read and applied.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

dblwizard
User
Posts: 43
Joined: Fri May 20, 2005 5:39 pm
Location: Conifer, CO USA

Re: Tiff Image Reversed/Flipped

Post by dblwizard » Wed Jun 18, 2008 6:18 pm

I'm sorry about posting the serial number in the forum. I was late and I wasn't thinking very well. I will look into the issue and see why that flag is set.

Thanks

dbl

John - Tracker Supp
Site Admin
Posts: 8201
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Re: Tiff Image Reversed/Flipped

Post by John - Tracker Supp » Thu Jun 19, 2008 10:26 am

No problem :)
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Post Reply