Page 1 of 1

Vertical PdfRubberStampAnnotation

Posted: Tue Sep 15, 2015 5:19 pm
by MiodragM
Hi,
I have a seemingly simple task to write vertical annotation using a true type font from file system but I don't know how to do that.

I realized how to write a vertical annotation using a Font type font with code below, but don't get how to do that with true type font from file.

...

Code: Select all

 PdfRubberStampAnnotation pdfAnnotation = new PdfRubberStampAnnotation(page);
    pdfAnnotation.Rectangle = new RectangleF(0, annotationMargin, lineHeight + annotationMargin, page.MediaBox.Height - annotationMargin * 2);
    ...

    using (PdfGraphics graphics = pdfAnnotation.CreateNormalAppearanceGraphics())
    {
        brush.Color = markColor;
        Font font = new Font(FontFamily.GenericSansSerif, fontSize);
        StringFormat strFormat = new StringFormat();
        strFormat.FormatFlags = StringFormatFlags.DirectionVertical;
        strFormat.Alignment = StringAlignment.Center;
        graphics.DrawString(classificationText, font, brush, pdfAnnotation.Rectangle, strFormat);
    }
    page.Annotations = new PdfAnnotationList(_document);
    page.Annotations.Add(pdfAnnotation);
...

Also, is it possible to rotate vertical annotation by 180 degrees?

Can you please give me a suggestion or example code?

Thanks,
Miki

Re: Vertical PdfRubberStampAnnotation

Posted: Thu Sep 17, 2015 10:05 am
by Alex
Hi Miki,

3 ways are possible for adding rotated rubber stamp annotation to PDF page:
  • The simplest way - use VintaSoft Annotation .NET Plug-in.
  • Use transformation matrix for drawing rotated text on PDF page:

    Code: Select all

    graphics.SaveGraphicsState();
    using(Matrix m = new Matrix())
    {
      m.Rotate(...) or m.RotateAt(...)
      graphics.MultiplyTransform(m);
    }
    graphics.DrawString(...);
    graphics.RestoreGraphicsState();
  • Use properties of PDF annotation: PdfAnnotation.AppearanceMatrix, PdfAnnotation.Rectangle or PdfFormXObjectResource.Matrix. More info please see in PDF Reference 8.4 Annotation, 8.4.4 Appearance Streams.
Best regards, Alexander

Re: Vertical PdfRubberStampAnnotation

Posted: Fri Sep 18, 2015 2:36 pm
by MiodragM
Hi Alexander,

regards your directions I successfully created vertical PdfRubberStampAnnotation Annotation. Thanks.

But... :cry:
I still can't use truetype fonts! Every single try produce an error. (I tried also with font file stream too but without any success)
My problems are:
1. Can not create (embedded) PDFFont object from the file with the font: (Error generatet: Object reference not set to an instance of an object.)

Code: Select all

using (PdfDocument document = new PdfDocument(filename))
            {
                // create font of PDF document based on TrueType font
		PdfFont newFont1 = document.FontManager.CreateSimpleFontFromTrueTypeFont("C:\\Temp\\arial.ttf");
                PdfFont newFont2 = document.FontManager.CreateCIDFontFromTrueTypeFont("C:\\Temp\\arial.ttf");
                
                string myfont = PdfFontManager.GetSystemTrueTypeFontFileName("Times New Roman"); // This line does not geneerate an error and return correct path to the font file!
                
                PdfFont newFont3 = document.FontManager.CreateSimpleFontFromTrueTypeFont(PdfFontManager.GetSystemTrueTypeFontFileName("Times New Roman"));
                PdfFont newFont4 = document.FontManager.CreateCIDFontFromTrueTypeFont(PdfFontManager.GetSystemTrueTypeFontFileName("Times New Roman"));
            }
2. Unable to create a vertical annotation using PDFFont object, because of Drawstring method of the Graphics class (one of the signatures) which contain PDFFont type attribute does not have attribute of type StringFormat (which actually write vertical string)

Maybe I miss something in your posted example codes?


Best regards,
Miki

p.s. Maybe I should send you my example PDF?

Re: Vertical PdfRubberStampAnnotation

Posted: Fri Sep 18, 2015 5:40 pm
by Alex
Hi Miki,
p.s. Maybe I should send you my example PDF?
Yes, please send us (to support@vintasoft.com) a working project which demonstrates your problems and we will try to help you.

Best regards, Alexander