Add watermark to existing PDF using adobe acrobat pro from windows batch - adobe

I don't normally script in Adobe and the rabbit hole is very deep after doing some searching, so I was wondering if someone knows how I can add a watermark to an existing PDF by calling Adobe Acrobat Pro from a windows batch file. I already know about 'Actions" in Adobe as well as Javascript, but not sure how I could call one of these from a batch file. I'm open to suggestions/ideas here though if it achieves the same thing and is fairly straight forward -- even if not using Adobe.

I don't know what you exactly want but here a short vbs example, which can easy changed to a windows batch file. Good luck, Reinhard
file = "d:\Test.pdf"
'// open acrobat and set required objects
Set App = CreateObject("Acroexch.app")
app.show
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
'// open the file and add a watermark based on text (using AcroJs)
If AVDoc.Open(file,"") Then
AForm.Fields.ExecuteThisJavaScript "this.addWatermarkFromText(""Confidential"", 0, font.Helv, 24, color.red);"
end if
Set AVDoc = Nothing
Set AForm = Nothing
Set APP = Nothing

Related

Trigger excel solver from vb.net web app

Using vb.net, visual studio 2013 and excel 2010.
I have a web page and when a button is clicked values are passed from the page to excel ( a presaved formatted copy). I then want to run the solver add in (which I have also preconfigured). I have been searching for a while now and cannot find a way of doing this.
The below is the code I use to open the excel application
Dim xlApp As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
xlApp = New Excel.Application
xlApp.Visible = True
xlApp.DisplayAlerts = False
xlWorkbook = xlApp.Workbooks.Open("c:\temp\RTO.xlsx")
xlWorksheet = xlWorkbook.Sheets("Optimiser")
Another curious problem that may be related is when I open excel from the web page the solver addin is enabled in excels options but does not appear in the data ribbon tab. If I disable and enable it in the options it comes back.
UPDATE
I tried the following code
xlApp.Run("C:\Program Files\Microsoft Office\Office15\Library\SOLVER\solver.xlam!Auto_Open")
But it errors with the following
Additional information: Cannot run the macro 'C:\Program
Files\Microsoft Office\Office15\Library\SOLVER\solver.xlam!Auto_Open'.
The macro may not be available in this workbook or all macros may be
disabled.
Ok, so
1) a website that populates excel with data and then streams the excel to the client.
2) the client then fill out or manipulates stuff in the excel.
3) Then clicks a button to solve and perhaps submit the excel...(where you are stuck)
Step 3 could be accomplished with a small 'one click application ' aka 'clickonce', whereas the application is online and served from your site. You could take one cell of your excel and have it open IE and point to the installer, and even pass a parameters (be sure to allow params to pass in the app) as to where the excel was located. Then the app could interop with the excel and do its stuff, perhaps even deliver data back to the server.
After further research and thinking about my problem, I came up with the following.
I cannot find any help about triggering solver from within my vb.net code but you can trigger a macro.
First I added the following code which loaded solver.xlam into excel once it had launched.
xlWorkbook.VBProject.References.AddFromFile("C:\Program Files\Microsoft Office\Office15\Library\SOLVER\solver.xlam")
I then created a macro in excel to launch solver. Once done I added the following line of code into my web page. Runsolver is the name of the macro.
xlApp.Run("RunSolver")
Hope this helps someone else down the line

Silent printing (direct) using KIOSK mode in Google Chrome

I am developing an application which generates pdf using ITextSharp and need to print silently or directly. My work flow is Like this, I have some forms listed in tree structure and on selecting the forms and click on the print button will automatically generate the pdf using Itextsharp and save to a location. this is because for multiple record we download it as zip file . And goes to print without opening any other windows. I am using google chrome as browser and uses the KIOSK mode.
But unfortunately when i execute the code the print preview will open up in my browser and i need to click on the back button to reach my page. I want this to be cleared. Also i need to clear the selection of the tree structure.
Hereby attaching the code while printing.
MemoryStream ms = new MemoryStream();
var urlPdf = Server.MapPath("~/Pdf/pdfMerge/" + id + "Merge_doc.pdf");
PdfReader ps = new PdfReader(urlPdf);//1
PdfStamper pdf = new PdfStamper(ps, ms);//2
pdf.JavaScript = "this.print({bUI: true,bSilent:false,bShrinkToFit: true});" + "\r\n" + "this.closeDoc();";//3
pdf.Close();//4
HttpContext.Current.Response.ClearContent();//5
HttpContext.Current.Response.ClearHeaders();//6
HttpContext.Current.Response.ContentType = "application/pdf";//7
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=quickforms.pdf");//8
HttpContext.Current.Response.BinaryWrite(ms.ToArray());//9
ms.Flush();
Can anybody help me?
Use
--kiosk --kiosk-printing <application_URL>
Create a new chrome.exe shortcut
Add –kiosk –kiosk-printing flags to the chrome.exe target shortcut
Add the url of the kiosk as the starting page in Chrome settings (or replace chrome.exe with “chrome.exe –kiosk http:// [enter URL here]”)
Drag the shortcut into the startup folder so it loads automatically.
That’s it! Then when you open it’s fullscreen and locked down with the kiosk and auto printing functionality all in one! :) To quit the Kiosk, press Alt + F4 on your keyboard.
MUST USE:
PRINT DIRECT: --kiosk-printing
KIOSK MODE: --kiosk [application_url]
KIOSK MODE & PRINT DIRECT: --kiosk-printing --kiosk [application_url]

How to use ReportingCloud in asp.net web site?

Recently I have started to work with SSRS and found ReportingCloud. It says
ReportingCloud provides an open source quality implementation
as an extension of the RDL specification
I haven't found any tutorial/documentation on how to use it in sourceforge or via google search.
Can anyone give an walk-through/example on How to use ReportingCloud?
There is one partial example available at http://sourceforge.net/projects/reportingcloud/forums/forum/1116661/topic/4571059.
The example takes an existing RDL file, parses and executes it and then places the HTML output into an asp.net Literal Control for display in the browser.
That code snippet is repeated here:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("C:\MyFolder\MyReport.rdl");
RDLParser rdlp = new RDLParser(xmlDoc.OuterXml);
rdlp.Parse();
MemoryStreamGen ms = new MemoryStreamGen();
ProcessReport pr = new ProcessReport(rdlp.Report, ms);
pr.Run(null, OutputPresentationType.ASPHTML);
// Dump memory stream (HTML Text) to an out-of-box ASPX Literal control
this.LiteralReportHtml.Text = ms.GetText();
To do this you'll need a reference to ReportingCloud.Engine.
I'm not sure exactly what your bigger goals are but I'd like to draw your attention to another open source project on GitHub called My-FyiReporting https://github.com/majorsilence/My-FyiReporting
Just like ReportingCloud, My-FyiReporting is a fork of FyiReporting (which has gone dormant).
The big difference as far as you are concerned is that My-FyiReporting has ASP.NET samples and an ASP.NET user control link. This might be the fast way to get to what you need.
File ORIGINALPROJECT.TXT from ReportingCloud says:
The ReportingCloud is a fork from the original project fyiReporting
4.1 (http://www.fyireporting.com).
File readme.md from My-FyiReporting says:
My-FyiReporting is a fork of fyiReporting. I cannot stress this
enough. This is a FORK. The main purpose is to make sure that I have a
copy of fyiReporting since that project seems to be dead.

How to Right click of File in Windows Explorer by AutoIt

I wish to simulate a right click on a file. This is done by opening a Windows Explorer window and then right clicking on it.
The main issue is finding the location of the file in Windows Explorer. I am currently using Autoit v3.3.8.1.
My code 's first line:
RunWait (EXPLORER.EXE /n,/e,/select,<filepath>)
The next step is the problem. Finding the coordinates of the file.
After that, right clicking at that coordinates (it seems to me at this time) is not a problem....
Some background:
OS: Windows 7 64-bit
Software Languages: C#, Autoit (for scripting)
The Autoit script is called by a code similar to that below:
Process p = new Process();
p.StartInfo.FileName = "AutoItScript.exe";
p.StartInfo.UseShellExecute = false;
p.Start();
The code is compiled into a console class file which is run at startup. The autoit script runs as the explorer window opens up.
It seems as though you are taking the wrong approach to the problem, so I'll answer what you are asking and what you should be asking.
First up though, that line of code is not valid, and is not what you want either. You want to automate the explorer window, and RunWait waits for the program to finish. Furthermore you want those items to be strings, that code would never work.
Finding the item in explorer
The explorer window is just a listview, and so you can use normal listview messages to find the coordinates of an item. This is done most simply by AutoIt's GUIListView library:
#include<GUIListView.au3>
Local $filepath = "D:\test.txt"
Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)
ProcessWait($iPid)
Sleep(1000)
Local $hList = ControlGetHandle("[CLASS:CabinetWClass]", "", "[CLASS:SysListView32; INSTANCE:1]")
Local $aClient = WinGetPos($hList)
Local $aPos = _GUICtrlListView_GetItemPosition($hList, _GUICtrlListView_GetSelectedIndices($hList))
MouseClick("Right", $aClient[0] + $aPos[0] + 4, $aClient[1] + $aPos[1] + 4)
As has already been mentioned, sending the menu key is definitely a better way than having to move the mouse.
Executing a subitem directly
This is how it should be done. Ideally you should never need an explorer window open at all, and everything can be automated in the background. This should always be what you aim to achieve, as AutoIt is more than capable in most cases. It all depends on what item you want to click. If it is one of the first few items for opening the file in various programs, then it is as simple as either:
Using ShellExecute, setting the verb parameter to whatever it is you want to do.
Checking the registry to find the exact command line used by the program. For this you will need to look under HKCR\.ext where ext is the file extension, the default value will be the name of another key in HKCR which has the actions and icon associated with the filetype. This is pretty well documented online, so google it.
If the action is not one of the program actions (so is built into explorer) then it is a little more complex. Usually the best way will be to look at task manager when you start the program and see what it runs. Other things can be found online, for example (un)zipping. Actions like copy, delete, rename, create shortcut, send to... They can all be done directly from AutoIt with the various File* functions.
With more information, it would be possible to give you more specific help.
First, you might want to look at the Microsoft Active Accessibility SDK. In particular look at this interface...
http://msdn.microsoft.com/en-us/library/accessibility.iaccessible.aspx
You can use this to walk the items in the control and find the one with the file name you are looking for and its screen location.
From there, maybe try something like this for simulating the right click.
How can I use automation to right-click with a mouse in Windows 7?
Once you have done the right click, use accessibility again to find the right option on the context menu.
Maybe there's an easier way, you should be able to cobble something together like this if you don't find one. Good luck!
Suppose I have a file named test.txt on D drive. It needs to right click for opening Context Menu. To do this, the following code should work:
Local $filepath = "D:\test.txt"
Local $iPid = Run("explorer.exe /n,/e,/select," & $filepath)
ProcessWait($iPid)
Sleep(1000)
Send('+{F10}')

Filemaker GetAs...How to display Container Field on webpage?

I have an ASP.Net application that needs to display an image that is stored in a Filemaker Container field. My query statement looks like:
SELECT GetAs(Image, 'JPG') FROM UA_Item_Pictures WHERE "Stock Number" = 33989 AND ImageOrder = 1
According to the documentation:
The possible file types (case sensitive) you can retrieve from a container field in a FileMaker database file are:
'EMBO'
OLE container data
'PDF '
Portable Document Format
'EMF+'
Windows Enhanced Metafile Plus
'PICT'
Mac OS (does not have 512-byte file-based header)
'EPS '
Embedded PostScript
'PNGf'
Bitmap image format
'FILE'
Result of an Insert File command
'PNTG'
MacPaint
'FPix'
Flash (FPX)
'qtif'
QuickTime image file
'FORK'
Resource fork (Mac OS)
'.SGI'
Generic bitmap format
'GIFf'
Graphics Interchange Format
'snd '
Standard sound (Mac OS raw format)
'JPEG'
Photographic images
'TIFF'
Raster file format for digital images
'JP2 '
JPEG 2000
'TPIC'
Targa
'META'
Windows Metafile (enhanced)
'XMLO'
Layout objects
'METO'
Windows Metafile (original)
'8BPS'
PhotoShop (PSD)
'moov'
Old QuickTime format (Mac OS)
So with this information, my questions are:
How do I retrieve contents with multiple formats?
How do I render the BLOG into an image on the page?
Any suggestions would be much appreciated!
Thanks, but I think I found out what was going on. If I did an inner join between an image table and another table, the image wasn't being returned (or being returned properly...not sure which). As soon as I ran a query against the image table directly, images were returned.
So this did not work:
select * from biography_table b inner join image_table i on b.stocknumber = i.stocknumber
where b.stocknumber = 12345
But this does:
select * from image_table where stocknumber = 12345
This means I have to run 2 separate queries, but at least I'm seeing data!!
If you cannot predict what the file type will be, AND/OR you need to use other extensions (such as docx, xlsx, etc), then you can exclusively use 'FILE' for all of your storage and retrieval scripts.
However doing it this way means that FileMaker does not know natively how to handle and open the file. In other words, when using FileMaker you will need to manually export the contents of the field to edit/view it, instead of being able to simply double click the field and it opens the file. So either the setup is advantageous to FileMaker, or advantageous to your external application.
If you do it this way, all files in container fields will be called 'Untitled.dat' and their internal name will be '?', so you will also need to store in another field the actual file name or its extension so you can open it later.
It is because you are using JPG instead of JPEG, in fact, your question answers itself. You can read it this way
SELECT GetAs(Image, 'JPEG') ...
And then, if you are using ado.net read it this way
var bytesLength = reader.GetBytes(0, 0, null, 0, 0);
var buffer = new Byte[bytesLength];
var bytes = reader.GetBytes(0, 0, buffer, 0, (int)bytesLength);
using (var fileStream = new FileStream(String.Format("{0}.jpg", Guid.NewGuid().ToString()), FileMode.Create, FileAccess.Write)) {
fileStream.Write(buffer, 0, buffer.Length);
}
Where 0 at the beggining of the the GetBytes function is the index of the photo field.
Buy a license of SuperContainer (shameless plug alert: I'm one of the authors) and a Mac Mini to host it on. Move the files out of your container fields and into SuperContainer, and let SuperContainer render image versions of your files by tapping into OS X's CoreImage libs.

Resources