PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Apr 18, 2024 2:14 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Jun 16, 2016 8:29 am 
Offline

Joined: Thu Jun 16, 2016 8:16 am
Posts: 3
hello ,
i have a problem when i use PDFSharp to save a PDF file using .save() and i give it the path, the PDF file is fine and it show's everything . But when i use .Save() to stream to get the byte array and then i write it as PDF it shows a blank empty PDF even tho it has the same size as the normal save with the path .
below is the code i used :

note : pDoc is pdfDocument .



Code:
MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
MigraDoc.Rendering.DocumentRenderer renderer = new DocumentRenderer(doc);
MigraDoc.Rendering.PdfDocumentRenderer pdfRenderer = new MigraDoc.Rendering.PdfDocumentRenderer();
pdfRenderer.PdfDocument = pDoc;
pdfRenderer.DocumentRenderer = renderer;
using (MemoryStream ms = new MemoryStream())
{
  pdfRenderer.Save(ms, false);
  byte[] buffer = new byte[ms.Length];
  ms.Seek(0, SeekOrigin.Begin);
  ms.Flush();
  ms.Read(buffer, 0, (int)ms.Length);
file.writeAllBytes(@"D:\test.pdf",buffer);
}


The main idea is i want to get the correct array of byte to that pDoc.

any idea ? please help thanks


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 16, 2016 8:42 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
Hi!

Maybe "file.Flush()" missing?

Why don't you simply use "ms.ToArray()"?
http://www.pdfsharp.net/wiki/Clock-sample.ashx

You could also call "ms.Capacity = (int)ms.Length;" and then use "ms.GetBuffer()".

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 16, 2016 9:43 am 
Offline

Joined: Thu Jun 16, 2016 8:16 am
Posts: 3
Thomas Hoevel wrote:
Hi!

Maybe "file.Flush()" missing?

Why don't you simply use "ms.ToArray()"?
http://www.pdfsharp.net/wiki/Clock-sample.ashx

You could also call "ms.Capacity = (int)ms.Length;" and then use "ms.GetBuffer()".


Hello Thomas ,

thanks for helping, i tried to use ms.toArray() and ms.GetBuffer() before and it still gives a blank PDF :(
although i think its a header footer maybe ? cause the file have the same size as when when i use .save() with path which work fine with me except for when i use it with stream .


Last edited by 1c1c on Thu Jun 16, 2016 10:00 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 16, 2016 9:55 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
We can't do anything with the code snippet you show us.

Give us two PDFs (the one from "Save(string)" that works and the one from "Save(stream)" that does not work and we can look for differences.

Give us a solution that allows us to try it (see Issue Submission Template, viewtopic.php?f=2&t=832) and we can have a look.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 16, 2016 10:33 am 
Offline

Joined: Thu Jun 16, 2016 8:16 am
Posts: 3
Thomas Hoevel wrote:
We can't do anything with the code snippet you show us.

Give us two PDFs (the one from "Save(string)" that works and the one from "Save(stream)" that does not work and we can look for differences.

Give us a solution that allows us to try it (see Issue Submission Template, viewtopic.php?f=2&t=832) and we can have a look.


Hello again ,
Iam using GDI+ dll's

These are the 2 files:

This one with string path :
http://docdro.id/gkBGidX

This one with stream :
http://docdro.id/FpEjTW0


Top
 Profile  
Reply with quote  
PostPosted: Thu Jun 16, 2016 11:23 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
The "stream" file is 10 bytes larger (8155 vs. 8145). Binary data was corrupted by converting ANSI characters to UTF-8 or such.

Not sure if DocDro.id mangled the files. You can ZIP both files and attach them to the forum to make sure they do not get manipulated (repaired) during upload/download.
You wrote both files had the same size. The files I downloaded have differing sizes.

You are using version 1.31. You can try version 1.50 beta 3 or version 1.32.

If you think it is a bug in PDFsharp then please create a solution that allows us to replicate the problem. You're code snippet without any drawing instructions is not enough.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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 113 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