PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 01, 2024 10:12 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Oct 16, 2013 11:25 am 
Offline

Joined: Wed Oct 16, 2013 10:54 am
Posts: 3
I'm having some issues with creating PDF's, which I suspect is my own fault! :)

I am trying to create a PDF with a background image. That is it.

This is from a Project (Visual Studio 2012) although it's a website.

public static string CreateTest()
{
try
{
string directory = @"C:\Users\Dave\Documents\Visual Studio 2012\Projects\Website\LifeCry\LifeCry\Content\Poster\";

PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
document.Options.NoCompression = true;
document.Options.ColorMode = PdfColorMode.Cmyk;
document.Version = 14;
page.Size = PdfSharp.PageSize.A4;

XImage xImagePosterBackground = XImage.FromFile(directory + "LifeCryPosterA4.jpg");

XGraphics graphics = XGraphics.FromPdfPage(page);

graphics.DrawImage(xImagePosterBackground, new XPoint(0, 0));

string fileName = DateTime.Now.ToString("yyMMddhhmmss") + ".pdf";

document.Save(directory + fileName);

return "../Content/Poster/" + fileName;
}
catch (System.Exception ex)
{
string s = ex.ToString();
System.Diagnostics.Debug.Assert(false, "beep beep, it failed!");
//TODO - impelement me (yeah, what ever)
}
}

The issue is the page exports/renders incorrectly in anything but FireFox. This means, in IE, Chrome, PDX-XChange and PhotoShop, it renders incorrectly. See attached for screen shots of how it renders and how it should be.

Here, I hope, you can see the issue.

Is this a fault with my code? Any advice would be appreciated.

Dave


Attachments:
File comment: HowItShouldBe
howItShouldBe.gif
howItShouldBe.gif [ 46.02 KiB | Viewed 7059 times ]
File comment: HowItIsExporting
render.gif
render.gif [ 121.86 KiB | Viewed 7059 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 16, 2013 12:36 pm 
Offline
PDFsharp Guru
User avatar

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

I presume your code will work under Windows XP.

Here's a proposed change that may work with Windows NT 6.0 through 6.3 (aka Vista, 7, 8, 8.1):
viewtopic.php?p=6963#p6963

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 16, 2013 2:34 pm 
Offline

Joined: Wed Oct 16, 2013 10:54 am
Posts: 3
Thank you for the reply but the post cited has left me confused.

The post suggests the following

Quote:
using (FileStream sourceFile = File.OpenRead(image.path))


But, as far as I know,
Code:
image
doesn't have a path property.

Either way, I can just create a string reference but, I don't see how I then pass this from a memory object into an XImage

Code:
graphics.DrawImage(xImagePosterBackground, new XPoint(0, 0));


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 16, 2013 2:51 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
The change has to go to the XImage.cs file - and there is a path member (or _path).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 18, 2013 1:36 pm 
Offline

Joined: Wed Oct 16, 2013 10:54 am
Posts: 3
I did what you suggested so the ximage.cs file now looks like

Code:
#if GDI

      memory = new MemoryStream();
     
        if (!image.path.StartsWith("*"))
      {
         using (FileStream sourceFile = File.OpenRead(image.path))
         {
            int count = 0;
            byte[] buffer = new byte[1024];
            memory = new MemoryStream((int)sourceFile.Length);
            do
            {
               count = sourceFile.Read(buffer, 0, buffer.Length);
               memory.Write(buffer, 0, buffer.Length);
            }
            while (count > 0);

         }
      }
      else
      {
         memory = new MemoryStream();
         image.gdiImage.Save(memory, ImageFormat.Jpeg);
      }

       
       //DR comment based upon pdfsharp suggestion image.gdiImage.Save(memory, ImageFormat.Jpeg);
      if ((int)memory.Length == 0)
      {
        Debug.Assert(false, "Internal error? JPEG image, but file not found!");
      }
#endif


This made no difference I'm afraid to say.

Thank you for your quick replies so far, it is appreciated.

Do you know what I've done wrong?


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

All times are UTC


Who is online

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