Hello,
i am searching a simple Example how to print a PDF-Document
from a VB.NET Programm with some options, like Filename, OutputPath and OwnerPassword.
Is somebody in this forum who make this allready and
can give me some CodeSnippets?
Greeting Joachim
;-)
Why don't you look at the com section?
PDFCreator\COM\Samples\Dot Net
Frank
Sorry, but I can't find the com section under pdfcreator. Are u sure that this section is online?
asocos
It comes with the installation! Take a look at the path "PDFCreator\COM\Samples\Dot Net\VS2003\Visual Basic" on your computer.
Frank
Hi,
I'm new to PDFCreator and VB as a whole.
Though I have a load of experience with all from assembler to C and C++ on top of scripting in several ways, I find it impossible to decipher how to use the examples in a way suitable for me.
Please, don't point me to the forms based solutions - I hate to have to push onscreen buttons.
I'm hoping to do automated PDF creation via VB stuff started with "winword.exe /mMyMacro MyTemplate.doc"
I suspect that *ten lines of text* would have me started. But those important lines are missing.
e.g: Add an example of printing ActiveDocument/ActiveSheet from Word or Excel: Write a plain VB Sub that can be run with singlestepping from VBE.
/zz - anonymous
'Create the objects needed:
Private WithEvents pdfMaker As PDFCreator.clsPDFCreator
Dim FileNm() As String
Dim pdfSourceDir, pdfTargetDir, pdfTargetFile As String
'Instantiate and start PDFMaker:
pdfMaker = New PDFCreator.clsPDFCreator
If pdfMaker.cStart(pdfParams) Then
pdfMaker.cClearCache()
pdfMaker.cPrinterStop = True
Else
MessageBox.Show("Blimey, we can't start...")
Me.Close()
End If
'Now, let's print something:
WordPrint("c:\test1.doc")
WordPrint("c:\test2.doc")
System.Threading.Thread.Sleep(1000)
'Combine print jobs into a document:
MakePDF(pdfTargetDir & "flurreblurre.pdf")
'When you're done:
Me.Close()
'Here's the procedure that we called above:
Sub WordPrint(ByVal WordFile)
'will print .DOC en .HTML files
Dim msWord As Word.Application
Me.Cursor = Cursors.WaitCursor
Application.DoEvents()
Try
msWord = New Word.Application
msWord.Visible = False
Catch ex As Exception
Me.Cursor = Cursors.Default
MessageBox.Show("Error opening Word.Basic" & vbCrLf _
& ex.Message, _
"Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Exit Sub
End Try
msWord.Documents.Open(WordFile)
msWord.ActivePrinter = "PDFCreator"
msWord.ActiveDocument.PrintOut(Background:=False)
msWord.ActiveDocument.Close(SaveChanges:=False)
msWord.Quit(False)
msWord = Nothing
GC.Collect()
End Sub
'Combine the print jobs to one document (if you've printed multiple documents)
Sub MakePDF(ByVal TargetFile)
'make sure last app is done printing.
System.Threading.Thread.Sleep(100)
pdfMaker.cCombineAll()
pdfMaker.cPrinterStop = False
'wait until combine is finished and PDF is rendered.
System.Threading.Thread.Sleep(100)
Do
FileNm = Directory.GetFiles(pdfSourceDir)
Loop Until FileNm.Length = 1
'wait until file is written out.
retry:
Try
File.Move(FileNm(0), pdfTargetDir & pdfTargetFile)
Catch ex As System.IO.IOException
GoTo retry
End Try
End Sub
'Clear up before we die gracefully:
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'wait for PDFCreator to sleep.
System.Threading.Thread.Sleep(100)
pdfMaker.cClose()
System.Runtime.InteropServices.Marshal.ReleaseComObject(pdfMaker)
GC.Collect()
End Sub
... does this help?