Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Sep 14, 2015 6:51 pm

I am using an existing PDF and adding a text string at the bottom of the page and a watermark to the page. If I only add the text string at the bottom and skip the watermark then the new document looks correct. If I add the watermark with or without the text string then the bottom half of my original document disappears.

The relevant code follows:

Code: Select all
        'Set original PDF object
        Dim original As New PdfDocument

        Try
            original.LoadFromFile(FileName)
        Catch ex As Exception
            MsgBox("Failed to open PDF" + vbNewLine + ex.Message)
            Exit Sub
        End Try

        'Create blank PDF for destination file
        Dim doc As New PdfDocument()

        'Create Page Objects for Original and New PDF
        Dim page As PdfPageBase 'New
        Dim originalPage As PdfPageBase 'Original

        For Each originalPage In original.Pages
            page = doc.Pages.Add(PdfPageSize.A4, New PdfMargins(0))
            InsertText(page, BatesNumberStart)
            If Not watermark = "NONE" Then InsertWatermark(page, watermark)
            originalPage.CreateTemplate().Draw(page, 0, 0)
        Next


The Insertwatermark sub works but the pasting of the original document messes up after using it. I am surmising that something related to the size or sizing of the page is being altered in the InsertWatermark sub, but I am not sure how to fix it.

InsertWatermark sub text:

Code: Select all
   Private Sub InsertWatermark(ByVal page As PdfPageBase, ByVal watermark As String)
        Dim brush As New PdfTilingBrush(New SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3))
        brush.Graphics.SetTransparency(0.3F)
        brush.Graphics.Save()
        brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2)
        brush.Graphics.RotateTransform(-45)
        brush.Graphics.DrawString(watermark, New PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Violet, 0, 0, New PdfStringFormat(PdfTextAlignment.Center))
        brush.Graphics.Restore()
        brush.Graphics.SetTransparency(1)
        page.Canvas.DrawRectangle(brush, New RectangleF(New PointF(0, 0), page.Canvas.ClientSize))

    End Sub

scurtiss01
 
Posts: 3
Joined: Tue Sep 08, 2015 9:37 pm

Tue Sep 15, 2015 6:33 am

Hello,

Thanks for your inquiry.
I have tested your code with Spire.PDF Pack(Hot Fix) Version:3.5.34. It worked well in our side.
Please download it and have a try. If the issue still exists, could you please offer us your sample pdf docuemnt?
It would be helpful to replicate the issue and work out the solution for you ASAP
If the information is confidential, you can send it to us ( Support@e-iceblue.com ) via email.

Best Regards,
Sweety
E-iceblue support team
Last edited by sweety1 on Wed Sep 16, 2015 12:17 am, edited 1 time in total.
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Tue Sep 15, 2015 4:16 pm

I emailed some sample pdfs

scurtiss01
 
Posts: 3
Joined: Tue Sep 08, 2015 9:37 pm

Wed Sep 16, 2015 1:48 am

Hello,

Thanks for your information.
I have noticed the issue. And I have posted the issue to our dev team. We will inform you when it is fixed. Sorry for the inconvenience.

Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Wed Sep 16, 2015 3:35 am

Hello,

Thanks for your waiting.
After the investigation, our dev team found a solution for you.
Please try to change this line of your code
Code: Select all
  If Not watermark = "NONE" Then InsertWatermark(page, watermark)

to the below code.
Code: Select all
  If Not watermark = "NONE" Then InsertWatermark(originalPage, watermark)

In addition, our dev team will continue to look into the issue and the reason why your code doesn't work well with document "Sample 1 Original.pdf".

Best Regards,
Sweety
E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.PDF