Giter Site home page Giter Site logo

empira / pdfsharp.samples Goto Github PK

View Code? Open in Web Editor NEW
51.0 51.0 10.0 104 KB

PDFsharp 6.0 and MigraDoc Foundation samples

Home Page: https://docs.pdfsharp.net/PDFsharp/Samples/About.html

License: Other

PowerShell 1.96% C# 97.04% Smalltalk 1.00%

pdfsharp.samples's People

Contributors

pdfsharp-team avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pdfsharp.samples's Issues

Error on Default Page Setup

Hello, I'm trying to update my project to the Net6.0 version. It is going pretty well. I ran into in a couple of spots.

The lines in question:
document.DefaultPageSetup.Orientation = Orientation.Portrait;
document.DefaultPageSetup.BottomMargin = Unit.FromCentimeter(4);

The error:
'DefaultPageSetup must not be changed.'

Should my code be changed? Or is this a bug?

Hello world does not work

Hi,
I copied the code of hello world:

// See https://aka.ms/new-console-template for more information
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using System.Diagnostics;


// Create a new PDF document.
var document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";
document.Info.Subject = "Just a simple Hello-World program.";

// Create an empty page in this document.
var page = document.AddPage();

// Get an XGraphics object for drawing on this page.
var gfx = XGraphics.FromPdfPage(page);

// Draw two lines with a red default pen.
var width = page.Width;
var height = page.Height;
gfx.DrawLine( XPens.Red, 0, 0, width, height );
gfx.DrawLine( XPens.Red, width, 0, 0, height );

// Draw a circle with a red pen which is 1.5 point thick.
var r = width / 5;
gfx.DrawEllipse( new XPen( XColors.Red, 1.5 ), XBrushes.White, new XRect( width / 2 - r, height / 2 - r, 2 * r, 2 * r ) );

// Create a font.
var font = new XFont("Times New Roman", 20, XFontStyleEx.BoldItalic);

// Draw the text.
gfx.DrawString( "Hello, PDFsharp!", font, XBrushes.Black,
    new XRect( 0, 0, page.Width, page.Height ), XStringFormats.Center );

// Save the document...
var filename = "HelloWorld_tempfile.pdf";
document.Save( filename );
// ...and start a viewer.
Process.Start( new ProcessStartInfo( filename ) { UseShellExecute = true } );

and get

Exception thrown: 'System.InvalidOperationException' in PdfSharp.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in PdfSharp.dll
No appropriate font found for family name "Times New Roman". Implement IFontResolver and assign to "GlobalFontSettings.FontResolver" to use fonts.

Is it normal?

"error": "You must not change font resolver after is was once used."

When I try using my endpoint in the swagger, I can generate the PDF, But it's work just once.
If I try again, I get this error: "error": "You must not change font resolver after is was once used."

To get it working again, I need to run the application again in VisualStudio.

What do I need to do to resolve this?

Font Issue

When trying to render the PDF, it's having issues with the founts.

pdfRenderer.RenderDocument();

Error:
'No appropriate font found for family name "Verdana".'

We have a define styles method. So it should be there to use.

private void DefineStyles()
{
// Get the predefined style Normal.
Style style = document.Styles["Normal"];
// Because all styles are derived from Normal, the next line changes the
// font of the whole document. Or, more exactly, it changes the font of
// all styles and paragraphs that do not redefine the font.
style.Font.Name = "Verdana";

 style = document.Styles[StyleNames.Header];
 style.ParagraphFormat.AddTabStop("16cm", TabAlignment.Right);

 style = document.Styles[StyleNames.Footer];
 style.ParagraphFormat.AddTabStop("8cm", TabAlignment.Center);

 // Create a new style called Table based on style Normal
 style = document.Styles.AddStyle("Table", "Normal");
 style.Font.Name = "Verdana";
 //style.Font.Name = "Times New Roman";
 style.Font.Size = 10;
 style.ParagraphFormat.SpaceBefore = "2mm";
 style.ParagraphFormat.SpaceAfter = "2mm";

 // Create a new style called Reference based on style Normal
 style = document.Styles.AddStyle("Reference", "Normal");
 style.ParagraphFormat.SpaceBefore = "5mm";
 style.ParagraphFormat.SpaceAfter = "5mm";
 style.ParagraphFormat.TabStops.AddTabStop("16cm", TabAlignment.Right);

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.