private void SaveFile(Save_Type_t type) { if (!m_file_open) return; System.Windows.Forms.SaveFileDialog dlg = new System.Windows.Forms.SaveFileDialog(); dlg.FilterIndex = 1; /* PDF output types */ if (type <= Save_Type_t.PDF) { dlg.Filter = "PDF Files(*.pdf)|*.pdf"; if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { String options = null; bool use_gs = true; String init_file = CreatePDFXA(type); switch (type) { case Save_Type_t.PDF: /* All done. No need to use gs or mupdf */ System.IO.File.Copy(m_currfile, dlg.FileName, true); use_gs = false; break; case Save_Type_t.LINEAR_PDF: mu_doc.PDFExtract(m_currfile, dlg.FileName, m_currpassword, m_currpassword != null, true, -1, null); use_gs = false; break; case Save_Type_t.PDF13: options = "-dCompatibilityLevel=1.3"; break; case Save_Type_t.PDFA1_CMYK: options = "-dPDFA=1 -dNOOUTERSAVE -dPDFACompatibilityPolicy=1 -sProcessColorModel=DeviceCMYK -dColorConversionStrategy=/CMYK -sOutputICCProfile=" + m_outputintents.cmyk_icc; break; case Save_Type_t.PDFA1_RGB: options = "-dPDFA=1 -dNOOUTERSAVE -dPDFACompatibilityPolicy=1 -sProcessColorModel=DeviceRGB -dColorConversionStrategy=/RGB -sOutputICCProfile=" + m_outputintents.rgb_icc; break; case Save_Type_t.PDFA2_CMYK: options = "-dPDFA=2 -dNOOUTERSAVE -dPDFACompatibilityPolicy=1 -sProcessColorModel=DeviceCMYK -dColorConversionStrategy=/CMYK -sOutputICCProfile=" + m_outputintents.cmyk_icc; break; case Save_Type_t.PDFA2_RGB: options = "-dPDFA=2 -dNOOUTERSAVE -dPDFACompatibilityPolicy=1 -sProcessColorModel=DeviceRGB -dColorConversionStrategy=/RGB -sOutputICCProfile=" + m_outputintents.rgb_icc; break; case Save_Type_t.PDFX3_CMYK: options = "-dPDFX -dNOOUTERSAVE -dPDFACompatibilityPolicy=1 -sProcessColorModel=DeviceCMYK -dColorConversionStrategy=/CMYK -sOutputICCProfile=" + m_outputintents.cmyk_icc; break; case Save_Type_t.PDFX3_GRAY: options = "-dPDFX -dNOOUTERSAVE -dPDFACompatibilityPolicy=1 -sProcessColorModel=DeviceGray -dColorConversionStrategy=/Gray -sOutputICCProfile=" + m_outputintents.cmyk_icc; break; } if (use_gs) { xaml_DistillProgress.Value = 0; if (m_ghostscript.Convert(m_currfile, options, Enum.GetName(typeof(gsDevice_t), gsDevice_t.pdfwrite), dlg.FileName, m_num_pages, 300, false, null, -1, -1, init_file, null) == gsStatus.GS_BUSY) { ShowMessage(NotifyType_t.MESS_STATUS, "GS busy"); return; } xaml_DistillName.Text = "Creating PDF"; xaml_CancelDistill.Visibility = System.Windows.Visibility.Collapsed; xaml_DistillName.FontWeight = FontWeights.Bold; xaml_DistillGrid.Visibility = System.Windows.Visibility.Visible; } } } else { /* Non PDF output */ gsDevice_t Device = gsDevice_t.xpswrite; bool use_mupdf = true; String Message = ""; textout_t textout = textout_t.HTML; switch (type) { case Save_Type_t.HTML: dlg.Filter = "HTML (*.html)|*.html"; Message = "HTML content written"; break; case Save_Type_t.XML: dlg.Filter = "XML (*.xml)|*.xml"; Message = "XML content written"; textout = textout_t.XML; break; case Save_Type_t.TEXT: dlg.Filter = "Text (*.txt)|*.txt"; Message = "Text content written"; textout = textout_t.TEXT; break; case Save_Type_t.PCLXL: use_mupdf = false; dlg.Filter = "PCL-XL (*.bin)|*.bin"; Device = gsDevice_t.pxlcolor; break; case Save_Type_t.XPS: use_mupdf = false; dlg.Filter = "XPS Files(*.xps)|*.xps"; break; } if (!use_mupdf) { if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (m_ghostscript.Convert(m_currfile, "", Enum.GetName(typeof(gsDevice_t), Device), dlg.FileName, 1, 300, false, null, -1, -1, null, null) == gsStatus.GS_BUSY) { ShowMessage(NotifyType_t.MESS_STATUS, "GS busy"); return; } } } else { if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { /* Write out first non null page then append the rest */ int curr_page = 0; bool done = false; while (!done) { String output = null; output = mu_doc.GetText(curr_page, textout); if (output == null) { curr_page = curr_page + 1; if (curr_page == m_num_pages) { ShowMessage(NotifyType_t.MESS_STATUS, "No text found in file"); return; } } else { System.IO.File.WriteAllText(dlg.FileName, output); done = true; } } curr_page = curr_page + 1; if (curr_page == m_num_pages) { ShowMessage(NotifyType_t.MESS_STATUS, Message); return; } done = false; while (!done) { String output = null; output = mu_doc.GetText(curr_page, textout); if (output != null) { System.IO.File.AppendAllText(dlg.FileName, output); } curr_page = curr_page + 1; if (curr_page == m_num_pages) { ShowMessage(NotifyType_t.MESS_STATUS, Message); return; } } } } } }
String CreatePDFXA(Save_Type_t type) { Byte[] Resource; String Profile; switch (type) { case Save_Type_t.PDFA1_CMYK: case Save_Type_t.PDFA2_CMYK: Resource = Properties.Resources.PDFA_def; Profile = m_outputintents.cmyk_icc; break; case Save_Type_t.PDFA1_RGB: case Save_Type_t.PDFA2_RGB: Resource = Properties.Resources.PDFA_def; Profile = m_outputintents.rgb_icc; break; case Save_Type_t.PDFX3_CMYK: Resource = Properties.Resources.PDFX_def; Profile = m_outputintents.cmyk_icc; break; case Save_Type_t.PDFX3_GRAY: Resource = Properties.Resources.PDFX_def; Profile = m_outputintents.gray_icc; break; default: return null; } String Profile_new = Profile.Replace("\\", "/"); String result = System.Text.Encoding.UTF8.GetString(Resource); String pdfx_cust = result.Replace("ICCPROFILE", Profile_new); var out_file = System.IO.Path.GetTempFileName(); System.IO.File.WriteAllText(out_file, pdfx_cust); return out_file; }