اخواني الاعزاء هذا كود يتعامل مع Engine كي يحول XSL file الى PDF file ارجوا منكم مساعدتي كيف اضع الامر اي كيف تكون هيكليته
مع العلم ان الامر سيكون موجود في متفير args1 وشكرا لكم .
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Altsoft.Publisher;
using Altsoft.Xml2PDF;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
const string Licence = "";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string s1;
string arg = "C:\\Documents and Settings\\a.aldakheel\\Desktop\\22248891003_113031152.xsl";
char[] myChars = arg.ToCharArray ();
string myString = new string(myChars);
string[] myStrings = new string[]{myString};
// APLog log1 = new APLog();
//log1 = Convert();
s1 = ExecuteSample(myStrings);
}
static APLog Convert(string source, APSourceFormat sourceType, string sourceXsl,
string output, APDestinationFormat outputFormat, APConfig config)
{
APEngine.Init(Licence);
APLog log = new APLog();
using (APDestination dest = APDestination.Create(output, outputFormat, config))
{
using (APSource src = APSource.Create(source, sourceType))
{
if (sourceXsl != null && sourceXsl.Length > 0)
src.ApplyXSLT(APSource.CreateXSLT(sourceXsl));
log.Add(APEngine.Append(src, dest));
}
if (log.Succeed)
log.Add(dest.Save());
}
return log;
}
/// <summary>
/// Checks if given string is one of known options.
/// </summary>
/// <param name="arg">String parameter to check.</param>
/// <returns>True if given string is recognized as known option.</returns>
static bool IsKnownOption(string arg)
{
switch (arg)
{
case "-fo":
case "-svg":
case "-xhtml":
case "-docx":
case "-wordml":
case "-xsl":
case "-output":
case "-format":
case "-conf":
case "-w":
return true;
default:
return false;
}
}
/// <summary>
/// Reads single option from command line parameters list.
/// </summary>
/// <param name="option">Option name or null for unnamed options.</param>
/// <param name="readValue">Indicates when to read parameter next to option name.</param>
/// <param name="value">Reading target.</param>
/// <param name="args">List of parameters.</param>
/// <param name="offset">Current position within <paramref name="args"/>.</param>
/// <returns>True when option succesfully loaded.</returns>
///
//convert
static bool ReadOption(string option, bool readValue, ref string value, string[] args, ref int offset)
{
if (offset >= args.Length)
return false;
if (option == null || option == args[offset])
{
if (option != null)
{
offset++;
if (!readValue)
return true;
else if (offset >= args.Length)
return false;
}
if (IsKnownOption(args[offset]))
return false;
value = args[offset];
offset++;
return true;
}
return false;
}
//convert
static string ExecuteSample(string[] args)
{
#region read command line arguments
string option = null;
int offset = 0;
APSourceFormat sourceType = APSourceFormat.Unknown;
if (ReadOption("-fo", false, ref option, args, ref offset))
sourceType = APSourceFormat.FO;
else if (ReadOption("-svg", false, ref option, args, ref offset))
sourceType = APSourceFormat.SVG;
else if (ReadOption("-docx", false, ref option, args, ref offset))
sourceType = APSourceFormat.Word2007DocX;
else if (ReadOption("-wordml", false, ref option, args, ref offset))
sourceType = APSourceFormat.Word2003Xml;
else if (ReadOption("-xhtml", false, ref option, args, ref offset))
sourceType = APSourceFormat.XHTML;
// else if (ReadOption("-xslt", false, ref option, args, ref offset))
// sourceType = APSourceFormat.XSLT;
string source = null;
if (!ReadOption(null, true, ref source, args, ref offset))
return "<source> parameter is not specified";
string sourceXsl = null;
// read option -xsl if exists
ReadOption("-xsl", true, ref sourceXsl, args, ref offset);
string output = null;
// read option -output if exists
ReadOption("-output", true, ref output, args, ref offset);
APDestinationFormat outputFormat;
if (!ReadOption("-format", true, ref option, args, ref offset))
{
// if output and output formats are not specified - use
// result.pdf as output
if (output == null)
output = "result.asp";
// if output format is not defined - take it from output filename
option = System.IO.Path.GetExtension(output);
if (option.Length == 0)
// we can't determine format of file without extension
return "Can not determine output format";
else
// remove extension separator '.'
option = option.Substring(1);
}
switch (option.ToLower())
{
case "xps":
outputFormat = APDestinationFormat.XPS;
break;
case "tiff":
case "tif":
outputFormat = APDestinationFormat.TIFF;
break;
case "pdf":
outputFormat = APDestinationFormat.PDF;
break;
case "ps":
outputFormat = APDestinationFormat.PS;
break;
default:
return "Unsupported output format";
}
// when output is not specified - it has same filename as source and
// extension corresponding to output format
if (output == null)
output = System.IO.Path.ChangeExtension(source, "." + option.ToLower());
// #endregion
APConfig config = null;
if (ReadOption("-conf", true, ref option, args, ref offset))
config = APConfig.Create(option);
else
config = APConfig.Create();
bool warnings = false;
if (ReadOption("-w", false, ref option, args, ref offset))
warnings = true;
if (offset < args.Length)
return "To much parameters specified";
#endregion
APLog log = Convert(source, sourceType, sourceXsl, output, outputFormat, config);
// Console.WriteLine(log.ToString(string.Format("Converting {0} to {1}", source, output), warnings));
return null;
}
}
}