Print Page | Close Window

this tif can't be converto pdf

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=2194
Printed Date: 28 Sep 24 at 11:00PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: this tif can't be converto pdf
Posted By: mjohn
Subject: this tif can't be converto pdf
Date Posted: 20 Mar 12 at 5:36PM

Below tif file can't be convert to pdf.
http://www.ipwom.com/Data/Sites/1/LQ/Files/000004.zip - http://www.bjsxy.com/Data/Sites/1/LQ/Files/000004.zip

Thanks!



Replies:
Posted By: Ingo
Date Posted: 20 Mar 12 at 9:38PM
Hi!

Where's your sample code?
I can convert it but when i want to open it with adobe
i've get a message "not enough data for a picture".
Don't know what this could mean ;-)

Cheers, Ingo


Posted By: edvoigt
Date Posted: 21 Mar 12 at 10:02AM
Hi,

your file looks broken. Different programs show not the same.

Picasapreview shows a white paper.
MS-Photoeditor shows Text and last line on half and a black area.
Irfanview shows text like MS-Photoeditor, but the last line only half.

Your can't hope that wrong input gives correct output. The source of your file is the problem.


Cheers,
Werner




Posted By: mjohn
Date Posted: 21 Mar 12 at 1:55PM
I get the message "not enough data for a picture" too.
But I use Microsoft office document Imaging Can see the most content of this tif file.
And the Microsoft office Picutre Manager Can see the most content of this tif file too.
When drag the tif file to Microsoft word, word Can see the most content of this tif file too.
But Quick PDF Library can't see any content of this tif file.
If  Quick PDF Library can see the good part the tif file, then it will be perfect.

Thanks!



Posted By: mjohn
Date Posted: 21 Mar 12 at 2:02PM
This file is downloaded from USPTO-United States Patent and Trademark Office
http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PG01&p=1&u=%2Fnetahtml%2FPTO%2Fsrchnum.html&r=1&f=G&l=50&s1=20120004625.PGNR.&OS=DN/20120004625&RS=DN/20120004625And%20there%20has%20many broken files%20as%20this%20tif%20file. - http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PG01&p=1&u=%2Fnetahtml%2FPTO%2Fsrchnum.html&r=1&f=G&l=50&s1=%2220120004625%22.PGNR.&OS=DN/20120004625&RS=DN/20120004625

And there has many broken files as this tif file.




Posted By: edvoigt
Date Posted: 21 Mar 12 at 3:59PM
Hi,

if you know that the file is corrupted, you should try a repair.

So you may save, what is to save.

In case of your example, I open it with Irfanview and did a save to another location. Because the program rebuilds the structure of file, it is repaired (with loss of destroyed part of course).

After this QPL made a PDF, which is fully correct. That's the proof, that QPL works with correct builded input.


Cheers again,

Werner



Posted By: mjohn
Date Posted: 21 Mar 12 at 4:36PM
But before open the merged pdf file that quick pdf  converted, 
I didn't know whick tif file is  corrupted. I have many many tif files need to be merged to many pdf files. 
I can't view all the tif files one by one before I merge them to pdf files.
Only after I open the merged pdf file, I get the message "not enough data for a picture", then I know there  is a corrupted tif file in the merged pdf file.
I hope QPL can give a tip when it detect a tif file is corrupted before merged to a pdf file or throw a error.
And I hope QPL can give a method to rebuilds the structure of the corrupted tif file too.
Thanks!


Posted By: edvoigt
Date Posted: 21 Mar 12 at 5:16PM
Hi,

QPL takes the image-file and embeds it only in PDF-code. As I think, there is no kind of looking for errors inside, because the main part of the image is only copied as is. So you get there no errormessage. But if you try to render this PDF - QPL does it! In this point it looks harder than adobe reader!

So I see no way of automated test of integrity.

QPL is no imageprocessor and hopes that the images are build correct.

But in Irfanview there is an easy to use batch-facillity. There you may configure a job like take all tiffs from one place and store them to another place. So you could use the clearing files (needed or not) without taking one by one every file in your fingers. If a file is ok, this process does not disturb, but after this you should have no more corrupted files. Try it!


Cheers,

Werner



Posted By: Ingo
Date Posted: 21 Mar 12 at 8:08PM
Hi!

You can render the pdf-pages to a stream
and convert it to bmp for example. Then
you can check the pixel rows and columns
(scanline!). If there are only white pixels
you know that there's a corrupt page. To
make this routine not too slow you should
scale the bmp down ;-)

This could be a starting point for you:
     pix := 64; // for example...
     QP.RenderPageToStream(72,page,0,test_stream); // render to bmp
     test_stream.Seek(0,0);
     bmp := TBitmap.Create;
     bmp2 := TBitmap.Create;
     bmp2.Width := Round(pix);
     bmp2.Height:= Round(pix);
     bmp.LoadFromStream(test_stream);
     bmp2.Canvas.StretchDraw(Rect(0, 0, pix, pix), bmp);

     for x := 0 to bmp2.Height - 1 do begin
        for y := 0 to bmp2.Width - 1 do begin
           geco  := bmp2.Canvas.Pixels[x,y];
           rgb   := ColorToRGB(geco);
           c1    := GetRValue(rgb);
           c2    := GetGValue(rgb);
           c3    := GetBValue(rgb);
// and so on ...

Cheers, Ingo


Posted By: mjohn
Date Posted: 21 Mar 12 at 8:15PM
Hi. edvoigt and Ingo.
Thank you all very much!


Posted By: edvoigt
Date Posted: 21 Mar 12 at 8:28PM
Hi,

Ingo's idea is nice, but no save way.

By the way Canvas.pixels is much too slow, if then use scanlines.

Your example-tif (0000004.tif) does not end in white pixels. The picture here is comming from QPL:



On a corrupted file nobody is able to say, how it will look. It looks different from program to program.


Werner


Posted By: mjohn
Date Posted: 21 Mar 12 at 8:42PM
Hi.
Now I found use itextsharp can convert this tif to pdf. 
But Quick PDF Library  can't.
So I thinks it not too good.
Here is the code i changed from the web use itextsharp.

///////////////////////////////////
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Drawing.Imaging;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Document document = new Document(PageSize.A4, 50, 50, 50, 50);

            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"D:\Image.pdf", FileMode.Create));

            System.Drawing.Bitmap bm = new System.Drawing.Bitmap(@"D:\000004.tif");
            int total = bm.GetFrameCount(FrameDimension.Page);

            document.Open();
            PdfContentByte cb = writer.DirectContent;

            for (int k = 0; k < total; ++k)
            {
                bm.SelectActiveFrame(FrameDimension.Page, k);
                MemoryStream ms = new MemoryStream();
                bm.Save(ms, ImageFormat.Tiff);

                iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms.ToArray());

                img.ScalePercent(72f / (float)img.DpiX * 100);
                img.SetAbsolutePosition(0, 0);

                cb.AddImage(img);
                document.NewPage();
            }
            document.Close();
        }
    }
}
////////////////////////////////////////////////
The full project source is here:
http://www.bjsxy.com/Data/Sites/1/LQ/Files/tif.rar - http://www.bjsxy.com/Data/Sites/1/LQ/Files/tif.rar

So you can see,  Quick PDF Library can't do well as iTextSharp.
Thanks! 



Posted By: AndrewC
Date Posted: 22 Mar 12 at 10:02AM
Your iTextSharp example is cheating and has nothing to do with iTextSharp being able to handle the image properly.  You code is using GDI+ to load the image into memory and then using the repaired image into iTextSharp.  If you used the same code to convert the TIFF image  ( bm.Save(ms, ImageFormat.Tiff); before loading into QPL then QPL would load the file correctly also.

Or you could just add call   QP.AddImageFromFile("000004.pdf", -page);  which uses GDI+ to load the page.  Note the negative page number. You will need to use the latest 8.14 beta 6 to process multipage tiffs with -page.

http://www.quickpdflibrary.com/blog/2012/03/quick-pdf-library-8-14-beta-6-released/

Andrew.


Posted By: mjohn
Date Posted: 22 Mar 12 at 2:39PM
Hi, AndrewC!
Thank you very much!


Posted By: mjohn
Date Posted: 29 Mar 12 at 5:58AM
Hi.  AndrewC!
file 000004.tif is 94k
when use QP.AddImageFromFile("000004.tif", 0)
The pdf file become 97K
But when use QP.AddImageFromFile("000004.tif", -page)
The pdf file become 297K.
So when use gid+, is too large.
So
1. How to reduce the pdf file size when I use gdi+ to load the tif file?
2. How to let QP to use tif format first when failed then use gdi+ to load the tif file?
Thanks!





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