These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Convert and write to pdf, Urgent

karan1981
Registered: Aug 5 2010
Posts: 6

Everyone,

I want to convert one html file to pdf and then attach that pdf to outlook email.
Here is the code:

//So the below code will create a html file to my file sytem.
var sbody = "mytext";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var tf = fso.CreateTextFile(htmlFile, true);
tf.Write (sbody);
tf.Close();

//Now I want to create a pdf of that html and save it , I am stuck as how to proceed further.

var AcroApp = new ActiveXObject("AcroExch.App");
var AVDoc = new ActiveXObject("AcroExch.AVDoc");
var PDDoc = new ActiveXObject("AcroExch.PDDoc");
var IsSuccess = false;
IsSuccess = AVDoc.Open(htmlFile , "");
AVDoc = AcroApp.GetActiveDoc();

if(IsSuccess)
{
AVDoc = AcroApp.GetActiveDoc(); //AVDoc always return null
}

Any Help is appreciated

My Product Information:
Acrobat Standard 8.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
This should really be done from the Acrobat side. There is a function in Acrobat JavaScript for opening a web page and converting it into a PDF, "doc.getURL()".

Your VBA script would open a known PDF that opens the selected web site. The URL can be passed from your VBA scirpt into the PDF script through the JS object on the "PDDoc" object. Look up the getJSObject function.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

karan1981
Registered: Aug 5 2010
Posts: 6
I already have my function to create html file which lies in my file system, Now what I want is to convert that file to pdf and save in my file system. So I was using this code.

Function HTML2PDF(sourcefile , desfile )

dim flag
Set AcroApp = CreateObject("AcroExch.App")
Set AVDoc = CreateObject("AcroExch.AVDoc")

Call AVDoc.Open(sourcefile , "")
Set AVDoc = AcroApp.GetActiveDoc
Do While Not AVDoc.IsValid

Set AVDoc = AcroApp.GetActiveDoc
If AVDoc.IsValid Then
Set PDDoc = AVDoc.GetPDDoc

End If

End Function


But it keeps on saying Object Required "Avdoc: error.

Please let me know how can I make this to work
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I do not think that the AVDoc.Open() is opening anything. In fact I'm not sure that this function will perform a conversion to PDF. I'd suggest testing to make sure the code is working by passing in a path to a PDF file. If it opens the PDF file then you'll know that it does not work for a converting HTML to PDF.

I'm also pretty sure that it's a blocking function, i.e., it doesn't return until the file is open in Acrobat. So you don't need t the loop.


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script