2013-10-29 5 views
1

WinJS를 사용하여 Windows 8 Store App을 작성하고 있습니다. 내 응용 프로그램은 텍스트와 그래프로 PDF를 생성해야합니다. 필자는 PDFtron이 HTML을 PDF로 변환 할 수 있다는 인상하에 있었지만 App Store 응용 프로그램의 경우는 그렇지 않습니다. 사실입니까?PDFTron WinRT에서 HTML에서 PDF로 변환

프런트 엔드는 WinJS/HTML 및 Telerik Radchart를 사용하여 SVG에서 그래프를 렌더링합니다. 그런 다음 DOM을 HTML 파일로 디스크에 파이프합니다. 그래프와 숫자를 멋지게 보여줍니다. 스타일뿐만 아니라 내용을 보존하기 위해 HTML을 PDF로 변환하려고합니다.

WinRT 버전은 HTML2PDF 어셈블리 또는 .Convert() 메서드와 함께 제공되지 않습니다. 다른 곳인가요? 필자는 문서, 샘플 및 웹을 검색했습니다.

답변

0

WinRT의 PDFTron의 PDFNet SDK는 HTML에서 PDF 로의 변환을 지원하지 않습니다 (버전 6.2 에서처럼).

WinRT에 PDFNet의 SDK 자체가 HTML 에서 PDF로 변환 할 수는 없지만, Windows 바탕 화면에서 PDFNet SDK는 그렇게 할 수 있습니다 : 여기

내가이 질문에 PDFTron 지원에서받은 응답이다. http://www.pdftron.com/pdfnet/samplecode.html#HTML2PDF에서 HTML에서 PDF 로의 변환을위한 샘플 코드를 찾을 수 있습니다.

우리 고객 중 일부는 HTML을 자신의 서버로 보냅니다. 여기에서 PDFNet은 HTML을 PDF로 변환 할 수 있습니다. Windows 데스크탑에는 Office 을 PDF로 변환하고 인쇄 가능한 문서 형식을 PDF로 변환하는 것을 포함하여 많은 변환 옵션이 있습니다.

0

EVO는 다음을 구현했습니다. solution to convert HTML to PDF in WinRT and Windows Store Applications. 이 페이지에서 compelte 코드 샘플을 찾을 수 있습니다.

코드 샘플의 복사본은 다음과 같습니다

private async void buttonConvertUrlToPdf_Click(object sender, RoutedEventArgs e) 
{ 
    // If another conversion is in progress then ignore current request 
    bool ignoreRequest = false; 
    lock(pendingConversionSync) 
    { 
     if (pendingConversion) 
      ignoreRequest = true; 
     else 
     { 
      msgUrlToPdfInProgress.Visibility = Windows.UI.Xaml.Visibility.Visible; 
      pendingConversion = true; 
     } 
    } 

    if (ignoreRequest) 
     return; 

    try 
    { 
     String serverIP = textBoxServerIP.Text; 
     uint port = uint.Parse(textBoxServerPort.Text); 

     HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter(serverIP, port); 

     // set service password if necessary 
     if (textBoxServicePassword.Text.Length > 0) 
      htmlToPdfConverter.ServicePassword = textBoxServicePassword.Text; 

     // set HTML viewer width 
     htmlToPdfConverter.HtmlViewerWidth = int.Parse(textBoxHtmlViewerWidth.Text); 

     // set HTML viewer height if necessary 
     if (textBoxHtmlViewerHeight.Text.Length > 0) 
      htmlToPdfConverter.HtmlViewerHeight = int.Parse(textBoxHtmlViewerHeight.Text); 

     // set navigation timeout 
     htmlToPdfConverter.NavigationTimeout = int.Parse(textBoxHtmlViewerWidth.Text); 

     // set conversion delay if necessary 
     if (textBoxConversionDelay.Text.Length > 0) 
      htmlToPdfConverter.ConversionDelay = int.Parse(textBoxConversionDelay.Text); 

     // set PDF page size 
     htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = SelectedPdfPageSize(); 

     // set PDF page orientation 
     htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = SelectedPdfPageOrientation(); 

     // set margins 
     htmlToPdfConverter.PdfDocumentOptions.LeftMargin = int.Parse(textBoxLeftMargin.Text); 
     htmlToPdfConverter.PdfDocumentOptions.RightMargin = int.Parse(textBoxRightMargin.Text); 
     htmlToPdfConverter.PdfDocumentOptions.TopMargin = int.Parse(textBoxTopMargin.Text); 
     htmlToPdfConverter.PdfDocumentOptions.BottomMargin = int.Parse(textBoxBottomMargin.Text); 

     // add header 
     if (checkBoxAddHeader.IsChecked != null && (bool)checkBoxAddHeader.IsChecked) 
     { 
      htmlToPdfConverter.PdfDocumentOptions.ShowHeader = true; 
      DrawHeader(htmlToPdfConverter, true); 
     } 

     // add footer 
     if (checkBoxAddFooter.IsChecked != null && (bool)checkBoxAddFooter.IsChecked) 
     { 
      htmlToPdfConverter.PdfDocumentOptions.ShowFooter = true; 
      DrawFooter(htmlToPdfConverter, true, true); 
     } 

     string urlToConvert = textBoxUrl.Text; 
     string errorMessage = null; 

     // Convert the HTML page from give URL to PDF in a buffer 
     byte[] pdfBytes = await Task.Run<byte[]>(() => 
     { 
      byte[] resultBytes = null; 
      try 
      { 
       resultBytes = htmlToPdfConverter.ConvertUrl(urlToConvert); 
      } 
      catch (Exception ex) 
      { 
       errorMessage = String.Format("Conversion failed. {0}", ex.Message); 
       return null; 
      } 

      return resultBytes; 
     }); 

     if (pdfBytes == null) 
     { 
      MessageDialog errorMessageDialog = new MessageDialog(errorMessage, "Conversion failed"); 
      await errorMessageDialog.ShowAsync(); 
      return; 
     } 

     // Save the PDF in a file 
     Windows.Storage.StorageFolder installedLocation = Windows.Storage.ApplicationData.Current.LocalFolder; 
     StorageFile outStorageFile = installedLocation.CreateFileAsync("EvoHtmlToPdf.pdf", CreationCollisionOption.ReplaceExisting).AsTask().Result; 
     FileIO.WriteBytesAsync(outStorageFile, pdfBytes).AsTask().Wait(); 

     // Open the file in a PDF viewer 
     await Windows.System.Launcher.LaunchFileAsync(outStorageFile); 
    } 
    finally 
    { 
     lock (pendingConversionSync) 
     { 
      msgUrlToPdfInProgress.Visibility = Windows.UI.Xaml.Visibility.Collapsed; 
      pendingConversion = false; 
     } 
    } 
}