문제

We use Version 8.1 from ABCPDF to generate some nice PDF documents from html.

Now we discovered that printing from within Adobe Reader, will add some thin borders at the top and bottom of the page, that are not visible when the document is displayed. Also when printing to XPS, those lines are not visible.

I guess we must have missed some setting that avoids that?

At the moment we print pages like that:

        using (var doc = new WebSupergoo.ABCpdf8.Doc())
        {
            doc.HtmlOptions.DoMarkup = false;
            doc.HtmlOptions.AddLinks = false;
            doc.HtmlOptions.FontEmbed = true;
            doc.HtmlOptions.Engine = EngineType.Gecko;

            //in case that we need to create more than 1 page, we need go get the PageId and use it
            int pdfPageId = doc.AddImageHtml(html);
            while (true)
            {
                doc.FrameRect();
                if (!doc.Chainable(pdfPageId))
                    break;
                doc.Page = doc.AddPage();
                pdfPageId = doc.AddImageToChain(pdfPageId);
            }

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

            doc.Save(pathToSave);
        }

I know the websupergoo guys are very friendly and reply fast. But I think this could help other people as well, so I write it here instead of sending them an email.

Update:

I tried to get rid of the linex by changing the size of the printed document. I actually try to print for A4 Papersize. I added a line of code to change the setting for the MediaBox (the documentation suggested that this should be possible "doc.MediaBox = "A4"", but it's not directly assignable):

            //set the printed area to A4
            doc.MediaBox.String = "A4";

Result: The lines got thicker and can now even be seen before printing in both AdobeReader and Foxit Reader. this is not yet the solution.

Update2:

I need to set the Rect of the document as well:

            //set the printed area to A4
            doc.Rect.String ="A4";
            doc.MediaBox.String = "A4";

Result: the lines are now drawn on the sides and can only be seen when printing. That's still not the complete solution.

도움이 되었습니까?

해결책

Well well, copy pasting code from the web has it's dangers!

This line adds the Frame around the content:

    doc.FrameRect();

all I had to do was remove it.. and no more lines are displayed.

I completely overlooked that until now.

Before I also tried the following, which didn't work as expected:

    //set the width to 0, so Rectancles have no width
    doc.Width = 0;
    // set the color to white, so borders of Rectangles should not be black
    doc.Color.String = "255 255 255"; //Edited based on the comments.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top