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
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
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!!
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
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?
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
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.
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.