We currently spin up adobe reader to print out a pdf from our legacy silverlight product which works fine with the following code:
Dim shell = AutomationFactory.CreateObject("Shell.Application")
shell.ShellExecute(path, "", "", "print", 1)
This works great, the problem is that after the printing has been done the Adobe reader application is still left open which is a little annoying to the user base.
My question is how do we close the adobe reader application from code?
Thanks
You cannot.
You call the Adobe Reader and another process, another program is opened. Nothing that you can do anymore but killing the task.
But the problem with killing the task is that you possibly it will close another PDF file opened after your print file be opened in the new instance of Adobe Reader.
I think that's OK in a custom software or in a closed and known environment of users if you choose to kill the Adobe process. But the users should be warned about this behavior. By manual of software or user training.
I used this to send a pdf to the standard printer
Dim pd As New System.Drawing.Printing.PrintDocument
Dim p As New PrintDialog()
p.SelectedPagesEnabled = False
If p.ShowDialog() = True Then
pd.DocumentName = pdfFile
pd.PrinterSettings.PrinterName = p.PrintQueue.Name
pd.PrintController = New System.Drawing.Printing.StandardPrintController()
pd.OriginAtMargins = False
pd.Print()
End If
Maybe works for you you too.
Related
I am trying to use VBA to open a PDF in an existing Adobe Acrobat window.
Currently, however, my code is opening the pdf in a separate Adobe window each time it is run.
End goal: VBA opens a PDF in an existing Adobe acrobat window in the form of a new PDF tab.
Here is my code:
Sub openPDF(sPath As String)
Dim primaryDoc As Object, PrimaryAVDoc As Object, appAdobe As Object ' Open Adobe instance
Dim zPath As String
Dim adobeDoc As Variant, PDFPageView As Variant
Set appAdobe = CreateObject("AcroExch.App")
' Create Adobe PDF object
Set primaryDoc = CreateObject("AcroExch.PDDoc")
Set PrimaryAVDoc = CreateObject("AcroExch.AVDoc")
If PrimaryAVDoc.Open(sPath, "") = True Then
PrimaryAVDoc.BringToFront
Call PrimaryAVDoc.Maximize(True)
Set PDFPageView = PrimaryAVDoc.GetAVPageView()
' Zoom (optional)
' Call PDFPageView.ZoomTo(2, 50)
End If
Set primaryDoc = Nothing
Set PrimaryAVDoc = Nothing
Set appAdobe = Nothing
End Sub
Whilst heavily used by programmable graphics applications, generally:-
This is a user application setting (depending on version user interface) it is unlikely to be externally program related (but see note below). Each user installation, just like in a browser, has user settings/preferences and this is thus a user run time option. I am not going to install every version or yours just to prove your user version does or does not have the required setting.
Many PDF viewers have legacy and Tabbed mode options (often addressable via DDE in Windows or Pipes in other systems) that may or may not be externally addressable for reuse windows. Those that are SyncTeX Aware usually have widest range of settings for external IDE calls. Adobe is SyncTeX Aware but offers fewer choices.
Here the upper quartiles setting is open as separate windows.
Lower view all files are now opened in tabs mode.
I am trying to display a pdf file in an Access form, but my code only works once. When I close the Access application and reopen it Acropdf doesn't display the pdf, it just gets stuck on this screen:
Private Sub Command1_Click()
Dim strPdfDoc As String
'Below is my source
strPdfDoc = "F:\Grifols\files\Unified Region TemplateV1_0_Budget.pdf"
'Here I am loading the pdf file with Acropdf
AcroPDF0.loadFile strPdfDoc
End Sub
I get no errors when debugging the code, but the pdf never shows.
I struggled with this issue for a long time, it was only happening when the EXE was run as Administrator.
My fix was the following:
Set EXE compile to x86 CPU
Change PDF output path to ProgramData: "C:\ProgramData(Client)(Project)"
Update code to first call "AxAcroPDF1.LoadFile(PDFfilepath)" then call "AxAcroPDF1.src = PDFfilepath"
Important: If you need to run the application on Windows Server for some reason, then the 32bit version of Crystal Runtime needs to be installed
Check that your version of Adobe Reader is up to date and replace your code with this. I was able to load the file several times, close and reopen and load again.
Private Sub Command1_Click()
Dim pdf As AcroPDF
Set pdf = Me.AcroPDF0.Object
pdf.LoadFile "F:\Grifols\files\Unified Region TemplateV1_0_Budget.pdf"
End Sub
I had Acrobat Reader DC installed, I Downgraded to 11 from this link
https://helpx.adobe.com/acrobat/kb/install-reader-x-windows.html
And changed the following registry setting to get this to work
To disable the Enable Protected Mode at startup configuration, navigate to the following registry key:
HKEY_CURRENT_USER\Software\Adobe\Acrobat Reader\DC\Privledged
… then modify the bProtectedMode REG_DWORD value to 0 to disable and 1 to enable:
found it at this link
http://terenceluk.blogspot.co.uk/2016/01/disabling-enable-protected-mode-at.html
I found a solution, that work for me, at this link:
To solve initializing screen for Acrobat Reader XI, just disable "Enable Protected Mode At Startup"
I am creating a Windows Phone App using VB.NET and what I want to do is have the user fill out a form within the app, and then when they press a send button I need to app to write these details to a text file, so I can then attach this to an email.
However the problem is I have no idea how to successfully write these details to a text file, I was wondering if anybody had an example of how it is done or just some advice that may help me to find what path I need to take in order to resolve this?
Thank you
The simplest way to send an email on Windows Phone is via the EmailComposeTask API.
Sample VB.NET code from MSDN:
Dim emailComposeTask as EmailComposeTask= new EmailComposeTask()
emailComposeTask.Subject = "message subject"
emailComposeTask.Body = "message body"
emailComposeTask.To = "recipient#example.com"
emailComposeTask.Cc = "cc#example.com"
emailComposeTask.Bcc = "bcc#example.com"
emailComposeTask.Show()
The downside of this API is that it doesn't allow attaching files.
So if you have the requirement to send the email with an attachment, you'll have to rely on an external service.
Here is the code for creating a text file in a MemoryStream:
Dim memoryStrm As New MemoryStream()
Dim writer As New StreamWriter(memoryStrm)
writer.WriteLine("Line 1")
writer.WriteLine("Line 2")
You could send this file to a web service that will in turn send the email.
In my app I want to open *.rtf file, and than wait for it to be closed. Often user has MS Word to open *.rtf files and here is the problem. Code below works, but only when "WINWORD" process has not been started yet. When it is, calling Process.Start() opens only a new window of Word, and most of data from Process object becomes empty. I can't 'wait' for process, cuz it throws an exception. How can I deal with it? Please, help.
Process p = new Process();
p.StartInfo.FileName = #"C:\Users\UserName\Desktop\MyFile.rtf";
p.Start();
string name = p.ProcessName;
p.WaitForExit();
Console.WriteLine(name + " has exited");
Console.ReadKey();
*Edit:
I have analyzed some solutions, and I have noticed, that if application by which user opens the *.rtf file is like Word (may open many files in many windows), I have to wait only for my *.rtf file window, not whole Process. It would be stupid. The problem is more and more complicated. Please Help.
A few more details.
I need to programmatically (Winforms, VB.NET) check if a site is in the Allowed Sites list of the IE Pop-Up Blocker (IE 7 and 8 and Windows XP, Vista and 7) and if not, add it. The application is fully trusted and I don't want to disable the Pop-Up blocker entirely.
To clarify some things, this is for a web-automation application with several users across 3 countries. I want to avoid receiving tons of emails and explaining each time how to add the website to the Allowed Sites manually.
Also, some of the users have Google Toolbar installed, which also has a Popup Blocker creating trouble to my app. Can this also be done programmatically?
Ok, I got the first part. It's just a registry value.
Imports Microsoft.Win32
And the actual code:
Dim siteString As String = "mysite.com"
Dim emptyArray() As Byte = New Byte() {} 'Works as a Zero-Length Binary Value'
Dim subKey As String = "Software\Microsoft\Internet Explorer\New Windows\Allow"
Dim rkKey As RegistryKey = Registry.CurrentUser.OpenSubKey(subKey)
Dim value As Object = rkKey.GetValue(siteString)
If value Is Nothing Then 'Check if the value is already there'
rkKey.SetValue(siteString, emptyArray, RegistryValueKind.Binary)
End If
It also works with multiple versions of IE and Windows.
Does anyone have any idea about the Google toolbar Popup blocker?
ps. Sorry about closing the single quotes, but it simply makes it look nicer.