' http://www.vbaexpress.com/forum/showthread.php?t=39616
Sub Test_WatermarkPDF()
Dim base_PDF As String, watermark_PDF As String
Dim cell As Range, i As Integer
base_PDF = ThisWorkbook.Path & "\Base_PDF.pdf"
watermark_PDF = ThisWorkbook.Path & "\Watermark_PDF.pdf"
' Make a basePDF
Sheet1.Cells.Clear
i = 0
For Each cell In Sheet1.Range("A1:F100")
i = i + 1
cell.Value2 = i
Next cell
ActiveSheet.PageSetup.PrintArea = "$A$1:$F$100"
PublishToPDF base_PDF, Sheet1
' Make a watermakePDF
Sheet2.Cells.Clear
Sheet2.Range("A1").Value2 = "DRAFT"
With Sheet2.Range("A1").Font
.Name = "Algerian"
.Size = 72
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16776961
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With Sheet2.Range("A1")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 45
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
PublishToPDF watermark_PDF, Sheet2
watermarkPDF base_PDF, watermark_PDF
End Sub
' Add Tools > References... > Adobe
' JavaScript API: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf
Function watermarkPDF(base_PDF As String, WatermarkPDF_AX As String)
Dim bolResult As Boolean
Dim pdfDoc1 As AcroPDDoc
Dim jsObj As Object
Set pdfDoc1 = CreateObject("AcroExch.PDDoc")
If pdfDoc1.Open(base_PDF) Then
Set jsObj = pdfDoc1.GetJSObject
'jsObj.addWatermarkFromFile WatermarkPDF_AX ', bOnTop:=False
'jsObj.addWatermarkFromFile WatermarkPDF_AX, 0, 0, 0, False, True, True, 0, 0, 0, 0, False, 1, False, 0, 1
' Pg. 272
jsObj.addWatermarkFromFile WatermarkPDF_AX, 0, 0, 100, False, True, True, 0, 0, 0, 0, False, 1, True, 0, 1
End If
pdfDoc1.Save 1, base_PDF
pdfDoc1.Close
Set jsObj = Nothing
Set pdfDoc1 = Nothing
End Function
Sub PublishToPDF(fName As String, ws As Worksheet)
Dim rc As Variant
'ChDrive "c:"
'ChDir GetFolderName(fName)
rc = Application.GetSaveAsFilename(fName, "PDF (*.pdf), *.pdf", 1, "Publish to PDF")
If rc = "" Then Exit Sub
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
End Sub
Bookmarks