Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
Word2PDF
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Vernier
Word2PDF
Commits
abcf13ce
Commit
abcf13ce
authored
Feb 26, 2016
by
Michael Vernier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added optional pdf name parameter, fixed working directory issue with new 2015 build
parent
07ccb213
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
11 deletions
+30
-11
Word2PDF/Program.cs
Word2PDF/Program.cs
+30
-11
Word2PDF/bin/Release/Word2PDF.exe
Word2PDF/bin/Release/Word2PDF.exe
+0
-0
No files found.
Word2PDF/Program.cs
View file @
abcf13ce
...
@@ -5,7 +5,7 @@ using System.Text;
...
@@ -5,7 +5,7 @@ using System.Text;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Microsoft.Office.Interop.Word
;
using
Microsoft.Office.Interop.Word
;
using
System.IO
;
using
System.IO
;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
namespace
Word2PDF
namespace
Word2PDF
{
{
...
@@ -14,7 +14,7 @@ namespace Word2PDF
...
@@ -14,7 +14,7 @@ namespace Word2PDF
static
void
Main
(
string
[]
args
)
static
void
Main
(
string
[]
args
)
{
{
object
missing
=
Type
.
Missing
;
object
missing
=
Type
.
Missing
;
object
notTrue
=
false
;
object
notTrue
=
false
;
string
docxname
=
""
;
string
docxname
=
""
;
try
try
{
{
...
@@ -23,20 +23,39 @@ namespace Word2PDF
...
@@ -23,20 +23,39 @@ namespace Word2PDF
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
Console
.
WriteLine
(
"Missing file"
);
Console
.
WriteLine
(
"Missing file"
);
Console
.
WriteLine
(
"Usage: "
+
args
[
0
]
+
"[docx
filename]"
);
Console
.
WriteLine
(
"Usage: "
+
System
.
AppDomain
.
CurrentDomain
.
FriendlyName
+
" <docx filename> [pdf
filename]"
);
Environment
.
Exit
(
-
1
);
Environment
.
Exit
(
-
1
);
}
}
if
(
docxname
==
"--help"
||
docxname
==
"-help"
||
docxname
==
"-h"
)
{
Console
.
WriteLine
(
"Usage: "
+
System
.
AppDomain
.
CurrentDomain
.
FriendlyName
+
" <docx filename> [pdf filename]"
);
Environment
.
Exit
(
0
);
}
FileInfo
file
=
new
FileInfo
(
docxname
);
FileInfo
file
=
new
FileInfo
(
docxname
);
object
docxnameobj
=
(
object
)
file
.
FullName
;
object
docxnameobj
=
(
object
)
file
.
FullName
;
//Console.WriteLine( "File name full: " + file.FullName );
//Console.WriteLine( "File name full: " + file.FullName );
string
pdfname
=
file
.
FullName
.
Substring
(
0
,
file
.
FullName
.
LastIndexOf
(
'.'
)
)
+
".pdf"
;
string
pdfname
=
""
;
try
{
pdfname
=
args
[
1
];
if
(
!
pdfname
.
Contains
(
".pdf"
)
)
{
pdfname
+=
".pdf"
;
}
}
catch
(
Exception
e
)
{
pdfname
=
file
.
FullName
.
Substring
(
0
,
file
.
FullName
.
LastIndexOf
(
'.'
)
)
+
".pdf"
;
}
//Console.WriteLine( "pdf name full: " + pdfname );
//Console.WriteLine( "pdf name full: " + pdfname );
pdfname
=
Environment
.
CurrentDirectory
+
'\\'
+
pdfname
;
object
pdfnameobj
=
(
object
)
pdfname
;
object
pdfnameobj
=
(
object
)
pdfname
;
object
format
=
(
object
)(
WdSaveFormat
.
wdFormatPDF
);
object
format
=
(
object
)(
WdSaveFormat
.
wdFormatPDF
);
Microsoft
.
Office
.
Interop
.
Word
.
Application
word
=
null
;
Microsoft
.
Office
.
Interop
.
Word
.
Application
word
=
null
;
...
@@ -44,15 +63,15 @@ namespace Word2PDF
...
@@ -44,15 +63,15 @@ namespace Word2PDF
try
try
{
{
word
=
new
Application
();
word
=
new
Application
();
doc
=
word
.
Documents
.
Open
(
ref
docxnameobj
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
);
doc
=
word
.
Documents
.
Open
(
ref
docxnameobj
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
);
doc
.
SaveAs2
(
ref
pdfnameobj
,
ref
format
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
);
doc
.
SaveAs2
(
ref
pdfnameobj
,
ref
format
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
,
ref
missing
);
(
(
Microsoft
.
Office
.
Interop
.
Word
.
_Document
)
doc
).
Close
(
ref
missing
,
ref
missing
,
ref
missing
);
(
(
Microsoft
.
Office
.
Interop
.
Word
.
_Document
)
doc
).
Close
(
ref
missing
,
ref
missing
,
ref
missing
);
(
(
Microsoft
.
Office
.
Interop
.
Word
.
_Application
)
word
).
Quit
(
ref
notTrue
,
ref
missing
,
ref
missing
);
(
(
Microsoft
.
Office
.
Interop
.
Word
.
_Application
)
word
).
Quit
(
ref
notTrue
,
ref
missing
,
ref
missing
);
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
...
@@ -70,7 +89,7 @@ namespace Word2PDF
...
@@ -70,7 +89,7 @@ namespace Word2PDF
{
{
Marshal
.
FinalReleaseComObject
(
word
);
Marshal
.
FinalReleaseComObject
(
word
);
word
=
null
;
word
=
null
;
}
}
}
}
}
}
}
}
...
...
Word2PDF/bin/Release/Word2PDF.exe
View file @
abcf13ce
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment