I have attached both the original image and the created Pdf file.
I have tried a color lzw image, and that works fine, so I'm thinking that there is something that it doesn't like with the palette.
Any suggestions?
I am using pxclib40 v4.0.212.0
This is the code that I was using to produce the result.
Code: Select all
Public Sub AddImages(ByVal sourceFile As String, ByVal pageWidthInInches As Double, ByVal pageHeightInInches As Double)
Dim res As Integer
Dim pp As IntPtr = IntPtr.Zero
Try
Dim pageWidth As Double = PDFXC.I2L(pageWidthInInches)
Dim pageHeight As Double = PDFXC.I2L(pageHeightInInches)
Dim npages As Integer = PDFXC.PXC_AddImageExA(_pdf, sourceFile, IntPtr.Zero, 0)
CheckReturnValue(npages)
Dim pages = New Integer(npages - 1) {}
For pageno As Integer = 0 To npages - 1
pages(pageno) = pageno + 1
Next
pp = Runtime.InteropServices.Marshal.AllocHGlobal(npages * IntPtr.Size)
res = PDFXC.PXC_AddImageExA(_pdf, sourceFile, pp, npages)
CheckReturnValue(res)
Dim p4() As Integer = Nothing
p4 = New Integer(npages - 1) {}
Runtime.InteropServices.Marshal.Copy(pp, p4, 0, npages)
Runtime.InteropServices.Marshal.FreeHGlobal(pp)
pp = IntPtr.Zero
For Each pageno As Integer In pages
Dim page As IntPtr
CheckReturnValue(PDFXC.PXC_AddPage(_pdf, pageWidth, pageHeight, page))
Dim img As IntPtr = New IntPtr(p4(pageno - 1))
Dim imageWidth As Double
Dim imageHeight As Double
Dim xDPI As Integer
Dim yDPI As Integer
CheckReturnValue(PDFXC.PXC_GetImageDimension(_pdf, img, imageWidth, imageHeight))
CheckReturnValue(PDFXC.PXC_GetImageDPI(_pdf, img, xDPI, yDPI))
If xDPI <= 0 Then xDPI = 96
If yDPI <= 0 Then yDPI = 96
Dim scaleW As Double
Dim scaleH As Double
GetScaleFactors(imageWidth, imageHeight, xDPI, yDPI, pageWidth, pageHeight, scaleW, scaleH)
CheckReturnValue(PDFXC.PXC_PlaceImage(page, img, 0, pageHeight, pageWidth * scaleW, pageHeight * scaleH))
Next
Finally
If pp <> IntPtr.Zero Then
Runtime.InteropServices.Marshal.FreeHGlobal(pp)
End If
End Try
End SubI just tried using PXC_AddImageFromHBITMAP using the code below and everything worked nicely.
Code: Select all
Public Sub AddImageFromBitmap(ByVal b As Bitmap, ByVal pageWidthInInches As Double, ByVal pageHeightInInches As Double)
Dim palette As IntPtr = IntPtr.Zero
Dim hBitmap As IntPtr = IntPtr.Zero
Try
palette = CreateWinPalette(b.Palette)
hBitmap = b.GetHbitmap()
Dim img As IntPtr
CheckReturnValue(PDFXC.PXC_AddImageFromHBITMAP(_pdf, hBitmap, palette, img))
Dim imageHorizontalResolution As Double = b.HorizontalResolution
If imageHorizontalResolution <= 0 Then imageHorizontalResolution = 96
Dim imageVerticalResolution As Double = b.VerticalResolution
If imageVerticalResolution <= 0 Then imageVerticalResolution = 96
Dim scaleW As Double
Dim scaleH As Double
Dim pageWidth As Double = PDFXC.I2L(pageWidthInInches)
Dim pageHeight As Double = PDFXC.I2L(pageHeightInInches)
GetScaleFactors(b.Width, b.Height, imageHorizontalResolution, imageVerticalResolution, pageWidth, pageHeight, scaleW, scaleH)
Dim page As IntPtr
CheckReturnValue(PDFXC.PXC_AddPage(_pdf, pageWidth, pageHeight, page))
CheckReturnValue(PDFXC.PXC_PlaceImage(page, img, 0, pageHeight, pageWidth * scaleW, pageHeight * scaleH))
Finally
If hBitmap <> IntPtr.Zero Then DeleteObject(hBitmap)
If palette <> IntPtr.Zero Then DeleteObject(palette)
End Try
End Sub