2013-03-21 51 views

回答

0

ComponentOne现在已经发布了他们在Windows Phone for Windows Runtime中使用的相同的PDF库。当然,它不是开源的。

1

尝试http://jspdf.com/

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

0

Amyuni PDF Creator for WinRT(商业图书馆)可用于此任务。您可以创建一个新的PDF文件,方法是创建类AmyuniPDFCreator.IacDocument的新实例,然后使用方法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文件。

-2

我想这可能会帮助你,如果你想将图像(.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(); 

谢谢。

+0

这个答案不正确。尽管没有明确提及,但这个答案依赖于外部库PDFSharp,它与Windows Store(WinRT)应用程序不兼容。 – yms 2015-01-21 19:26:00