This is a migrated thread and some comments may be shown as answers.

Image is not imported/exported from PDF file

7 Answers 492 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Maurício
Top achievements
Rank 1
Maurício asked on 01 Feb 2016, 12:34 PM

Hello 

 The following method is supposed to import a PDF file and export it. It works as expected, except that the image is lost. 

private void Test1()
      {
          var provider = new PdfFormatProvider();
 
          var stream = File.OpenRead(@"C:\inputFile.pdf");
 
          var document = provider.Import(stream);
 
          using (var output = new FileStream(@"C:\outputFile.pdf", FileMode.OpenOrCreate))
          {
              provider.Export(document, output);
          }
      }

 

 You might say that the file is in bad format or something, but why would this work?

private void Test2()
    {
        var stream = new FileStream(@"C:\inputFile.pdf", FileMode.Open, FileAccess.Read);
 
        var source = new PdfDocumentSource(stream, FormatProviderSettings.ReadOnDemand);
 
        ViewModel.DocumentSource = source;
    }

DocumentSource is binded to the PdfViewer.DocumentSource.

 

Here is the link to the PDF inputFile: https://goo.gl/3lpe9O

 Thank you

7 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 04 Feb 2016, 09:23 AM
Hi MaurĂ­cio,

The PdfFormatProvider class is shared between RadPdfProcessing and RadPdfViewer and it is important which of the provider's constructor overloads you are using. If I correctly understand, you are trying to use RadPdfViewer. The corresponding PdfFormatProvider could be created using the constructor that takes two parameters:
PdfFormatProvider provider = new PdfFormatProvider(stream, settings);

For more information on this topic, you could refer to the Showing a File article in our documentation.

However, RadPdfViewer is intended only to display PDF files and doesn't support exporting them.

Hope this is helpful.

Regards,
Tanya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Maurício
Top achievements
Rank 1
answered on 04 Feb 2016, 10:17 AM

Hello Tanya!

 I think I wasn't clear

I will explain directly what I am trying to do:

I have two different PDF files in my hard drive. I want them to become a single RadFixedDocument so I can set it to the PdfViewer.DocumentSource.

Here's what I am doing:

    private static RadFixedDocument LoadDocument(string file)
       {
           var provider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
           using (Stream stream = File.OpenRead(file))
           {
               return provider.Import(stream);
           }
       }
 
       private void LoadPdf()
       {
           var mainDocument = new RadFixedDocument();
 
           var document1 = LoadDocument(@"C:\inputFile.pdf");
 
           var document2 = LoadDocument(@"C:\inputFile1.pdf");
 
           foreach (var page in document1.Pages.ToList())
           {
               document1.Pages.Remove(page);
               mainDocument.Pages.Add(page);
           }
 
           foreach (var page in document2.Pages.ToList())
           {
               document2.Pages.Remove(page);
               mainDocument.Pages.Add(page);
           }
 
           pdfViewer.DocumentSource = GetPdfDocumentSource(mainDocument);
       }
 
private PdfDocumentSource GetPdfDocumentSource(RadFixedDocument document)
       {
           var formatProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider
           {
               ExportSettings =
               {
                   ImageQuality = ImageQuality.High
               }
           };
 
           var pdfMemoryStream = new MemoryStream(formatProvider.Export(document));
 
           var pdfSource = new PdfDocumentSource(pdfMemoryStream, pdfViewer.DefaultFormatProviderSettings);
 
           pdfSource.Loaded += (sender, args) =>
           {
               if (pdfMemoryStream != null)
               {
                   pdfMemoryStream.Dispose();
                   pdfMemoryStream = null;
               }
           };
 
           return pdfSource;
       }

 

Here are the pdf files you can try to join (must be them because that's the point of the post, one of it doesn't show the image): https://goo.gl/Wjwk2i

 Thank you for your reply!!

0
Tanya
Telerik team
answered on 08 Feb 2016, 05:34 PM
Hi MaurĂ­cio,

I was able to reproduce the behavior you are experiencing and it is caused by a missing feature in the RadPdfProcessing library. The image in question is actually preserved as a Form XObject. We have already logged such a request and you could track its progress through this public item. However, I am afraid that I cannot suggest you a suitable approach to work around this missing functionality.

Regards,
Tanya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Vo
Top achievements
Rank 1
answered on 08 Sep 2017, 10:28 AM

Hi,

i am using pdfviewer to show pdf content from url.

 

My problem is some content is not showed.

 

I tried open my pdf file in latest demo version and this error is still appeared. (attach file)

 

Can anybody help me?

0
Tanya
Telerik team
answered on 12 Sep 2017, 02:56 PM
Hello,

I am afraid I cannot tell why the content is missing before testing the case. Is it possible to share a sample document so we can check what is causing you issues?

Regards,
Tanya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Vo
Top achievements
Rank 1
answered on 13 Sep 2017, 06:25 AM

my test case is very simple. I open a pdf by a edit pdf tool and insert some new content, then save it.

When i open edited file by pdfviewer (direct on telerik demo) --> pdf is showed but my new content is lost.

0
Maurício
Top achievements
Rank 1
answered on 13 Sep 2017, 06:55 PM
[quote]Vo said:

my test case is very simple. I open a pdf by a edit pdf tool and insert some new content, then save it.

When i open edited file by pdfviewer (direct on telerik demo) --> pdf is showed but my new content is lost.

[/quote]

I just did what you said and it worked fine.

I've created a new PDF using this online edit tool: http://www.pdfescape.com/open/

Then I drew a line, downloaded the file and opened with the PdfViewer from the demos.

Tags
PdfProcessing
Asked by
Maurício
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Maurício
Top achievements
Rank 1
Vo
Top achievements
Rank 1
Share this question
or