PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 2:41 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Apr 09, 2013 7:13 am 
Offline

Joined: Mon Mar 11, 2013 1:06 pm
Posts: 1
Hi

I'm using PDFsharp 1.32 GDI+ version in .NET 2

i have trouble to figure out how to embed entire font to PDF Problem is Font Arial and czech characters. My goal is to no subset, but embed font into PDF in Unicode because I use Czech characters. Example text is "ěščřžýáíéúů".

My Code to insert text into PDF is:
Code:
private void DrawText(JObject obj, XGraphics gfx) {
      
      XUnit padding = new XUnit((double)obj["possiblePadding"],XGraphicsUnit.Point);

      string text = (string)obj["text"];
      //prepare font
      XFontStyle fontStyle = new XFontStyle();
      if ((bool)obj["isBold"]) fontStyle |= XFontStyle.Bold;
      if ((bool)obj["isItalic"]) fontStyle |= XFontStyle.Italic;
      if ((bool)obj["isUnderline"]) fontStyle |= XFontStyle.Underline;
      if (!(bool)obj["isBold"] && !(bool)obj["isItalic"] && !(bool)obj["isUnderline"]) fontStyle |= XFontStyle.Regular;
      

      // set font
      XPdfFontOptions fontOption = new XPdfFontOptions(PdfFontEncoding.Unicode,PdfFontEmbedding.Always);
      XFont font = new XFont("Arial", (double)obj["fontsize"], fontStyle, fontOption);
         
      string longestString = "something long for examlpe";
      
      double left = 0;
      double top = 0;
      // set rectangle
      XRect rect = new XRect(
         left,
         top,
         gfx.MeasureString(longestString, font).ToSizeF().Width,
         gfx.MeasureString(longestString, font).ToSizeF().Height         
      );      
      
      // set align
      XTextFormatter tf = new XTextFormatter(gfx);      
      switch((string)obj["align"]) {
         case "left" : tf.Alignment = XParagraphAlignment.Left; break;
         case "right": tf.Alignment = XParagraphAlignment.Right; break;
         case "center": tf.Alignment = XParagraphAlignment.Center; break;
         default: tf.Alignment = XParagraphAlignment.Left; break;
      }
      
      // color
      XBrush brush = null;      
      if (isStamp) {
         brush = new XSolidBrush(XColor.FromArgb(System.Drawing.ColorTranslator.FromHtml(getColorRGB((string)obj["color"]))));
      }
      else {
         brush = new XSolidBrush(XColor.FromArgb(System.Drawing.ColorTranslator.FromHtml((string)obj["color"])));
      }
      
      // draw text
      tf.DrawString(text.Replace("$", Environment.NewLine), font, brush, rect);
   }


this code generate PDF with fonts shown in attached file (now.jpg) in format Arial,Bold (Embeded Subset) etc.
but I need to insert entire font in format shown in attached file (mustBe.jpg) in format Arial-BoldMT (Embeded)

only distinction beatween these two files is (i thing) embeding or subseting font.

Sorry I can't submit project to forum, but it is complex web site depends on many settings.

Is it any way to truly embed entire font not only subset? If there is no way to do that my only option will be change library and lost lot of work time.

I would appreciate your help
Thank you

Paul


Attachments:
File comment: font must be in this format
mustBe.jpg
mustBe.jpg [ 60.22 KiB | Viewed 3769 times ]
File comment: font subset by pdfsharp
now.jpg
now.jpg [ 50.81 KiB | Viewed 3769 times ]
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 124 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