Samuel Corpuz Ответов: 1

Как конвертировать файл .xdw в файл .jpeg


Добрый день, как конвертировать файл .xdw в файл .jpeg в коде c#.

Что я уже пробовал:

<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>]

1 Ответов

Рейтинг:
0

Dave Kreskowiak

Вам придется обратиться к документации по библиотеке, которую вы используете для загрузки и анализа ваших файлов XDW, чтобы узнать, поддерживается ли она. Имейте в виду, что этого может и не быть.

Одним из альтернативных вариантов было бы, если бы библиотека поддерживала "печать" страниц документа на растровые объекты. Опять же, обратитесь к документации по используемой библиотеке.


Samuel Corpuz

https://drive.google.com/file/d/1nAUTFIF5gfnC5Y0g9y_tnVcq7ohTLvbu/view?usp=sharing