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 Oct 12, 2020 4:16 pm

We're having trouble getting this text to show up on PDF. When it was generated, we got 2 blank pages w/ the evaluation warning messages at the top. I follow this sample code & it doesn't work. Well, this forum doesn't all me to post the url link.

Our code here is

Code: Select all
            var pdfPage = pdfDocument.Pages.Add(
                new dotnetDrawing::SizeF(_pageWidthBlockSizes, _pageHeightBlockSizes),
                new PdfMargins() { Top = 0f, Right = 0f, Bottom = 0f, Left = 0f, All = 0f },
                PdfPageRotateAngle.RotateAngle0,
                PdfPageOrientation.Portrait
            );
            var pdfGraphicsState = pdfPage.Canvas.Save();
            var pdfSolidBrush = new PdfSolidBrush(dotnetDrawing::Color.Black);
            var pdfPen = new PdfPen(dotnetDrawing::Color.Black);

            foreach (var item in impactFormItems)
            {
                var formattedValue = GetFormattedValue(item.Value, item.Type);
 
                formattedValue = ImpactTruncateText(formattedValue, item);

                var rectangleField = new dotnetDrawing::RectangleF(
                    new dotnetDrawing::PointF(item.CoordinateXPt, item.CoordinateYPt),
                    new dotnetDrawing::SizeF((item.Width * _xPointBlockSize), 10f)
                );

                pdfPage.Canvas.DrawString(
                    formattedValue,
                    new PdfFont(
                        (_pdfFontFamily == PdfDocumentFontFamily.Helvetica ? PdfFontFamily.Helvetica : PdfFontFamily.Courier),  // e-IceBlue Spire PDF.NET doesn't have "Courier New" font family.
                        item.FontSize,
                        PdfFontStyle.Regular
                    ),
                    pdfPen,
                    pdfSolidBrush,
                    rectangleField,
                    PdfTextAlignment.Left,
                    false
                );
            }

            pdfPage.Canvas.Restore(pdfPage.Canvas.Save());

fletchsod
 
Posts: 3
Joined: Mon Oct 12, 2020 3:31 pm

Tue Oct 13, 2020 3:18 am

Hello,

Thanks for your inquiry.
Since your code contains some custom variables that cannot be run directly, I made some changes (as shown below) and then tested it with the latest Spire.PDF Pack(Hot Fix) Version:6.10.0 but found the text appeared on the PDF as expected. Attached is my output file.
To help us reproduce and solve your issue, please provide us with your full test code or a runnable project. You could send it to us ([email protected]) via email. Thanks in advance.
Code: Select all
PdfDocument pdfDocument = new PdfDocument();
            var pdfPage = pdfDocument.Pages.Add(
             PdfPageSize.A4,
             new PdfMargins() { Top = 0f, Right = 0f, Bottom = 0f, Left = 0f, All = 0f },
             PdfPageRotateAngle.RotateAngle0,
             PdfPageOrientation.Portrait
            );
            var pdfGraphicsState = pdfPage.Canvas.Save();
            var formattedValue = "12345";
            PdfPen pdfPen = new PdfPen(Color.Black);
            var pdfSolidBrush = new PdfSolidBrush(Color.Black);
            PdfStringFormat format = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Left;
            //"Courier New" font
            Font font = new Font("Courier New", 15f, FontStyle.Bold);
            PdfTrueTypeFont trueTypeFont = new PdfTrueTypeFont(font);
            var rectangleField = new RectangleF(
                   new PointF(40, 226f),
                   pdfPage.Canvas.ClientSize
               );

            pdfPage.Canvas.DrawString(
                formattedValue,
                trueTypeFont,
                pdfPen,
                pdfSolidBrush,
                rectangleField,
                format,
                false
            );
            pdfPage.Canvas.Restore(pdfPage.Canvas.Save());

            String reuslt = "result.pdf";
            pdfDocument.SaveToFile(reuslt, FileFormat.PDF);


Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Tue Oct 13, 2020 1:10 pm

How come we have to use PdfTrueTypeFont?

Isn't Helevitca font already embedded inside Spire PDF.NET for Windows that we can use from?

Helevitica font isn't supported on Windows due to royality/patent reasons. So Spire PDF.NET included Helevitica assuming the royality/patents been included & paid for.

Thanks

fletchsod
 
Posts: 3
Joined: Mon Oct 12, 2020 3:31 pm

Wed Oct 14, 2020 9:35 am

Hello,

Thanks for providing your file via email.
In fact, the Helevitca font is a standard font defined in the PDF Standard, and our Spire.PDF is based on the PDF Standard. We recommend you to use PdfTrueTypeFont as it supports more fonts, including private fonts.
As for the code you provided via email, unfortunately it also contains some custom classes and I still can’t run it directly. I took some code snippets to test, but still did not reproduce your issue. Could you please provide a runnable project that could reproduce your issue to help us investigate further? Thanks in advance.
Besides, here I uploaded my test project for your reference, you can run it directly on your side.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Return to Spire.PDF