Search code examples
abcpdf

Abcpdf copyable/selectable text


i'm using websupergoos abcpdf to convert html pages to pdf via addimageurl.

Works great, but the resulting pdf does not allow the user to select text and copy. All is one 'image'.

Is it possible to do this? Which are the settings to use?

This is my current code. The commented "flatten" does not seem to do anything relevant. The HttpStream simply forewards the pdf to users as a doc.

            var doc = new Doc();
            doc.HtmlOptions.UseScript = true;

            doc.Units = "mm";
            doc.MediaBox.String = "0 0 210 297";
            doc.Rect.String = doc.MediaBox.String;
            doc.Rect.Inset(10.0, 10.0);
            doc.SetInfo(0, "License", abcpdfkey);
            doc.HtmlOptions.UseScript = true;
            doc.HtmlOptions.AddMovies = true;

            doc.HtmlOptions.RetryCount = 0;
            doc.HtmlOptions.ContentCount = 1;


                doc.Page = doc.AddPage();
                for (int i = doc.AddImageUrl(url); doc.Chainable(i); i = doc.AddImageToChain(i))
                {
                    doc.Page = doc.AddPage();
                }

                int pageCount = doc.PageCount;
                for (int j = 1; j <= pageCount; j++)
                {
                    doc.PageNumber = j;
                 //   doc.Flatten();
                }

                this.HttpStream(doc.GetData(), filename);

Solution

  • Before sending the PDF to the HTTP stream, you can set the encryption properties

    The CanCopy Property sets if the user can copy text from the PDF

    To set it add the following code:

    doc.Encryption.CanCopy = true;
    

    You may need to set doc.Encryption.CanExtract as well