Sign In  Sign Up Live-Chat

PDF to TIFF conversion

Last post 07-02-2008, 1:29 AM by codewarior. 1 replies.
Sort Posts: Previous Next
  •  07-01-2008, 6:54 PM 133876

    PDF to TIFF conversion

    Hi Mdm/Sir,

    How do I set the image property to black and white (monochrome) when convert from PDF to Tiff using PdfConverter?

    Thank You.

    Kind Regards,

    Caymond

     
  •  07-02-2008, 1:29 AM 133894 in reply to 133876

    Re: PDF to TIFF conversion

    Hello Caymond,

    Thanks for considering Aspose.

    I am sorry to inform you that currently PdfConverter has no such property that can be used for converting Pdf to Monochrome Tiff. As a work around this can be done through code.

    First convert the Pdf to Tiff, than we need to convert Tiff to BMP (as we cannot convert Colored Tiff to Monochrome Tiff directly) & than convert the BMP to Monochrome and save as Tiff.

    Please see the following code snippet developed in C#.Net

    PdfConverter converter = new PdfConverter();
    converter.BindPdf(
    @"C:\Temp\UpdaetdFormated.pdf");
    converter.DoConvert();
    converter.SavaAsTIFF(
    @"C:\Temp\Converted.tiff");

    // Code to convert Tiff file to BMP

    Guid myGuid;
    FrameDimension myDimension;
    int myPageCount;
    Image myImage;

    FileStream fs = new FileStream("C:\\Temp\\Converted.tiff", FileMode.Open);
    myImage =
    Image.FromStream(fs);
    myGuid = myImage.FrameDimensionsList[0];
    myDimension =
    new FrameDimension(myGuid);
    myPageCount = myImage.GetFrameCount(myDimension);

    for (int i = 0; i < myPageCount; i++)
    {
    myImage.SelectActiveFrame(myDimension, i);
    myImage.Save(
    "C:\\temp\\ConvertedtoBMP.BMP", ImageFormat.Bmp);
    }
    fs.Close();

    // Code to convert BMP to Monochrome and Save in Tiff Format

    Image img = new Bitmap("C:\\temp\\ConvertedtoBMP.BMP");
    Bitmap bm = new Bitmap(img.Width, img.Height);
    Graphics g = Graphics.FromImage(bm);
    ColorMatrix cm = new ColorMatrix(new float[][]{ new float[]{0.5f,0.5f,0.5f,0,0},
    new float[]{0.5f,0.5f,0.5f,0,0},
    new float[]{0.5f,0.5f,0.5f,0,0},
    new float[]{0,0,0,1,0,0},
    new float[]{0,0,0,0,1,0},
    new float[]{0,0,0,0,0,1}});

    ImageAttributes ia = new ImageAttributes();

    ia.SetColorMatrix(cm);
    g.DrawImage(img,
    new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
    g.Dispose();
    bm.Save(
    "C:\\Temp\\Monochrome.tiff", ImageFormat.Tiff);

    For conversion of BMP to monochrome we have used ColorMatrix Class.


    Nayyer Shahbaz
    Support Developer
    Aspose Changsha Team
    About Us
     
View as RSS news feed in XML