PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 3:31 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Nov 26, 2009 5:36 am 
Offline

Joined: Thu Nov 26, 2009 5:13 am
Posts: 1
Hi Thomas ,

A very good morning to you :D

I am facing a problem with opening the pdf file.

My code is :

Document document = invoiceForm.CreateDocument();

// Create a renderer for PDF that uses Unicode font encoding
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

// Set the MigraDoc document
pdfRenderer.Document = document;

// Create the PDF document
pdfRenderer.RenderDocument();

// Save the PDF document...
string filename = "Invoice.pdf";

MemoryStream stream = new MemoryStream();
stream.Seek(0, SeekOrigin.Begin);

pdfRenderer.PdfDocument.Save(stream, false);


byte[] data = new byte[stream.Length];
stream.Read(data, 0, data.Length);
stream.Close();

InsertBlob("testblob", data, "application/pdf", "invoicedoc");

byte[] result = GetBlob("testblob", "invoicedoc");


Now when i convert the byte array to pdf file and try to open it then i am getting this error :
"The document does not start with %PDF-"

Please help me out...I tried to open the pdf both using the blob URL as well as by a file stream but it didn't work.

Thanks !

Regards
Rashid Ali


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 26, 2009 9:18 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Maybe you should try the
Code:
stream.Seek(0, SeekOrigin.Begin);

after the Save() {no longer needed with PDFsharp 1.31 coming out very soon now}.

Or rely on the trusted old code from the WebClock sample:
Code:
MemoryStream stream = new MemoryStream();
document.Save(stream, false);
byte[] data = stream.ToArray();

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 374 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