如何将.xdw转换为.jpeg [英] How to convert .xdw to .jpeg

查看:229
本文介绍了如何将.xdw转换为.jpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天如何使用c#代码将.xdw转换为.jpeg。



我尝试了什么:



Good Day How do I Convert .xdw to .jpeg in c# code.

What I have tried:

<pre lang="c#"> <pre>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FujiXerox.DocuWorks.Toolkit;
using System.IO;
using System.Xml;
using System.Xml.Linq;
namespace oracledll
{
    public partial class frmtest : Form
    {
        private string pathString = Path.Combine( Directory.GetCurrentDirectory(), "TestFolder");
        string out_path = @"" + Directory.GetCurrentDirectory() + "\\TestFolder";
        public frmtest()
        {
            InitializeComponent();
        }
        public bool Check()
        {
            return true;
        }
        public static void print_error(int code)
        {
            switch (code)
            {
                case Xdwapi.XDW_E_FILE_NOT_FOUND:
                    MessageBox.Show("File not found.");
                    break;
                case Xdwapi.XDW_E_ACCESSDENIED:
                    //  MessageBox.Show("Inaccesable.");
                    //break;
                case Xdwapi.XDW_E_INVALID_NAME:
                    //  MessageBox.Show("Invalid name.");
                    //break;
                case Xdwapi.XDW_E_BAD_NETPATH:
                    MessageBox.Show("File not opened.");
                    break;
                case Xdwapi.XDW_E_BAD_FORMAT:
                    MessageBox.Show("File bad format.");
                    break;
                case Xdwapi.XDW_E_INVALID_ACCESS:
                    MessageBox.Show("Invalid access.");
                    break;
                case Xdwapi.XDW_E_OUTOFMEMORY:
                    MessageBox.Show("Out of memory.");
                    break;
                case Xdwapi.XDW_E_INVALIDARG:
                    //MessageBox.Show("Invalid Argument.");
                    //break;
                default:
                    MessageBox.Show("Error.");
                    break;
            }
        }
        public void test(string[] args)
        { 
            //string in_path = Path.GetFullPath(args[0]);
            string out_path =@""+ Directory.GetCurrentDirectory() + "\\TestFolder";
            //string Complete_Path = Path.GetFileNameWithoutExtension(in_path);
            //Xdwapi.XDW_IMAGE_JPEG
            //Xdwapi.XDW_ConvertPageToImageHandle();
            //Xdwapi.XDW_ConvertPageToImageFile()
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //string[] files =
            //    Directory.GetFiles(txtPath.Text, "*ProfileHandler.cs", SearchOption.AllDirectories);
           //Directory.GetFiles
           // openFileDialog1.InitialDirectory = Path.Combine(Path.GetDirectoryName(Application.StartupPath), "FolderName");
            //openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory();
            //openFileDialog1.RestoreDirectory = true;
            //string test = Path.Combine(Path.GetDirectoryName(Application.StartupPath), "FolderName");
            //if (openFileDialog1.ShowDialog() == DialogResult.OK)
            //{
            //    while (Path.GetDirectoryName(openFileDialog1.FileName) != Path.Combine(Path.GetDirectoryName(Application.StartupPath), "FolderName"))
            //    {

            //        MessageBox.Show("Please select .EXE which is in the default folder", "Wrong folder", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        openFileDialog1.ShowDialog();

            //    }
            //}

        }
        private void button2_Click(object sender, EventArgs e)
        {
            int api_result = 0;
            openFileDialog1.ShowDialog();
            openFileDialog1.DefaultExt = ".xdw";
            string in_path = Path.GetFullPath(@""+openFileDialog1.FileName);
            Xdwapi.XDW_DOCUMENT_HANDLE handle = new Xdwapi.XDW_DOCUMENT_HANDLE();
            Xdwapi.XDW_OPEN_MODE_EX mode = new Xdwapi.XDW_OPEN_MODE_EX();
            mode.Option = Xdwapi.XDW_OPEN_READONLY;
            mode.AuthMode = Xdwapi.XDW_AUTH_NODIALOGUE;
            api_result = Xdwapi.XDW_OpenDocumentHandle(in_path, ref handle, mode);
            if (api_result < 0)
            {
                print_error(api_result);
            }

            if (FolderExist())
            {
                //Clear the folder and put all the images and Details Info
                clearFolder(Directory.GetCurrentDirectory() + "\\TestFolder");


                //api_result = Xdwapi.XDW_OpenDocumentHandle(in_path, ref handle, mode);

                Xdwapi.XDW_DOCUMENT_INFO info = new Xdwapi.XDW_DOCUMENT_INFO();
                Xdwapi.XDW_GetDocumentInformation(handle, ref info);
                int last_page = info.Pages;

                Xdwapi.XDW_IMAGE_OPTION_EX option = new Xdwapi.XDW_IMAGE_OPTION_EX();
                option.Dpi = 200;
                option.Color = Xdwapi.XDW_IMAGE_COLOR;
                option.ImageType = Xdwapi.XDW_IMAGE_JPEG;
                option.DetailOption = Xdwapi.XDW_IMAGE_JPEG;


                Xdwapi.XDW_IMAGE_OPTION option2 = new Xdwapi.XDW_IMAGE_OPTION();
                option2.Color = option.Color;
                option2.Dpi = 200;


              //System.IO.BinaryReader rdr = new System.IO.BinaryReader( stm );

                // int bodyLen = 100;
                byte[] head = new byte[100852];
                int test = 0;
 
                int test3 = 0;
               
                for(int i=1;i<=last_page;i++)
                {
                  int result =  ImageConversion(handle, option,i);
                  if (result < 0)
                      print_error(result);
                   test = Xdwapi.XDW_ConvertPageToImageHandle(handle, i, ref head, option2);
                   test3 = Xdwapi.XDW_GetPageImage(handle, i, out_path);
                }
        
                if (test < 0 )
                {
                    print_error(test);
                }
                //if (test2 < 0)
                //{
                //    print_error(test2);
                //}
                //if (test3 < 0)
                //{
                //    print_error(test3);
                //}
             

                string TEST = "ASF";
               // XmlDocument doc = new XmlDocument();
                XElement xml = new XElement("Details",
                new XElement("OWNERNAME", "Baguio City"),
                new XElement("NEWARP", "123456"),
                new XElement("OLDARP", "1234567"),
                new XElement("PINNO", TEST),
                new XElement("DOCUTYPE", TEST),
                new XElement("LOTAREA", TEST),
                new XElement("ASTYEAR", TEST)
                );
                xml.Save(Directory.GetCurrentDirectory() + "\\TestFolder\\XMLFile.xml");

            }
            else
            {
                FolderExist();
            }
        }
       public int ImageConversion(Xdwapi.XDW_DOCUMENT_HANDLE handle,Xdwapi.XDW_IMAGE_OPTION_EX option, int page)
        {
            Xdwapi.XDW_PAGE_INFO_EX info = new Xdwapi.XDW_PAGE_INFO_EX();
            int result = Xdwapi.XDW_GetPageInformation(handle, page, ref info);
            if (result < 0)
                return result;

            if (info.PageType == Xdwapi.XDW_PGT_FROMAPPL || info.PageType == Xdwapi.XDW_PGT_FROMIMAGE)
            {
                // Use XDW_GetPageText to get text data.
              //result =  Xdwapi.XDW_ConvertPageToImageFile(handle, page, out_path, option);
              //  if (result < 0)
              //      return result;

                string temp_path = Path.GetRandomFileName();
                result = Xdwapi.XDW_GetPageText(handle, page, temp_path);
                if (result < 0)
                    return result;

                Console.WriteLine(File.ReadAllText(temp_path, Encoding.Default));
                File.Delete(temp_path);
            }
            return result;
         
        }
       //string[] filePaths = Directory.GetFiles(@"c:\MyDir\", "*.bmp");
        public void clearFolder(string FolderName)
        {
            DirectoryInfo dir = new DirectoryInfo(FolderName);

            foreach (FileInfo fi in dir.GetFiles())
            {
                fi.Delete();
            }

            foreach (DirectoryInfo di in dir.GetDirectories())
            {
                clearFolder(di.FullName);
                di.Delete();
            }
        }
        public bool FolderExist()
        {
           
            //if (File.Exists(pathString))
            //{
            //    MessageBox.Show("Challenge Accepted");
            //    return true;
            //}
            //else 
            if (Directory.Exists(pathString))
            {
                MessageBox.Show("Challenge Accepted");
                return true;
            }
            else
            {
                MessageBox.Show("NO Existed folder");
                Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\TestFolder");
                return false;
            }
          
        }

        private void button3_Click(object sender, EventArgs e)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Directory.GetCurrentDirectory() + "\\TestFolder\\XMLFile.xml");
            XmlNodeList nodeList = xmlDoc.DocumentElement.SelectNodes("/Details");
            string proID = "", proName = "", price = "";
            foreach (XmlNode node in nodeList)
            {
                proID = node.SelectSingleNode("OWNERNAME").InnerText;
                proName = node.SelectSingleNode("NEWARP").InnerText;
                price = node.SelectSingleNode("OLDARP").InnerText;
               // MessageBox.Show(proID + " " + proName + " " + price);
            }
            textBox1.Text = proID;
            textBox2.Text = proName;
            textBox3.Text = price;
          
        }
    }
}

<a href="https://drive.google.com/file/d/1nAUTFIF5gfnC5Y0g9y_tnVcq7ohTLvbu/view?usp=sharing"></a>[<a href="" target="_blank">^</a>]

推荐答案

您必须查阅用于加载和解析XDW文件的库的文档,以查看它是否受支持。请记住,它可能不是。



一种替代选择是,如果库支持将文档页面打印到Bitmap对象。再次,请参阅您正在使用的库的文档。
You would have to consult the documentation on the library you're using to load and parse your XDW files to see if it's supported. Keep in mind, it may not be.

One alternative option would be if the library supports "printing" the document pages to Bitmap objects. Again, consult the documentation on the library you're using.


这篇关于如何将.xdw转换为.jpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆