Skip to content

Missing spaces when copying text from PDF created with MigraDoc & PdfSharp #360

@park-jasper

Description

@park-jasper

Reporting an Issue Here

Our users have reported that when they have a PDF open that we create using MigraDoc and PdfSharp in some viewers (namely MS Edge) then upon copying text from the PDF the spaces between the words are missing.

Expected Behavior

When copying text and pasting it then there are spaces between the words.

Actual Behavior

Some spaces are missing from the copied text.

Steps to Reproduce the Behavior

This just needs a simple change to the CreateDocument method in the issue template:

static Document CreateDocument()
{
    // Create a new MigraDoc document.
    var document = new Document
    {
        Info =
        {
            Title = "MigraDoc Issue Template",
            Author = "Your Name",
            Subject = "Demonstrate an issue of MigraDoc"
        }
    };

    // Add a section to the document.
    var section = document.AddSection();

    // Add a paragraph to the section.
    var paragraph = section.AddParagraph();

    // Add some text to the paragraph.
    paragraph.AddFormattedText("Copy me in MS Edge - I am missing some spaces", TextFormat.Bold);

    return document;
}

and also removing this line

pdfRenderer.PdfDocument.Options.Layout = PdfWriterLayout.Verbose;

Then the generated PDF, when opened in MS Edge (without the preview feature of the new pdf viewer) and copying the text, the result is
Copy me in MSEdge- I ammissing some space
instead of the expected
Copy me in MS Edge - I am missing some spaces (for some reason the last character is not selectable, which is a different issue).

When opening the PDF with e.g. PdfPig, then it is apparent that the spaces between the words are not present in the letters on the page, because they are not included in the Tj operations, rather the words are manually spaced with Td operations.

This may get fixed if Ddge handles this differently in the future, other viewers like Firefox do copy the text out correctly. But it might be worth to consider including the spaces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions