代码之家  ›  专栏  ›  技术社区  ›  Tobias Hertkorn

将RTF文档转换为图像或在服务器上打印RTF

  •  1
  • Tobias Hertkorn  · 技术社区  · 17 年前

    我有一个我想去的地方 转换RTF 文件 形象化 用于存档和打印。我正在使用.NET。
    有没有图书馆可以帮助我进行这种转换?

    我需要

    • 将RTF转换为服务器上的图像
    • 设置创建图像时需要粘贴的纸张大小

    商业图书馆是一种选择,但我更喜欢操作系统。 如果有一种客户端的方法,这也是一个有效的答案,但是服务器端会非常好。

    编辑:

    谢谢你的回答。因为它们都涉及打印RTF文档,所以我有一个后续问题:

    • 在服务器上打印RTF文档的最佳方法是什么
    4 回复  |  直到 14 年前
        1
  •  2
  •   Robert MacLean    17 年前

    我的建议是有一个可以转储到图像的打印驱动程序-这样,您就可以使用标准打印功能(如纸张大小),然后抓取文件并将其用于实际打印或存档。

    免费开放源代码版本为: Virtual Image Printer driver

        2
  •  0
  •   LegendLength    17 年前

    我最近不得不处理这个问题。我们的应用程序允许用户在标准控件中编辑一些RTF(与Visual Studio一起提供),然后将其转换为图像,以便我们可以将其发送到另一个不理解RTF的应用程序。

    我在网上看起来相当困难,唯一的可能就是截取控件的屏幕截图并将其转换为图像。这意味着在可视区域之外的任何文本(即必须滚动)都不会出现。真让我吃惊,它竟然是那样被砍下来的。

    我知道你问过关于商业图书馆的问题,但我想我会告诉你我在内置控制方面的经验。

        3
  •  0
  •   Brian    17 年前

    扩展罗伯特的答案,如果需要,您可以通过选择操作系统附带的“标准”打印机并打印到文件来避免下载标准打印驱动程序。很多驱动程序使用标准版本的PostScript进行调整。如果需要,可以很容易地将PostScript文件转换为PDF文件进行查看。打印它们通常也很容易。

    这个解决方案比只使用输出图像的专用驱动程序要稍微多一些工作。

        4
  •  0
  •   Alex Essilfie    14 年前

    我可以通过以下代码片段来捕获richtextbox的图片。我想它也可能是你用的。

    private void ShowBitmap_btn_Click(object sender, RoutedEventArgs e)
        {
            if (MyTextBox_txt == null)
                return;
    
            Rect _descendentBounds = VisualTreeHelper.GetDescendantBounds(MyTextBox_txt);
            //RenderTargetBitmap _targetBitmap = new RenderTargetBitmap((Int32)_descendentBounds.Width, 
            //                                                          (Int32)_descendentBounds.Height, 
            //                                                          96, 96, PixelFormats.Pbgra32);
    
            Rect _tempRect = new Rect(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X,
                                        System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y,
                                        System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
                                        System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
            RenderTargetBitmap _targetBitmap = new RenderTargetBitmap((Int32)_tempRect.Width,
                                                                                (Int32)_tempRect.Height,
                                                                                    96, 96, PixelFormats.Pbgra32);
    
            DrawingVisual _drawingVisual = new DrawingVisual();
    
            using (DrawingContext _drwaingContext = _drawingVisual.RenderOpen())
            {
                VisualBrush _visualBrush = new VisualBrush(MyTextBox_txt);
                _drwaingContext.DrawRectangle(_visualBrush, null, new Rect(new Point(), _tempRect.Size));
            }
    
            _targetBitmap.Render(_drawingVisual);
    
            PngBitmapEncoder _png = new PngBitmapEncoder();
    
            _png.Frames.Add(BitmapFrame.Create(_targetBitmap));
            Stream _fileStream;
            _fileStream = File.Create(@"E:\sample1.png");
    
            _png.Save(_fileStream);
    
            System.Drawing.Bitmap _tempBitmap = new System.Drawing.Bitmap(_fileStream);
            _tempBitmap.Save(@"E:\sample1.bmp");
    
            _fileStream.Close();
            _fileStream.Dispose();
    
        }
    
    推荐文章