Office 2007 to PDF

L

Lit

Hello,

I am using VS.NET 2005, C# or VB.NET

Does anyone know how to programmatically open a word doc and save it as PDF
in office 12 2007 Beta?

Thanks for any Links, code, etc..

O
 
A

Alvin Bruney

pdf's aren't built in, you'd need a 3rd party app for this. It isn't to late
to have your say either if you want this supported in the release version.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
 
L

Lit

Alvin,

If you can saveAs PDF why can't I programmatically open a document and save
it as pdf??
From what I heard the in office 12 Microsoft opened up the API fro PDF
generation.

Lit


Alvin Bruney said:
pdf's aren't built in, you'd need a 3rd party app for this. It isn't to
late to have your say either if you want this supported in the release
version.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Lit said:
Hello,

I am using VS.NET 2005, C# or VB.NET

Does anyone know how to programmatically open a word doc and save it as
PDF in office 12 2007 Beta?

Thanks for any Links, code, etc..

O
 
A

Alvin Bruney

I've been pouring over the literature for the last hour or so and I can't
find the API. Either I haven't looked well enough on the WordAPI model or it
isn't there. I'll keep it on my list of things to research.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Lit said:
Alvin,

If you can saveAs PDF why can't I programmatically open a document and
save it as pdf??
From what I heard the in office 12 Microsoft opened up the API fro PDF
generation.

Lit


Alvin Bruney said:
pdf's aren't built in, you'd need a 3rd party app for this. It isn't to
late to have your say either if you want this supported in the release
version.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Lit said:
Hello,

I am using VS.NET 2005, C# or VB.NET

Does anyone know how to programmatically open a word doc and save it as
PDF in office 12 2007 Beta?

Thanks for any Links, code, etc..

O
 
J

Josh Sale

Actually PDF support is built-in with Office 2007. I suggest you turn on
the macro recorder and then open your document and then save it as a PDF
file and then see what gets recorded.

josh
 
L

Lit

Josh,

Good Idea.

Does this record in VBA?
So what you are saying then I can do this eventually in C# or VB.NET

Lit
 
L

Lit

Alvin,

Thanks hope to hear from you good news.

Lit

Alvin Bruney said:
I've been pouring over the literature for the last hour or so and I can't
find the API. Either I haven't looked well enough on the WordAPI model or
it isn't there. I'll keep it on my list of things to research.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Lit said:
Alvin,

If you can saveAs PDF why can't I programmatically open a document and
save it as pdf??
From what I heard the in office 12 Microsoft opened up the API fro PDF
generation.

Lit


Alvin Bruney said:
pdf's aren't built in, you'd need a 3rd party app for this. It isn't to
late to have your say either if you want this supported in the release
version.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Hello,

I am using VS.NET 2005, C# or VB.NET

Does anyone know how to programmatically open a word doc and save it as
PDF in office 12 2007 Beta?

Thanks for any Links, code, etc..

O
 
J

Josh Sale

Yes, it will record a VBA macro which you can then inspect to see how it
manipulates the Office object model.

I'm not sure what your development environment is (VSTO?) but the object
model is common across all of the environments (VBA, VSTO, etc) even if the
language details are different.

BTW, I was able to record a the publication of an Excel workbook into PDF
using Excel's macro recorder so I don't see why the same thing wouldn't work
with Word.

josh
 
A

Alvin Bruney

This appears to work. Note, I had several problems with file corruption,
shared files and the like, but this should give you a good starting point

private void button1_Click(object sender, EventArgs e)

{

object Missing = System.Reflection.Missing.Value;

object newDoc = "c:\\mypdf.pdf";

Word.Application app = new Word.ApplicationClass();

Word.Document doc = new Word.Document();

doc = ThisApplication.Documents.Open(ref newDoc,

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.Paragraphs[1].Range.Text = "this is new pdf text";

doc.SaveAs(ref newDoc,

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);

}


--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Lit said:
Alvin,

Thanks hope to hear from you good news.

Lit

Alvin Bruney said:
I've been pouring over the literature for the last hour or so and I can't
find the API. Either I haven't looked well enough on the WordAPI model or
it isn't there. I'll keep it on my list of things to research.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Lit said:
Alvin,

If you can saveAs PDF why can't I programmatically open a document and
save it as pdf??
From what I heard the in office 12 Microsoft opened up the API fro PDF
generation.

Lit


"Alvin Bruney" <www.lulu.com/owc> wrote in message
pdf's aren't built in, you'd need a 3rd party app for this. It isn't to
late to have your say either if you want this supported in the release
version.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Hello,

I am using VS.NET 2005, C# or VB.NET

Does anyone know how to programmatically open a word doc and save it
as PDF in office 12 2007 Beta?

Thanks for any Links, code, etc..

O
 
L

Lit

Alvin,

First Thank you for the code that was a very good start for me. However,

I tested the code you provided but with an existing document and I did not
get the results I wanted.
I have a srcDoc ="myTestDoc.docx"
I asked to save srcDoc as PDF and the result file was corrupt.

The thing is I need to be able to tell Word2007 to Export or To save as PDF
Format.

I don't know what to substitute for "Missing" object you have below.

I recorded a MACRO to save as PDF and it has the following :

Sub Macro1()
'
' Macro1 Macro
'
ActiveDocument.ExportAsFixedFormat _
OutputFileName:= "C:\\dstDoc.pdf" _
, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False,
OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1,
To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True,
_
CreateBookmarks:=wdExportCreateNoBookmarks
ChangeFileOpenDirectory "C:\test\"

End Sub

I don't know how to translate some of the parameters like
ExportFormat:=wdExportFormatPDF etc.. etc... etc...

Thanks Alvin.

Lit



Alvin Bruney said:
This appears to work. Note, I had several problems with file corruption,
shared files and the like, but this should give you a good starting point

private void button1_Click(object sender, EventArgs e)

{

object Missing = System.Reflection.Missing.Value;

object newDoc = "c:\\mypdf.pdf";

Word.Application app = new Word.ApplicationClass();

Word.Document doc = new Word.Document();

doc = ThisApplication.Documents.Open(ref newDoc,

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.Paragraphs[1].Range.Text = "this is new pdf text";

doc.SaveAs(ref newDoc,

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);

}


--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Lit said:
Alvin,

Thanks hope to hear from you good news.

Lit

Alvin Bruney said:
I've been pouring over the literature for the last hour or so and I
can't find the API. Either I haven't looked well enough on the WordAPI
model or it isn't there. I'll keep it on my list of things to research.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Alvin,

If you can saveAs PDF why can't I programmatically open a document and
save it as pdf??
From what I heard the in office 12 Microsoft opened up the API fro PDF
generation.

Lit


"Alvin Bruney" <www.lulu.com/owc> wrote in message
pdf's aren't built in, you'd need a 3rd party app for this. It isn't
to late to have your say either if you want this supported in the
release version.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Hello,

I am using VS.NET 2005, C# or VB.NET

Does anyone know how to programmatically open a word doc and save it
as PDF in office 12 2007 Beta?

Thanks for any Links, code, etc..

O
 
L

Lit

Alvin,

Okay I have to use the Export as the MACRO did and it works
doc.ExportAsFixedFormat("c:\dstDoc.pd", etc.. ) VS.NET 2003 give me all
the Intellisence I needed.

Thank you

Lit


Lit said:
Alvin,

First Thank you for the code that was a very good start for me. However,

I tested the code you provided but with an existing document and I did not
get the results I wanted.
I have a srcDoc ="myTestDoc.docx"
I asked to save srcDoc as PDF and the result file was corrupt.

The thing is I need to be able to tell Word2007 to Export or To save as
PDF Format.

I don't know what to substitute for "Missing" object you have below.

I recorded a MACRO to save as PDF and it has the following :

Sub Macro1()
'
' Macro1 Macro
'
ActiveDocument.ExportAsFixedFormat _
OutputFileName:= "C:\\dstDoc.pdf" _
, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False,
OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1,
To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True,
KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks
ChangeFileOpenDirectory "C:\test\"

End Sub

I don't know how to translate some of the parameters like
ExportFormat:=wdExportFormatPDF etc.. etc... etc...

Thanks Alvin.

Lit



Alvin Bruney said:
This appears to work. Note, I had several problems with file corruption,
shared files and the like, but this should give you a good starting point

private void button1_Click(object sender, EventArgs e)

{

object Missing = System.Reflection.Missing.Value;

object newDoc = "c:\\mypdf.pdf";

Word.Application app = new Word.ApplicationClass();

Word.Document doc = new Word.Document();

doc = ThisApplication.Documents.Open(ref newDoc,

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.Paragraphs[1].Range.Text = "this is new pdf text";

doc.SaveAs(ref newDoc,

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);

}


--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Lit said:
Alvin,

Thanks hope to hear from you good news.

Lit

"Alvin Bruney" <www.lulu.com/owc> wrote in message
I've been pouring over the literature for the last hour or so and I
can't find the API. Either I haven't looked well enough on the WordAPI
model or it isn't there. I'll keep it on my list of things to research.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Alvin,

If you can saveAs PDF why can't I programmatically open a document and
save it as pdf??
From what I heard the in office 12 Microsoft opened up the API fro PDF
generation.

Lit


"Alvin Bruney" <www.lulu.com/owc> wrote in message
pdf's aren't built in, you'd need a 3rd party app for this. It isn't
to late to have your say either if you want this supported in the
release version.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

Hello,

I am using VS.NET 2005, C# or VB.NET

Does anyone know how to programmatically open a word doc and save it
as PDF in office 12 2007 Beta?

Thanks for any Links, code, etc..

O
 
L

Lit

Josh,

Recording a MACRO was a very good Idea so Office 2007 tells me what to do.

I can not find out what to put for Parameters at times because VS.NET 2003
does not give me the Intellisence I need.
Can not find a doc to tell me what the Enums are...

Thank you again,

Lit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top