【问题标题】:Create PDF file with images in WinRT在 WinRT 中创建带有图像的 PDF 文件
【发布时间】:2013-03-21 14:42:22
【问题描述】:

如何从 WinRT 中的图像列表创建 PDF 文件。我在这里找到了适用于 windows phone 8 的类似内容("Converting list of images to pdf in windows phone 8") 但我正在寻找适用于 windows 8 的解决方案。如果有人对此有所了解,请与我分享您的想法。

【问题讨论】:

    标签: pdf windows-8 windows-runtime pdf-generation


    【解决方案1】:

    试试http://jspdf.com/

    这应该可以在 WinJS 上运行,但我还没有测试过。在 XAML 应用程序中,您可以尝试使用启用 jsPDF 的页面托管 Web 浏览器控件。

    【讨论】:

      【解决方案2】:

      ComponentOne 现在发布了与 Windows Phone for Windows Runtime 相同的 PDF 库。当然,它不是开源的。

      【讨论】:

        【解决方案3】:

        Amyuni PDF Creator for WinRT(商业图书馆)可用于此任务。您可以通过创建类AmyuniPDFCreator.IacDocument的新实例来创建一个新的PDF文件,然后使用AddPage方法添加新页面,并使用IacPage.CreateObject方法为每个页面添加图片。

        在 C# 中用于向页面添加图片的代码如下所示:

        public IacDocument CreatePDFFromImage()
        {
            IacDocument pdfDoc = new IacDocument();
            // Set the license key
            pdfDoc.SetLicenseKey("Amyuni Tech.", "07EFCD0...C4FB9CFD");
            IacPage targetPage = pdfDoc.GetPage(1); // A new document will always be created with an empty page
        
            // Adding a picture to the current page
            using (Stream imgStrm = await Windows.ApplicationModel.Package.Current.InstalledLocation.OpenStreamForReadAsync("pdfcreatorwinrt.png"))
            {
                IacObject oPic = page.CreateObject(IacObjectType.acObjectTypePicture, "MyPngPicture");
                BinaryReader binReader = new BinaryReader(imgStrm);
                byte[] imgData = binReader.ReadBytes((int)imgStrm.Length);
                // The "ImageFileData" attribute has not been added yet to the online documentation
                oPic.AttributeByName("ImageFileData").Value = imgData;
                oPic.Coordinates = new Rect(100, 2000, 1200, 2000);
            }
            return pdfDoc;
        }
        

        免责声明:我目前是该库的开发人员

        对于“开源”替代方案,您最好使用rely on a web service 使用众多可用的开源库之一创建 PDF 文件。

        【讨论】:

          【解决方案4】:

          如果您想将图像 (.jpg) 文件转换为 PDF 文件,我认为这可能会对您有所帮助。 它在我的实验室工作。

          string source = "image.jpg";
            string destinaton = "image.pdf";
          
            PdfDocument doc = new PdfDocument();
            doc.Pages.Add(new PdfPage());
            XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
            XImage img = XImage.FromFile(source);
            xgr.DrawImage(img, 0, 0);
            doc.Save(destinaton);
            doc.Close();
          

          谢谢。

          【讨论】:

          • 这个答案不正确。虽然没有明确提及,但此答案依赖于与 Windows 应用商店 (WinRT) 应用程序不兼容的外部库 PDFSharp。
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多