(String
inputUrl, int
htmlWidth,
String pageFormat,
int permissions,
String bookmarks,
String orientation,
String fontsDir,
String outfile) {
PD4ML pd4ml = new
PD4ML();
pd4ml.HtmlWidth = (htmlWidth);
if(orientation ==
null)
orientation =
"portrait";
if ("PORTRAIT".Equals(orientation.ToUpper()))
pd4ml.PageSize = PD4Constants.getSizeByName(pageFormat);
else
pd4ml.PageSize =
pd4ml.changePageOrientation(
PD4Constants.getSizeByName(pageFormat) );
if ( permissions
!= -1 )
pd4ml.setPermissions("empty",
permissions, true);
if ( bookmarks !=
null ) {
if (
"ANCHORS".Equals(bookmarks.ToUpper())
)
pd4ml.generateOutlines(false);
else
if (
"HEADINGS".Equals(bookmarks.ToUpper())
)
pd4ml.generateOutlines(true);
}
if ( fontsDir !=
null &&
fontsDir.Length > 0 )
pd4ml.useTTF( fontsDir,
true );
if (outfile ==
null ||
outfile.Equals("-"))
{
pd4ml.render(new
Uri(inputUrl), Console.Out);
}
else
pd4ml.render( new
Uri(inputUrl),
new System.IO.FileStream(outfile,
System.IO.FileMode.Create));
}
}
[STAThread]
static
void Main(string[]
args) {
String infile =
null;
int
width = -1;
String
format = "A4";
int
permissions = -1;
String
bookmarks = null;
String
orientation = "portrait";
String
ttf = null;
String
outfile = null;
bool
formatSet = false;
FileInfo
ff;
for(
int i = 0; i < args.Length;
i++ ) {
if (
"-permissions".Equals(
args[i] ) ) {
++i;
if ( i ==
args.Length ) {
wrongParam("missing permissions number
" +
"(a
sum of single permission codes)");
return;
}
permissions = Int32.Parse(args[i]);
continue;
}
if (
"-bookmarks".Equals( args[i]
) ) {
++i;
if ( i ==
args.Length ) {
wrongParam("missing
bookmark type (HEADINGS or ANCHORS)");
return;
}
bookmarks = args[i];
continue;
}
if (
"-orientation".Equals(
args[i] ) ) {
++i;
if ( i ==
args.Length ) {
wrongParam("missing
orientation type (PORTRAIT or LANDSCAPE)");
return;
}
orientation = args[i];
continue;
}
if
(
"-ttf".Equals( args[i] ) )
{
++i;
if ( i ==
args.Length ) {
wrongParam("missing
TTF fonts directory");
return;
}
ff = new
FileInfo(args[i]);
ttf = ff.FullName;
continue;
}
if (
"-out".Equals( args[i] ) )
{
++i;
if ( i == args.Length ) {
wrongParam("missing
output file name");
return;
}
outfile = args[i];
continue;
}
if (
args[i].StartsWith("-")
) {
wrongParam("unknown:
" + args[i]);
return;
}
if ( infile ==
null ) {
string ss = args[i];
if(!ss.StartsWith("http://")
&& !ss.StartsWith("file://"))
{
ff = new
FileInfo(ss);
infile =
"file:///" + ff.FullName;
}else
infile = ss;
continue;
}
if ( width ==
-1 ) {
width = Int32.Parse(args[i]);
continue;
}
if ( !formatSet
) {
formatSet =
true;
format = args[i];
continue;
}
wrongParam(args[i]);
return;
}
if ( infile ==
null ) {
Console.Out.WriteLine("source
URL is missing");
Console.Out.WriteLine(
USAGE );
return;
}
if ( width ==
-1 ) {
Console.Out.WriteLine("HTML
width parameter is missing");
Console.Out.WriteLine(
USAGE );
return;
}
PD4Test converter = new
PD4Test();
converter.generatePDF( infile, width, format, permissions,
bookmarks, orientation, ttf, outfile );
}
}