PdfReaderRenderPageToGdPictureImage and bitonal content

Discussions about image processing and document imaging.
Post Reply
sbarlow
Posts: 31
Joined: Fri Jun 19, 2009 3:13 pm

PdfReaderRenderPageToGdPictureImage and bitonal content

Post by sbarlow » Thu Aug 05, 2010 4:52 pm

Hi, I'm having an issue when converting from a PDF with B&W image content to a multipage TIFF

After using the PdfReaderRenderPageToGdPictureImage method , and using TiffSaveAsMultiPageFile(MultiPageID, ImagefileName, TiffCompression.TiffCompressionAUTO)

the tiff pages are always LZW compressed, instead of what I was hoping for, CCITT4

Does the output from PdfReaderRenderPageToGdPictureImage always do this, and is there a workaround

Thanks,

Scott

Code: Select all

Public Function PDFtoTIFF(ByVal FileName As String) As String
            Dim MultiPageID As Integer = 0
            Try
                'this is just a call to a method to create a unique file name
                Dim ImagefileName As String = CreateNewFileName("tif")
                'PDF to converted
                Dim InputPDFID As Integer = GDP.PdfReaderLoadFromFile(FileName)
                Dim pageCount As Integer = GDP.PdfReaderGetPageCount(InputPDFID)
                Dim cStat As GdPictureStatus = GdPictureStatus.OK
                For nImageCount As Integer = 1 To pageCount
                    If GDP.PdfReaderSelectPage(InputPDFID, nImageCount) = True Then
                        Dim ImageID As Integer = GDP.PdfReaderRenderPageToGdPictureImage(InputPDFID, 300, True)
                        If ImageID <> 0 Then
                            If nImageCount = 1 Then
                                MultiPageID = ImageID
                                Debug.Print(GDP.IsBitonal(ImageID).ToString)
                                Debug.Print(GDP.GetBitDepth(ImageID).ToString)
                                cStat = GDP.TiffSaveAsMultiPageFile(MultiPageID, ImagefileName, TiffCompression.TiffCompressionAUTO)
                                Application.DoEvents()
                            Else
                                Debug.Print(GDP.IsBitonal(ImageID).ToString)
                                Debug.Print(GDP.GetBitDepth(ImageID).ToString)
                                cStat = GDP.TiffAddToMultiPageFile(MultiPageID, ImageID)
                                Application.DoEvents()
                                GDP.ReleaseGdPictureImage(ImageID)
                            End If
                        End If
                        If cStat <> GdPictureStatus.OK Then
                            Throw New ApplicationException("Conversion failed")
                        End If
                    Else
                        Throw New ApplicationException("Conversion failed")
                    End If
                Next nImageCount
            Catch ex As Exception
                'just a method to alert user
                'Info(Constants.msgUnableToConvert)
                Return ""
            End Try
            GDP.TiffCloseMultiPageFile(MultiPageID)
            GDP.ReleaseGdPictureImage(MultiPageID)
            Return ImagefileName
        End Function

User avatar
Loïc
Site Admin
Posts: 5745
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: PdfReaderRenderPageToGdPictureImage and bitonal content

Post by Loïc » Thu Aug 05, 2010 5:48 pm

Hi Scott,

The rasterizer engine always generate color output image.

If you want to get a bitonal image you have just to use the ConvertTo1Bpp method. If you want to extract image from PDF in its native bitdepth you should use the PdfReaderRenderExtractImage method.

Kind regards,

Loïc

sbarlow
Posts: 31
Joined: Fri Jun 19, 2009 3:13 pm

Re: PdfReaderRenderPageToGdPictureImage and bitonal content

Post by sbarlow » Thu Aug 05, 2010 6:14 pm

Loïc wrote:Hi Scott,

The rasterizer engine always generate color output image.

If you want to get a bitonal image you have just to use the ConvertTo1Bpp method. If you want to extract image from PDF in its native bitdepth you should use the PdfReaderRenderExtractImage method.

Kind regards,

Loïc
Thanks Loïc,

But that poses another problem , although the following snippet works, it won't work if the original PDF page was a combination of images and vector graphics or other content , and the image count on the page = 1 (if count > 1 then I just render it). What happens is that the rest of the content other than the image will be lost , meaning I should have rendered it instead. I have no way of knowing if the original pdf page was a mixture of different content to be able to make the decision

I guess what I would need is a way to determine if this a only a Image based PDF page (maybe with extracted text) , in which case I can use the PdfReaderExtractImage without a problem.

If GDP.PdfReaderGetImageCount(InputPDFID) = 1 Then
ImageID = GDP.PdfReaderExtractImage(InputPDFID, 1)
Else
ImageID = GDP.PdfReaderRenderPageToGdPictureImage(InputPDFID, 300, True)
End If

Thanks,
Scott

User avatar
Loïc
Site Admin
Posts: 5745
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: PdfReaderRenderPageToGdPictureImage and bitonal content

Post by Loïc » Fri Aug 06, 2010 9:30 am

Hi Scott,

I think I have a better idea: Use the IsGrayscale method on the generated image. If true, convert it to 1bpp, if false convert to 24bpp.

What do you mind ?

Kind regards,

Loïc

sbarlow
Posts: 31
Joined: Fri Jun 19, 2009 3:13 pm

Re: PdfReaderRenderPageToGdPictureImage and bitonal content

Post by sbarlow » Fri Aug 06, 2010 1:13 pm

Do you mean from the output from the output of PdfReaderRenderPageToGdPictureImage ?

Scott

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests