Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Convert TIFF to PDF in memory
            SautinSoft.PdfVision v = new SautinSoft.PdfVision();

            //v.Serial = "XXXXXXXXXXXXXXX";

            //specify converting options
            v.PageStyle.PageSize.Auto();
            //v.PageStyle.PageMarginLeft.Inch(1);
            //v.ImageStyle.Heightmm(150);
            //v.ImageStyle.WidthInch(10);

            //Specify a path to a TIFF file, e.g. "d:\my Funny Picture.tiff"
            string   inpFile = Path.GetFullPath(@"..\..\image-tiff.tiff");
            FileInfo outFile = new FileInfo(@"Result.pdf");

            //1. Read bytes from TIFF file.
            byte[] imageBytes = File.ReadAllBytes(inpFile);

            //2. Convert TIFF bytes into PDF bytes in memory.
            byte[] pdfBytes = v.ConvertImageStreamToPdfStream(imageBytes);

            //3. Save PDF bytes to file
            if (pdfBytes != null)
            {
                File.WriteAllBytes(outFile.FullName, pdfBytes);
                // Open the resulting PDF document in a default PDF Viewer.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile.FullName)
                {
                    UseShellExecute = true
                });
            }
        }
Exemplo n.º 2
0
        public static byte[] convertirArchivo(string rutaArchivo)
        {
            if (File.Exists(rutaArchivo))
            {
                FileStream fs           = new FileStream(rutaArchivo, FileMode.Open, FileAccess.Read);
                byte[]     arregloBytes = new byte[fs.Length];

                fs.Read(arregloBytes, 0, Convert.ToInt32(fs.Length));
                fs.Close();

                return(arregloBytes);
            }
            else
            {
                try
                {
                    SautinSoft.PdfVision v = new SautinSoft.PdfVision();
                    v.Serial = "10360615139";

                    string rutaTif = rutaArchivo.Replace(".pdf", ".TIF");

                    byte[] bytesTiff = File.ReadAllBytes(rutaTif);
                    byte[] bytesPDF  = v.ConvertImageStreamToPdfStream(bytesTiff);

                    BinaryWriter writer = null;
                    writer = new BinaryWriter(File.OpenWrite(rutaArchivo));

                    writer.Write(bytesPDF);
                    writer.Flush();
                    writer.Close();

                    return(bytesPDF);
                }
                catch (Exception ex)
                {
                    return(null);
                }
            }
        }
Exemplo n.º 3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        SautinSoft.PdfVision v = new SautinSoft.PdfVision();

        byte[] tiffBytes = null;
        byte[] pdfBytes  = null;

        if (FileUpload1.FileBytes.Length > 0)
        {
            // get bytes from image
            tiffBytes = FileUpload1.FileBytes;
        }

        else
        {
            Result.Text = "Please select image file at first!";
        }

        // convert image stream to pdf stream
        pdfBytes = v.ConvertImageStreamToPdfStream(tiffBytes);

        // show PDF
        if (pdfBytes != null)
        {
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "application/PDF";
            // Response.AddHeader("content-disposition", "attachment; filename=Result.pdf");
            Response.AddHeader("content-disposition", "inline; filename=Result.pdf");
            Response.BinaryWrite(pdfBytes);
            Response.Flush();
            Response.End();
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }