2016-04-01 13 views
1

私の奇妙な問題をPDFSharpで読む時間を取ってくれてありがとう。PDFSharpはC#とWPFで風景ページを切り詰めています

私はPDFファイルをパスワードで保護するために、PDFSharp Library Version 1.50.4000.0(私は1.3.2からアップデートして同じ問題があります)を使用します。

このプログラムはポートレート文書ではうまく動作しますが、時折、向きが混在する文書があります。

しかし、ドキュメント内にランドスケープページがあるときはいつも、ページがカットされています。

あなたの参照のためのコード:

PdfDocument document = PdfReader.Open(System.IO.Path.Combine("H:/Bloq1/", file.Name), "PasswordHere"); 

        PdfSecuritySettings securitySettings = document.SecuritySettings; 
        securitySettings.OwnerPassword = "PasswordHere"; 


        securitySettings.PermitAccessibilityExtractContent = false; 
        securitySettings.PermitAnnotations = false; 
        securitySettings.PermitAssembleDocument = false; 
        securitySettings.PermitExtractContent = false; 
        securitySettings.PermitFormsFill = true; 
        securitySettings.PermitFullQualityPrint = true; 
        securitySettings.PermitModifyDocument = false; 
        securitySettings.PermitPrint = true; 

        document.Save(System.IO.Path.Combine("H:/Bloq1/", file.Name)); 

        tbx.Text = "Complete"; 
        tbx.Background = Brushes.ForestGreen; 

お時間を事前に感謝し、この質問を読んだり答える= D

**************** *************解決済み************************************ *********

私はiTextSharpに切り替えて、文書のカップルをテストし、私は参照用のコードを共有しましょうかなりうまく機能:

private void Button_Full(object sender, RoutedEventArgs e)//PROTEGE PDF PERMITIENDO IMPRESION 
    { 
     string Password = "password"; 

     DirectoryInfo dir = new DirectoryInfo("H:/Bloq1/"); 

     if(dir.GetFiles("*.pdf").Length ==0) 
     { 
      MessageBox.Show("There are no files in the default directory", "No Files", MessageBoxButton.OK, MessageBoxImage.Warning); 
      tbx.Background = Brushes.OrangeRed; 
      tbx.Text = "No Files Found"; 
     } 
     else 
     { 
      tbx.Background = Brushes.White; 
      tbx.Text = "Protecting...."; 

      foreach (FileInfo file in dir.GetFiles("*.pdf")) 
      { 
       try 
       {  
        string InputFile = System.IO.Path.Combine("H:/Bloq1/", file.Name); 
        string OutputFile = System.IO.Path.Combine("H:/Bloq1/", "@"+file.Name); 
        using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read)) 
        { 
         using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None)) 
         { 
          PdfReader.unethicalreading = true; 
          PdfReader reader = new PdfReader(input);         
          PdfEncryptor.Encrypt(reader, output, true, null, Password, PdfWriter.AllowPrinting);         

         } 
        } 

        file.Delete(); 
        File.Move(@"H:\Bloq1\@"+file.Name, @"H:\Bloq1\"+file.Name); 

        tbx.Text = "Full Protected"; 
        tbx.Background = Brushes.ForestGreen; 
       } 
       catch (Exception ex) 
       { 
        tbx.Text = "Error in: " + file.Name + ex; 
        tbx.Background = Brushes.IndianRed; 

       } 
      } 
     }      
    } 
+2

可能な重複(http://stackoverflow.com/questions/10948731/page-truncate-in-right-side-for-landscape- orientation-with-trimmargins-using-pdf) –

+0

あなたがリンクしているポストでは、新しいpdfをレンダリングしています。 – Kuri

答えて

0

私はiTextSharpに切り替えて文書のカップルをテストし、働くかなりよく、私がトップで、参照用のコードを共有します。

は、「私はiTextのに切り替えた」と信じている人のために、すべての

0

あなたがPDFsharpのソースコードのバージョンを使用している場合は、それはあなたの問題を解決するかどうかを確認するためにPdfPage.csでこの変更を行うことができます。

internal PdfPage(PdfDictionary dict) 
    : base(dict) 
{ 
    // Set Orientation depending on /Rotate. 
    //int rotate = Elements.GetInteger(InheritablePageKeys.Rotate); 
    //if (Math.Abs((rotate/90)) % 2 == 1) 
    // _orientation = PageOrientation.Landscape; 
} 

あなたがさらに確認する必要があれば、私はフィードバックを見て喜んでいると思いますそれが機能するように変更されます。

も参照してください:
http://forum.pdfsharp.net/viewtopic.php?p=9591#p9591

+0

私はソースコードを持っていないのでitextsharpに切り替えます。versión=(トップにあるコードを共有します。回答は@ThomasH – Kuri

+0

です。ソースコードは、SourceForge、GitHubのCodePlexにあります。 –

2

にありがとう、私はPDFSharpのための「修正」を見つけた、答えではありません。

ソースコードに潜んでいないPDFSharpは横向きのページで冗長回転をしているようです。これにより、私が作業していたドキュメントのランドスケープページが修正されました。

PdfPages pageCollection = pdfDoc.Pages; 
     for (int i = 0; i < pageCollection.Count; i++) 
     { 
      if pageCollection[i].Orientation.ToString().Equals("Landscape")) 
      { 
       if (pageCollection[i].Rotate == 90) 
       { 
        pageCollection[i].Orientation = ageOrientation.Portrait; 
       } 
      } 
     } 
    } 
[ページPdfSharp使用trimmarginsと横向き用右側に切り捨てる〕の
関連する問題