tags:

views:

1176

answers:

4

IM using the TWAIN Scanner & gdiplus.dll.

i scanned the file , and can save as image format like *.jpg, *.bmp

but it is not allow to save as in PDF format. Showing an error unknown format picture.

this is the code,


public static bool SaveDIBAs(string picname, IntPtr bminfo, IntPtr pixdat) {

        SaveFileDialog sd = new SaveFileDialog();
        sd.FileName = picname;
        sd.Title = "Save bitmap as...";
        sd.Filter = "PDF (*.pdf)|*.pdf";
        sd.Filter = "Bitmap file (*.bmp)|*.bmp|TIFF file (*.tif)|*.tif|JPEG file (*.jpg)|*.jpg|PNG file (*.png)|*.png|PDF file (*.pdf)|*.pdf|All files (*.*)|*.*";

        sd.FilterIndex = 1;
        if (sd.ShowDialog() == DialogResult.OK)

            return false;


        Guid clsid;
        if (!GetCodecClsid(sd.FileName, out clsid))
        {
            //MessageBox.Show("Unknown picture format for extension " + Path.GetExtension(sd.FileName),
                            "Image Codec", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return false;
        }

        IntPtr img = IntPtr.Zero;
        int st = GdipCreateBitmapFromGdiDib( bminfo, pixdat, ref img );
        if( (st != 0) || (img == IntPtr.Zero) )
            return false;

        st = GdipSaveImageToFile(img, sd.FileName, ref clsid, IntPtr.Zero);
        GdipDisposeImage(img);
        return st == 0;
        }
            [DllImport("gdiplus.dll", ExactSpelling=true)]
        internal static extern int GdipCreateBitmapFromGdiDib( IntPtr bminfo, IntPtr pixdat, ref IntPtr image );

            [DllImport("gdiplus.dll", ExactSpelling=true, CharSet=CharSet.Unicode)]
        internal static extern int GdipSaveImageToFile( IntPtr image, string filename, [In] ref Guid clsid, IntPtr encparams );

            [DllImport("gdiplus.dll", ExactSpelling=true)]
        internal static extern int GdipDisposeImage( IntPtr image );
    }


              ****The above code doesnt allow to save as in PDF format.****
+3  A: 

first you'd need to acquire the image using either TWAIN or WIA and then once you've captured that image you need to convert it to PDF using something like abcPDF

lomaxx
+1  A: 

Not entirely sure what you are talking about, but this library: http://sourceforge.net/projects/pdflibrary/ is excellent for saving a PDF.

For scanning (from a TWAIN Scanner?) check out http://www.codeproject.com/KB/dotnet/twaindotnet.aspx Ive done that before, and it seems to work pretty well.

Erich
i couldnt scan the image files as PDF...Plz help me.
nithi
You would have to scan them in via a TWAIN/WIA device first. At this point, most output to an image of some sort, which you could then use pdflibrary to save it. There is no C# library for Scan->PDF directly, you'll have to combine two other things.
Erich
A: 

if you're using GDI. Print directly to a PDF printer (I use bullzip pdf myself because it's free and has a silent print feature)

SnOrfus
+1  A: 

It will not save as PDF at all, because GDI library of Microsoft doesnt have PDF facility, the best way to do is save your file as JPEG first in temporary file. And then use iTextSharp library or PDFSharp library to create PDF out of JPEG, you can embed your JPG/Bitmap any sort of file inside PDF using these two libraries.

Akash Kava