PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon May 06, 2024 8:50 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: PagePreview problem
PostPosted: Sun Apr 06, 2008 11:23 am 
Offline

Joined: Sat Apr 05, 2008 8:39 pm
Posts: 1
Hi,

I've got problem with pdf preview.

This is my C# code:

public partial class PrintForm : Form, IPrintForm
{
private PagePreview.RenderEvent renderEvent;
private System.IO.MemoryStream memStream;
public PrintForm()
{
InitializeComponent();
}
public void ShowPrintForm(System.IO.MemoryStream mem)
{
this.memStream = mem;
this.renderEvent = new PagePreview.RenderEvent(Render);
pagePreview.SetRenderEvent(this.renderEvent);
this.ShowDialog();
}
private void Render(XGraphics gfx)
{
PdfDocument document = PdfReader.Open(this.memStream);
gfx = XGraphics.FromPdfPage(document.Pages[0]);
}

...

}

I'm using VS 2008 Express Edition with PDFSharp v.1.0.898.0
PDFSharp was compiled under VS2008 and Runtime version 2.0.50727.
I'm using PdfSharp.Forms.PagePreview for viewing PDF's.

Problem: I'm receiving blank preview.

When I put this code in Render method:

PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
gfx.DrawString("Hello, World!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height),
XStringFormat.Center);

.... everything works good.

When I try save document (in Render metod) ... everything works good.

Does anyone know what is wrong ?

Thanks
Adam S.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 14, 2008 8:14 pm 
Offline

Joined: Tue Oct 14, 2008 7:53 pm
Posts: 4
Hi,

Is there a solution for this problem already? I encountered a similar (if not the same) one - the following code does produce an empty preview.

Code:
        [...]
        PdfDocument outputDocument = new PdfDocument();
        PdfDocument inputDocument = PdfReader.Open(<<some_file_or_filestream>>, PdfDocumentOpenMode.Import);
               
        for (int i = 0; i < inputDocument.PageCount; i++) {
            PdfPage page = inputDocument.Pages[i];
            outputDocument.AddPage(page);
        }

        for (int i = 0; i < outputDocument.PageCount; i++) {
            PdfPage page = outputDocument.Pages[i];
            gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);
        }
        [...]


The code above is an excerpt from the Preview sample Render(XGraphics) method which I modified.

Any help would be much appreciated. TIA


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Oct 15, 2008 8:23 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
Hello!

It's by design that only XGraphics show in Preview, not imported PDF pages.

Imported pages will show when a PDF file is created (directly or indirectly from the Preview dialogue).

Workaround: Create PDFs directly and show them with Adobe Reader.

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

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