PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Sat Oct 11, 2025 11:36 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Apr 19, 2012 2:00 pm 
Offline

Joined: Thu Apr 19, 2012 1:53 pm
Posts: 2
Hello,
i am trying to use PdfSharp to create Sharepoint designer workflow to merge 2 pdf document.
However when i try to pass the file url to PdfReader to open the document i am getting an error about URI formats not supported.
Any help would be really appreciated. If i can't pass the file path as a URI how can i open the file with PdfReader ??
Regards,
RZ


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 23, 2012 11:52 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
Hi!
ronyz wrote:
If i can't pass the file path as a URI how can i open the file with PdfReader?
Use .NET to read the PDF file from the URI into a stream, then use PdfReader to read from that stream.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed May 09, 2012 2:18 pm 
Offline

Joined: Wed May 09, 2012 2:08 pm
Posts: 3
Hi Thomas

I have the same issue.
I'm a novice so could you expand on your answer?

This is the code I have so far:-
Code:
               
string strPDF = @"http://Myserver/MyPdf.pdf";
HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(strPDF);
HttpWebResponse myResponce = (HttpWebResponse)myRequest.GetResponse();
PdfDocument inputDocument1;
try
{
     inputDocument1 = PdfSharp.Pdf.IO.PdfReader.Open(myResponce.GetResponseStream(),PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import );
}
catch(Exception ex)
{
     lblMessage.Text = ex.ToString();
     return;
}


Many thanks in advance
Hawkmoth


Top
 Profile  
Reply with quote  
PostPosted: Wed May 09, 2012 2:26 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3136
Location: Cologne, Germany
Hi!
Hawkmoth wrote:
I'm a novice so could you expand on your answer?
So far the code looks correct.
Where's the problem?

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed May 09, 2012 2:32 pm 
Offline

Joined: Wed May 09, 2012 2:08 pm
Posts: 3
Hi Thomas

Thanks for your speedy reply.

I get thie error from the catch statment:-

System.NotSupportedException: This stream does not support seek operations. at System.Net.ConnectStream.get_Length() at PdfSharp.Pdf.IO.Lexer..ctor(Stream pdfInputStream) at PdfSharp.Pdf.IO.PdfReader.Open(Stream stream, String password, PdfDocumentOpenMode openmode, PdfPasswordProvider passwordProvider) at PdfSharp.Pdf.IO.PdfReader.Open(Stream stream, PdfDocumentOpenMode openmode) at IWManuals.Default.CombinePDFDocument(List`1 strFilename) in D:\Old_D_Drive\My Programs\CSharp 2010\IWManuals\IWManuals\Default.aspx.cs:line 47

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Wed May 09, 2012 3:32 pm 
Offline

Joined: Wed May 09, 2012 2:08 pm
Posts: 3
Hi Thomas

Think I've solved mine.
Like I said, I'm a novice at this so I'm not sure why this works and the origanal didn't.

So for anyone following in the future, This code now works:-

Code:
string strPDF = "http://MyServer/MyPdf.pdf;

byte[] buffer = new byte[4096];

WebRequest wr = WebRequest.Create(strPDF);
               
WebResponse response = wr.GetResponse();

Stream responseStream = response.GetResponseStream();
MemoryStream memoryStream = new MemoryStream();
                       
int count = 0;
do
{
   count = responseStream.Read(buffer, 0, buffer.Length);
   memoryStream.Write(buffer, 0, count);

} while (count != 0);

PdfDocument inputDocument1;
try
{
   inputDocument1 = PdfSharp.Pdf.IO.PdfReader.Open(memoryStream, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Import);
}
catch(Exception ex)
{
   lblMessage.Text = ex.ToString();
   return;
}


All the best
Hawkmoth


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 175 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group