We have a WPF application that has a print preview dialog. When we create the PDF to match this print preview dialog, we want the PDF to show a 100% match. For instance, we have a WPF Text开发者_开发知识库Block with a set height and width and some content that wraps in the text block. We then want to recreate this text exactly in the PDF. So far we have tried a PDF component and we have found that for the most part this looks correct, but wrapping will not always match 100%. For example, where the print preview WPF TextBlock shows 7 words on a line, the PDF created with the PDF component may only show 6 (with the seventh on the next line).
Is it possible to get a 100% match between our WPF TextBlocks and the PDF textblock? Or is this a limitation in going from the WPF textblock to the PDF textblock which any component will never be able to overcome? We really want the print preview to show a perfect match to what will be delivered to our customers in the PDF.
You might want to try WPF's RichTextBox as readonly instead of TextBlock.
We used Tall Components TallPdf to create the PDF and have found that it matches extremely well. To get a close match using the TallPDF component we had to:
- Play with the MultilineTextShape.LineSpacing to get a match between the WPF textblock and the PDF
- Use the specific system font files for bold, italics, etc. (such as timesbd.ttf) instead of the Fragment.Bold (or Italics, etc.) properties of the Fragments.
- Make sure the font size are in points (the WPF Textblock had font sizes in pixels, the same goes for the width or the textblock too).
After accounting for these items, the PDF textblock matched the WPF Textblock exactly.
精彩评论