In our application we are using the Core API and (among others) the PlaceWatermark call.
We are finding that on large documents ( many pages - several hundred or thousands) something is
causing the call to slow down during processing and eventually stall completely forcing us to use Task Mgr
to kill the process.
Our client requirements force us to watermark each page individually, but even when we stamp all pages the same
we get stalled.
We have a client delivery next week and this is causing tremendous grief for us.
This is the pertinent code we are using as a test that is failing (VB6)
Please note I have omitted the code that we use to license/activate the CoreAPI
Also, I can send only one sample document that does not require NDA with our clients - let me know how to send it to you.
Code: Select all
Private Sub Form_Load()
Set pxcInst = New PXC_Inst
Set pAInt = pxcInst.GetExtension("AUX")
End Sub
Private Sub stampBut_Click()
Dim str_error As String
Dim pageCount As Long
Dim dPageWidthCurrent As Double
Dim dPageHeightCurrent As Double
Dim fileName As String
Dim convertedFileName As String
On Error GoTo nofile:
cdlg.CancelError = True
str_error = "No file chosen"
cdlg.Filter = "PDF Files (*.pdf)|*.pdf"
cdlg.DialogTitle = "Load an existing PDF File"
cdlg.ShowOpen
On Error GoTo 0
fileName = cdlg.fileName
' make a copy of the original file and use that in order to keep the original file unchanged
Dim ipos As Integer
ipos = Len(fileName) - InStrRev(fileName, ".") + 1
convertedFileName = Left(fileName, Len(fileName) - ipos) & "-WEH" & GetTickCount & ".pdf"
FileCopy fileName, convertedFileName
' load the document
If Not api.loadPdfFile(convertedFileName, pDoc, gInst) Then
str_error = "Could not load file: " & ReturnFileName(convertedFileName) & vbNewLine & Err.Description
GoTo nofile
End If
Dim timeThen As Date
statusTxt.Text = statusTxt.Text & "*********** NEW TEST *************" & vbNewLine
statusTxt.Text = statusTxt.Text & ReturnFileName(convertedFileName) & vbNewLine
timeThen = Now
statusTxt.Text = statusTxt.Text & "Start: " & timeThen & vbNewLine
statusTxt.SelStart = Len(statusTxt.Text)
DoEvents
Dim i As Integer
Dim sError As String
Dim pageRectangle As PXC_Rect
Dim currentPage As IPXC_Page
Dim wmark As IPXC_WatermarkParams
Set wmark = pxcInst.CreateWatermarkParams()
For i = 0 To pDoc.Pages.Count - 1
' get the current page
Set currentPage = pDoc.Pages.Item(i)
'These methods are normally used for placement purposes but are commented out here for basic testing
''get the bounding box for the page
' pageRectangle = currentPage.Box(PBox_PrintBox)
'' interchange the height and width of page if needed
'interchangeHeightWidth currentPage.Rotation, pageRectangle
'' calculate the page dimesions and the new page sizes
'calculatePageHeightWidth pageRectangle, dPageWidthCurrent, dPageHeightCurrent
With wmark
.VOffset = 30# 'points
.HOffset = 30# 'points
.WatermarkType = PXC_WatermarkType.Watermark_Text
.RenderMode = PXC_TextRenderingMode.TRM_Fill
.Scale = 100
.FontName = "Arial"
.FillColor.SetRGB 255, 0, 0
.Opacity = 100
.FontSize = 12
.Rotation = 0
.Text = "TopLeft"
End With
' set the page on which watermark should apply
Set pIndex = pAInt.CreateBitSet(pDoc.Pages.Count) 'this MUST be set every page
pIndex.Set i, 1 ' Placing watermark on current page
pDoc.PlaceWatermark pIndex, wmark
Set currentPage = Nothing
Set pIndex = Nothing
pageLabel.Caption = "Page: " & i + 1 & " of " & pDoc.Pages.Count
DoEvents
Next i
' save the file
If Not api.savePdfFile(convertedFileName, pDoc) Then
str_error = "Could not save file."
GoTo nofile
End If
statusTxt.Text = statusTxt.Text & "Finish: " & Now & vbNewLine
statusTxt.Text = statusTxt.Text & "Diff: " & DateDiff("s", timeThen, Now) & " seconds" & vbNewLine
statusTxt.SelStart = Len(statusTxt.Text)
DoEvents
' open the file
ShellExecute 0&, "open", convertedFileName, "", "", vbNormalFocus
Set currentPage = Nothing
Set wmark = Nothing
Exit Sub
nofile:
statusTxt.Text = statusTxt.Text & str_error & vbNewLine
MsgBox str_error
End Sub
Private Sub interchangeHeightWidth(ByVal pageAngle As Long, ByRef pageRectangle As PXC_Rect)
If pageAngle = 90 Or Abs(pageAngle) = 270 Then
Dim xTemp
xTemp = pageRectangle.Top
pageRectangle.Top = pageRectangle.Right
pageRectangle.Right = xTemp
End If
End Sub
Private Sub calculatePageHeightWidth(ByRef pageRectangle As PXC_Rect, ByRef dPageWidthCurrent As Double, ByRef dPageHeightCurrent As Double)
'get the width and height of the image from the page bounding box
dPageWidthCurrent = Abs(pageRectangle.Right - pageRectangle.Left)
dPageHeightCurrent = Abs(pageRectangle.bottom - pageRectangle.Top)
End Sub
Private Function ReturnFileName(ByVal sPath As String) As String
'Returns full file name
Dim i As Long
Dim tmpChr As String
For i = Len(sPath) To 1 Step -1
tmpChr = Mid$(sPath, i, 1)
If tmpChr = "\" Or tmpChr = "/" Then
ReturnFileName = Right$(sPath, Len(sPath) - i)
Exit Function
End If
Next i
ReturnFileName = sPath
End Function