Print Page | Close Window

Blank bitmaps from RenderDocumentToFile

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=237
Printed Date: 15 May 24 at 8:30AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Blank bitmaps from RenderDocumentToFile
Posted By: Pirmin
Subject: Blank bitmaps from RenderDocumentToFile
Date Posted: 04 Jan 06 at 3:12AM

Hello,

The following C# program works good for some PDF documents, but for the iSED manual it doesn't work at all.
Every resulting bitmap page I check appears to be blank. When I view such a page with a HEX-Editor, I see a header followed bei 0xff for the rest of the file. With some different PDF files I tried the program, some pages have been rendered correctly, while some pages have appeared blank also.

using System;
using System.IO;
using System.Text;
using System.Drawing;
using iSED = SEDTech.iSED;
class Test
{
    public static void Main()
    {
        iSED.QuickPDF qp = new iSED.QuickPDF();
        qp.UnlockKey( "your key" );

        string file = "iSEDQuickPDF 5.11 Reference Guide.pdf";

        Console.Write( "Loading PDF file " + file );
        int result = qp.LoadFromFile( file );
        int pages = qp.PageCount();

        if ( result == 1 )
        {
            Console.WriteLine( "Rendering " + file + " (" + pages.ToString() + " pages)" );
            qp.RenderDocumentToFile(72, 1, pages, 0, "Page_%p_of_file.bmp" );
        }

        Console.WriteLine( "Finished!" );
    }
}

Could please somebody try this program, ported to Delpi, ActiveX or something else?

Thanks in advance.

Best regards,
Pirmin




Replies:
Posted By: swb1
Date Posted: 04 Jan 06 at 10:31AM

I tried the following in Delphi. I got the same results that you did , Pirmin.

procedure TForm1.Button3Click(Sender: TObject);
var qp : TiSEDQuickPDF;
begin
 if OpenDialog1.Execute then
  begin
  qp := TiSEDQuickPDF.Create;
   try
   qp.UnlockKey(MY_QDPF_KEY);
   qp.LoadFromFile(OpenDialog1.FileName );
   Screen.Cursor := crHourGlass;
   qp.RenderDocumentToFile( 72, 1, qp.PageCount, 0, 'ISedDoc.bmp' );
   finally
   Screen.Cursor := crDefault;
   qp.Free;
   end;
  end;
end;

I then changed my code to this :

 

procedure TForm1.Button3Click(Sender: TObject);

var qp : TiSEDQuickPDF;

      i : integer;

      stream : TMemoryStream;

      bmp : TBitmap;

begin

      if OpenDialog1.Execute then

            begin

            stream := TMemoryStream.Create;

            bmp := TBitmap.Create;

            qp := TiSEDQuickPDF.Create;

                  try

                  qp.UnlockKey(MY_QDPF_KEY);

                  qp.LoadFromFile(OpenDialog1.FileName );

                  Screen.Cursor := crHourGlass;

                  for i := 1 to qp.PageCount do

                        begin

                        stream.Clear;

                        qp.RenderPageToStream(72,i,0,stream );

                        stream.Position := 0 ;

                        bmp.LoadFromStream( stream );

                        bmp.SaveToFile(ExtractFilePath(OpenDialog1.FileName) + Format('ISedDoc%d.bmp',[ i ]));

                        end;

                  finally

                  Screen.Cursor := crDefault;

                  stream.Free;

                  bmp.Free;

                  qp.Free;

                  end;

            end;

end;

 

This took longer to run however the resulting bitmap files appeared to be correct.

 

I don’’t know the equivalent structures for TMemoryStream and TBitmap in C# however this is the method I have used in the past (with Delphi) and it has work reliably for me.

 

Perhaps when I find myself  with some time on my hands I will step through the RenderDocumentToFile function and see if I can tell why it is yielding null Bitmaps.

 

Steve

 



Posted By: Pirmin
Date Posted: 04 Jan 06 at 10:34PM

Hi Steve

Thank you! When I was reading the code in your post, it looked a kind of familiar to me.
The equivalent function RenderPageToString gives good results!
In my topic Convert string from RenderPageToString I have described how I used this function and what workarounds are necessary to make it work properly.
When I saw, that RenderPageToString needed about 6 times more time then RenderDocumentToFile (as you noted also), I thought it would be better, using RenderDocumentToFile. After having to solve other problems and because sometimes I have to pause my work for a long time, I forgot about the rendering problems I have found myself.
Now my conclusion is, to be slow is better than to be faulty. So I will definitely use the function RenderPageToString instead of RenderDocumentToFile.

Best regards,
Pirmin




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk