Esempio n. 1
0
        void ConvertAsync()
        {
            try
            {
                writeLog("Dosya dönüştürme - yazma işlemi başladı.");
                string saveFilePath = string.Empty;
                string openFilePath = string.Empty;
                bool   result       = false;
                foreach (var item in lstFiles.Items)
                {
                    try
                    {
                        openFilePath = string.Format("{0}", item);
                        saveFilePath = openFilePath.Replace(".docx", ".pdf");

                        Dpn dpn = new Dpn();

                        result = dpn.DpsConvertFile(openFilePath, saveFilePath);

                        if (result)
                        {
                            writeLog(string.Format("{0} File Conversion Successed.", openFilePath));
                        }
                        else
                        {
                            writeLog(string.Format("{0} File Conversion Failed.", openFilePath));
                        }
                    }
                    catch (Exception ex)
                    {
                        writeLog(string.Format("{0} Kaydetme Hata Oluştu.", item));
                        writeException("InsertAsyncForeach", ex);
                    }
                }
                writeLog("Dosya dönüştürme - yazma işlemi bitti.");
            }
            catch (Exception ex)
            {
                writeException("InsertAsync", ex);
            }
            finally
            {
                isNotLocked = true;
            }
        }
Esempio n. 2
0
        private void OK_Click(object sender, System.EventArgs e)
        {
            bool result = false;

            Status.Text = "";

            string InFile  = InputFile.Text;
            string OutFile = OutputFile.Text;

            // check the file names
            if (InFile.Length == 0)
            {
                InputFile.Focus();
                return;
            }
            if (OutFile.Length == 0)
            {
                OutputFile.Focus();
                return;
            }

            Status.Text = "Converting...";
            Status.Refresh();

            // do the conversion
            Dpn dpn = new Dpn();

            //dpn.InWebServer = true;

            //dpn.DpsSetPaperSize(PaperKind.Custom, 12240, 15840);
            //dpn.DpsSetPaperOrient(false);
            //dpn.DpsSetPageMargin(720, 720, 720, 720);
            //dpn.DpsSetPageBorder(Dpn.BRDRTYPE_DBL,30,720,Color.Red);
            //dpn.DpsSetPageRange(0,0);      // example to print just the first page

            //dpn.OwnerPassword = "******";
            //dpn.UserPassword = "******";
            //dpn.PermFlags = 0; // Dpn.PERM_COPY | Dpn.PERM_MOD;
            //dpn.PictQuality = 5; // picture quality, 1=lowest, 5=highest, 3=default
            //dpn.DoCaching=false;  // write directly to disk
            //dpn.ExactTextPlacement=true;
            //dpn.MacCompatible=true;
            //dpn.PdfA=true;               // generate pdfA compliant output

            if (UseBuffer.Checked)
            {  // read the file in the memory buffer and do the conversion
                byte[] InData = null;
                string OutData;

                if ((InData = dpn.DpsFileToBytes(InFile)) != null)
                {
                    if ((OutData = dpn.DpsConvertBuffer(InData)) != null)
                    {
                        result = dpn.DpsWriteToFile(OutFile, OutData); // write the memory to the output file
                    }
                }
            }
            else
            {
                result = dpn.DpsConvertFile(InFile, OutFile); // convert files directly
            }
            InputFile.Focus();                                // ask for the next file
            Status.Text = result ? "Done!" : "Error!";

            if (result)
            {
                try { System.Diagnostics.Process.Start(OutFile); }  // display pdf
                catch { };
            }
        }