Click or drag to resize
Pdf Library for .NET

Pdf Word Element

PdfWordElement draws a Word document into a region of a pdf page, the way PdfHtmlElement draws html there. The document is given as a file path or a stream, in any format the Word converter reads, and is rendered in-process at render time with every page set to the size of the region - the region is the paper. Its web links and bookmark links stay clickable, and its headings (or its Word bookmarks, per Bookmarks) become entries in the outline of the host document.

Coordinates and sizes are in the page's client-area coordinate system, relative to the top-left corner of the writable area inside the page margins. Width defaults to the client width minus X; Height decides how the content flows:

  • A fixed height that fits its page draws the first rendered page, cut at the box.

  • The default, -1, lets the content flow onto the pages that follow, using the document's next page when there is one and appending one when there is not - so two overflowing regions on one page share the pages after it.

  • A fixed height taller than what is left of the page continues on the pages that follow, the same way, until that much height has been drawn.

The Word engine lays a document out on pages of one height, so a region that starts part-way down a page is laid out on pages of whichever height leaves the least blank space on any one page: the room left when most of a page is left (the pages after the first then all end that much early), otherwise the largest whole fraction of a page that fits the room (the first page ends early and the pages after it are whole). A region that starts at the top of a page fills every page.

Note  Note

PdfWordElement is available only in the full commercial SelectPdf library.

Sample Code

A title drawn from code, then a Word document flowing from below it onto the pages that follow.

PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage();

PdfFont titleFont =
    PdfFont.CreateStandardFont(PdfStandardFont.HelveticaBold, 20);
page.Add(new PdfTextElement(0, 0, "Annex A - the attached report", titleFont,
    new PdfColor(44, 62, 80)));

// from 60pt down the page, continuing on the pages after it
PdfWordElement report = new PdfWordElement(0, 60, "report.docx");
PdfRenderingResult result = page.Add(report);

// where each rendered page landed, and the page the region ended on
SelectPdf.Universal.Drawing.RectangleF[] slices = report.PdfPagesRectangles;
int lastPage = result.PdfPageLastIndex;

doc.Save("annex.pdf");
doc.Close();

A fixed rectangle shows the first rendered page and nothing more:

PdfDocument doc = new PdfDocument();
PdfPage page = doc.AddPage();

PdfWordElement card = new PdfWordElement(50, 100, 300, 200, "summary.docx");
page.Add(card);

doc.Save("card.pdf");
doc.Close();
On a template

Added to a header, footer or stamp template (Templates), the element draws the first rendered page on every page the template applies to and re-creates its web links on each of them; the outline is not carried, since a band has no single place in a reading order.

Tagged documents

On a page of a tagged document the region carries its own structure: the Word document's headings, paragraphs, lists, tables and links join the host document's logical structure, in the reading order, at the place the region was drawn - so a document declaring PDF/UA-1 or PDF/UA-2 stays conformant with a Word region on it. Tagged asks for that structure on a document that is not tagged itself. A single TagType over the whole region is refused, the region being a structure rather than one element; set Artifact to declare the whole region decorative instead.

In a header, footer or stamp the element is still refused on a tagged document unless it is decorative: a band repeats on every page, so its content has no single place in a reading order.

See Also