2015-02-10 72 views
0

我需要一個方法或庫將圖像JPG轉換爲文件pdf。我嘗試在網上找到,但我確實只找到了SautinSoft,但這是pdf格式,不是免費的。 有人可以幫我嗎?Jpg到Pdf轉換器在C#3.5

此函數用於C#3.5。

回答

2

你需要的是創建PDF文件,如http://www.pdfsharp.net/

然後您可以創建一個PDF文件,並注入你的形象到它的庫。你不打算將JPG轉換爲PDF,這沒有多大意義,你正在試圖創建一個PDF 內部的它。從另一個答案

示例代碼:Overlay image onto PDF using PDFSharp

private void GeneratePDF(string filename, string imageLoc) 
{ 
    PdfDocument document = new PdfDocument(); 

    // Create an empty page or load existing 
    PdfPage page = document.AddPage(); 

    // Get an XGraphics object for drawing 
    XGraphics gfx = XGraphics.FromPdfPage(page); 
    DrawImage(gfx, imageLoc, 50, 50, 250, 250); 

    // Save and start View 
    document.Save(filename); 
    Process.Start(filename); 
} 

void DrawImage(XGraphics gfx, string jpegSamplePath, int x, int y, int width, int height) 
{ 
    XImage image = XImage.FromFile(jpegSamplePath); 
    gfx.DrawImage(image, x, y, width, height); 
} 
+1

很好的答案先生! – AFract 2015-02-10 17:25:14