PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jan 04, 2023 4:36 pm 
Offline

Joined: Wed Jan 04, 2023 4:25 pm
Posts: 3
Hello! I'm trying to output text with border using "Draw Glyphs" sample code.

Code:
XGraphicsPath path = new XGraphicsPath();
// Test gfx active
gfx.DrawLine(XPens.Black, 10, 10, 100, 100);
// Output outlined font
path.AddString("Hello!", new XFontFamily("Times New Roman"), XFontStyle.BoldItalic, 100, new XRect(0, 0, 250, 140), XStringFormats.Center);
gfx.DrawPath(new XPen(XColors.Purple, 2.3), XBrushes.DarkOrchid, path);


As the result - I can see black line on my page, but no text (screenshort attached). No any errors or warnings, so I have no idea what goes wrong :(

Attachment:
2023-01-04 19_37_05-2023-01-04 19_31_59-test.pdf - Adobe Acrobat Reader (64-bit).jpg ‎- Фотографии.jpg
2023-01-04 19_37_05-2023-01-04 19_31_59-test.pdf - Adobe Acrobat Reader (64-bit).jpg ‎- Фотографии.jpg [ 22.31 KiB | Viewed 1582 times ]


Last edited by pridachin_nikolai on Thu Jan 05, 2023 5:31 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 05, 2023 10:13 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
pridachin_nikolai wrote:
Hello! I'm trying to output text with border using "Draw Glyphs" sample code.
Thanks for showing the lines from our sample. I can see no error in there.
Thanks for not sharing the rest of your code. The error is probably somewhere in that code.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 05, 2023 4:14 pm 
Offline

Joined: Wed Jan 04, 2023 4:25 pm
Posts: 3
Hello, Thomas. Thank you for answer. Do you have any ideas, how can I debug this to understand the problem?

I created the test project (Clear WPF .NET 4.8 App ), and add PdfSharp via NuGet. I got the same result in this blank project - I can see only line, but no text :(

Here is the full code:

Code:
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PDFSharpTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            PdfDocument document = new PdfDocument();

            PdfPage page = document.AddPage();
            XGraphics gfx = XGraphics.FromPdfPage(page);
            XGraphicsPath path = new XGraphicsPath();

            // Test gfx active
            gfx.DrawLine(XPens.Black, 10, 10, 100, 100);
            // Output outlined font
            path.AddString("Hello!", new XFontFamily("Times New Roman"), XFontStyle.BoldItalic, 100, new XRect(0, 0, 250, 140), XStringFormats.Center);
            gfx.DrawPath(new XPen(XColors.Purple, 2.3), XBrushes.DarkOrchid, path);

            const string filename = "HelloWorld.pdf";
            document.Save(filename);
            Process.Start(filename);
        }
    }
}


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 05, 2023 5:08 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 909
Location: CCAA
One could check the contents of the PDF file to see what gets added.

You can download the sample and run it to see if it still works:
https://github.com/empira/PDFsharp-samples

You can download PDFsharp and step through the code (reference the project files, not the NuGet packages):
https://github.com/empira/PDFsharp

Are you using the WPF build or the GDI build of PDFsharp? AIUI this code will not work with the Core build of PDFsharp.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 05, 2023 5:30 pm 
Offline

Joined: Wed Jan 04, 2023 4:25 pm
Posts: 3
pridachin_nikolai wrote:
Are you using the WPF build or the GDI build of PDFsharp? AIUI this code will not work with the Core build of PDFsharp.

Ah! Yes, this is was my problem. I delete PDFSharp Core iand installed PDFsharp-MigraDoc-wpf and now it works fine! Thank you so much!


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

All times are UTC


Who is online

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