PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 26, 2024 6:40 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Oct 24, 2014 10:31 pm 
Offline

Joined: Fri Oct 24, 2014 9:10 pm
Posts: 3
Using the sample to place rubber stamps on PDF's
the sample code in VB.Net is below and makes a black rectangle crossed out. the rubber stamp will display in PDFArchitect. Can point PDFSharp at the Reader XI (11)'s directory for Annotations?
( C:\Program Files (x86)\Adobe\Reader 11.0\Reader\plug_ins\Annotations\Stamps\ENU)?

'------------------
Dim document As PdfDocument = New PdfDocument
document.Info.Title = "Created with PDFsharp"
document.Version = 16
' Create an empty page
Dim page As PdfPage = document.AddPage

' Get an XGraphics object for drawing
Dim gfx As XGraphics = XGraphics.FromPdfPage(page)

' Draw crossing lines
Dim pen As XPen = New XPen(XColor.FromArgb(255, 0, 0))
gfx.DrawLine(pen, New XPoint(0, 0), New XPoint(page.Width.Point, page.Height.Point))
gfx.DrawLine(pen, New XPoint(page.Width.Point, 0), New XPoint(0, page.Height.Point))

' Draw an ellipse
gfx.DrawEllipse(pen, 3 * page.Width.Point / 10, 3 * page.Height.Point / 10, 2 * page.Width.Point / 5, 2 * page.Height.Point / 5)

' Create a font
Dim font As XFont = New XFont("Verdana", 20, XFontStyle.Bold)

' Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black, _
New XRect(0, 0, page.Width.Point, page.Height.Point), XStringFormats.Center)

' Create a PDF text annotation
Dim textAnnot As New PdfTextAnnotation()
textAnnot.Title = "This is the title"
textAnnot.Subject = "This is the subject"
textAnnot.Contents = "This is the contents of the annotation." & vbCr & "This is the 2nd line."
textAnnot.Icon = PdfTextAnnotationIcon.Note

gfx.DrawString("The first text annotation", font, XBrushes.Black, 30, 50, XStringFormats.[Default])

' Convert rectangle from world space to page space. This is necessary because the annotation is
' placed relative to the bottom left corner of the page with units measured in point.
Dim rect As XRect = gfx.Transformer.WorldToDefaultPage(New XRect(New XPoint(30, 60), New XSize(30, 30)))
textAnnot.Rectangle = New PdfRectangle(rect)

' Add the annotation to the page
page.Annotations.Add(textAnnot)


' Create another PDF text annotation which is open and transparent
textAnnot = New PdfTextAnnotation()
textAnnot.Title = "Annotation 2 (title)"
textAnnot.Subject = "Annotation 2 (subject)"
textAnnot.Contents = "This is the contents of the 2nd annotation."
textAnnot.Icon = PdfTextAnnotationIcon.Help
textAnnot.Color = XColors.LimeGreen
textAnnot.Opacity = 0.5
textAnnot.Open = True

gfx.DrawString("The second text annotation (opened)", font, XBrushes.Black, 30, 140, XStringFormats.[Default])

rect = gfx.Transformer.WorldToDefaultPage(New XRect(New XPoint(30, 150), New XSize(30, 30)))
textAnnot.Rectangle = New PdfRectangle(rect)

' Add the 2nd annotation to the page
page.Annotations.Add(textAnnot)
'============================================================FAIL=======================
' Create a so called rubber stamp annotation. I'm not sure if it is useful, but at least
' it looks impressive...
Dim rsAnnot As New PdfRubberStampAnnotation()
rsAnnot.Icon = PdfRubberStampAnnotationIcon.Approved
'============================================================FAIL=======================

rect = gfx.Transformer.WorldToDefaultPage(New XRect(New XPoint(100, 400), New XSize(350, 150)))
rsAnnot.Rectangle = New PdfRectangle(rect)

' Add the rubber stamp annotation to the page
page.Annotations.Add(rsAnnot)
rect = gfx.Transformer.WorldToDefaultPage(New XRect(New XPoint(100, 400), New XSize(350, 150)))
rsAnnot.Rectangle = New PdfRectangle(rect)

' Save the document...
Dim filename As String = "HelloWorld.pdf"
document.Save("C:\" & filename)

' ...and start a viewer.
Process.Start(filename)
'---------------------------------------


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 27, 2014 3:07 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

Can you explain
Code:
============================================================FAIL=======================
a little bit?

Compile-time error? Run-time exception?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 27, 2014 5:35 pm 
Offline

Joined: Fri Oct 24, 2014 9:10 pm
Posts: 3
Sorry, about the comment. I should have removed that. The code did not have issues but Acrobat 11 is displaying a Black Box with an X and not the stamp.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 337 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group