[C#/VB.NET] PDF to TIFF using Color Detection

Discussions about color detection and MRC support.
Post Reply

Ken
Posts: 5
Joined: Fri Jun 12, 2015 12:58 am

Re: [C#/VB.NET] PDF to TIFF using Color Detection

Post by Ken » Fri Jun 12, 2015 1:10 am

I used the sample code provided to convert PDF to TIFF using color detection however some of the image disappears in the tif file. If I do not use color detection then all the lines appear. I've uploaded two tiff files. GrayWallProblem.tif which is missing lines and GrayWall_Correct.tif which is how it should look. GrayWallProblem.tif was created using ColorDectection. Any insight on this would be appreciated. Thank you.

Code: Select all

Private Sub CreateTiffs(File As String, OutputFilePath As String, RevisionNumber As String)
        Dim oGdPicturePDF As New GdPicturePDF
        Dim oGdPictureImaging As New GdPictureImaging

        If oGdPicturePDF.LoadFromFile(File, False) = GdPictureStatus.OK Then
            Dim tiffID As Integer = 0
            Dim PageCount As Integer = oGdPicturePDF.GetPageCount()
            Me.ProgressBar1.Maximum = PageCount
            For i As Integer = 0 To PageCount - 1
                oGdPicturePDF.SelectPage(i + 1)
                'rasterize page or extract page bitmap.
                Dim rasterPage As Integer = oGdPicturePDF.RenderPageToGdPictureImageEx(200.0F, True, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
                Dim tiffCompression__1 As TiffCompression = TiffCompression.TiffCompressionCCITT4 'defines the compression of the tiff page. Let's use CCITT4 for bitonal pages and JPEG for others.
                'apply color detection and color depth automatic conversion.
                'oGdPictureImaging.ColorDetection(rasterPage, True, False, False)
                'If oGdPictureImaging.GetBitDepth(rasterPage) = 1 Then
                '    tiffCompression__1 = TiffCompression.TiffCompressionCCITT4
                'Else
                '    tiffCompression__1 = TiffCompression.TiffCompressionJPEG
                'End If

                If i = 0 Then
                    oGdPictureImaging.TiffSaveAsMultiPageFile(rasterPage, OutputFilePath, tiffCompression__1)
                    'first rasterizer page GdPicture ID becomes the multipage tiff id.
                    tiffID = rasterPage
                Else
                    oGdPictureImaging.TiffAddToMultiPageFile(tiffID, rasterPage, tiffCompression__1)
                    oGdPictureImaging.ReleaseGdPictureImage(rasterPage)
                End If
                Me.ProgressBar1.Value += 1
            Next
            oGdPictureImaging.TiffCloseMultiPageFile(tiffID)
            oGdPictureImaging.ReleaseGdPictureImage(tiffID)
            Me.ProgressBar1.Value = 0
            SplitTif(OutputFilePath, "original")
            GC.Collect()
            GC.WaitForPendingFinalizers()
        Else
            MessageBox.Show("Can not open file. Status: " + oGdPicturePDF.GetStat().ToString())
        End If
    End Sub
Attachments
GrayWall_Correct.tif
This was created without color detection.
GrayWall_Correct.tif (830.59 KiB) Viewed 3434 times
GrayWallProblem.tif
This was created with color detection.
GrayWallProblem.tif (47.65 KiB) Viewed 3434 times

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

Re: [C#/VB.NET] PDF to TIFF using Color Detection

Post by Loïc » Fri Jun 12, 2015 10:32 am

Hello Ken,

That's an interesting case. We've enhanced the engine to produce the attached result. If our regressive tests are good the next minor release will fix it.
GrayWall_Correct.png
Kind regards,

Loïc

Ken
Posts: 5
Joined: Fri Jun 12, 2015 12:58 am

Re: [C#/VB.NET] PDF to TIFF using Color Detection

Post by Ken » Fri Jun 12, 2015 7:52 pm

When is the minor release scheduled?

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

Re: [C#/VB.NET] PDF to TIFF using Color Detection

Post by Loïc » Sat Jun 13, 2015 10:12 am

On next Monday.

Ken
Posts: 5
Joined: Fri Jun 12, 2015 12:58 am

Re: [C#/VB.NET] PDF to TIFF using Color Detection

Post by Ken » Mon Jun 15, 2015 11:43 pm

When using ColorDetection with AutoConvert when the bitdepth = 1 GDPicture converts the image to a mode that when the tif file is opened in Adobe PhotoShop the image mode is "Bitmap" (don't confuse this with the file type bmp; it's not a bitmap file, its image mode is Bitmap) What GDPictureImaging.ConvertTo method do I need to use to duplicate the same AutoConvert during ColorDetection? The end result is that when I open the Tif in PhotoShop it should have an Image Mode of Bitmap. Thanks.

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

Re: [C#/VB.NET] PDF to TIFF using Color Detection

Post by Loïc » Tue Jun 16, 2015 9:00 am

Hi Ken,

Could you clarify please? I do not understand a word of what you are trying to explain.

Thank you for your efforts.

With best regards,

Loïc

Ken
Posts: 5
Joined: Fri Jun 12, 2015 12:58 am

Re: [C#/VB.NET] PDF to TIFF using Color Detection

Post by Ken » Tue Jun 16, 2015 10:14 pm

Using the code below, I am converting pdf to tiff using ColorDetection. I have the AutoConvert parameter set to True. After the tiff files are saved I open them in PhotoShop. The "Image Mode" is Bitmap (see attached image). What conversion is used during the AutoConvert process to make a tiff file with an Image Mode of Bitmap?

Code: Select all

                                PDFPageID = oGdPicturePDF.RenderPageToGdPictureImageEx(200.0F, False, Imaging.PixelFormat.Format24bppRgb)
                                oGdPictureImaging.ColorDetection(PDFPageID, True, False, False)
                                If oGdPictureImaging.GetBitDepth(PDFPageID) = 1 Then
                                    Compression = TiffCompression.TiffCompressionCCITT4
                                Else
                                    Compression = TiffCompression.TiffCompressionJPEG
                                End If
                                oGdPictureImaging.TiffSaveAsMultiPageFile(PDFPageID, FullOutputFileName, Compression)
                                oGdPictureImaging.TiffCloseMultiPageFile(PDFPageID)
                                oGdPictureImaging.ReleaseGdPictureImage(PDFPageID)

Attachments
PhotoShopBitmap.jpg

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

Re: [C#/VB.NET] PDF to TIFF using Color Detection

Post by Loïc » Thu Jun 18, 2015 3:14 pm

I don't understand what the problem is. What did you expect to obtain instead of Bitmap?
In your case the produced document is bitonal, using black & white color palette entries.

Kind regards,

Loïc

Ken
Posts: 5
Joined: Fri Jun 12, 2015 12:58 am

Re: [C#/VB.NET] PDF to TIFF using Color Detection

Post by Ken » Thu Jun 18, 2015 6:05 pm

I'm sorry that I am not being clear. How do I produce the same result without using ColorDection. How do I take a color pdf and make a tiff that has an Image Mode of bitmap??

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest