Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Compress existing PDF returns blank file
  FAQ FAQ  Forum Search   Register Register  Login Login

Compress existing PDF returns blank file

 Post Reply Post Reply
Author
Message
ASB View Drop Down
Beginner
Beginner
Avatar

Joined: 26 Nov 09
Location: Ramat Gan
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote ASB Quote  Post ReplyReply Direct Link To This Post Topic: Compress existing PDF returns blank file
    Posted: 26 Nov 09 at 12:01PM
Hi,
 
I used some xmpl code to take an existing PDF file ,compress it ( it's rather large for a 2 page file : 1.5 Mb; it  has some pics in it ) with all 3 compression modes and save it as another pdf file.
The result is a blank 1 KB file. As far as i know the file is not encrypted and has no password on it.
I used to use PDFCreator to shrink the file size - that's my sole purpose, but got permissions trouble with the Printer, and prefer to continue with Code only.
 
Why does this give me a blank pdf. Do i something wrong here? No error is given. Thanks!
below is my code.
 
btw , why is the handle for opening the file a "long" and when closing you need an "int" ?
 
 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using QuickPDFDLL0717;

namespace Hello_World

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void btnHelloWorld_Click(object sender, EventArgs e)

{

// Create an instance of the class and give it the path to the DLL

PDFLibrary QP = new PDFLibrary("C:\\QuickPDFDLL0717.dll");

long lngPDF;

// Check if the DLL was loaded successfully

if (QP.LibraryLoaded())

{

// Include and check the validity of the license key

if (QP.UnlockKey("......") == 1)

{

lngPDF =QP.DAOpenFile("C:\\TEST1.PDF","");

if (lngPDF == 0)

{

//coult not be opened

MessageBox.Show("err");

}

if(QP.CompressFonts(1)==0)

{

//not succeeeded

MessageBox.Show("err");

}

if (QP.CompressImages(1) == 0)

{

//not succeeded

MessageBox.Show("err");

}

if (QP.CompressContent() == 0)

{

//not succeeded

MessageBox.Show("err");

}

if (QP.SaveToFile("c:\\pdftestdone.pdf") == 0)

{

//could not be saved

}

QP.DACloseFile(Convert.ToInt32(lngPDF));

}

}

}

}

}



Edited by Rowan - 26 Nov 09 at 11:46PM
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 29 Nov 09 at 9:29PM
Hi!

The "Unlock" is missing ...
You wrote "as far as i know"...
Why not use a syntax like "If encrypted then decrypt it"?

Cheers, Ingo
Back to Top
ASB View Drop Down
Beginner
Beginner
Avatar

Joined: 26 Nov 09
Location: Ramat Gan
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote ASB Quote  Post ReplyReply Direct Link To This Post Posted: 30 Nov 09 at 7:40AM
I'm using unlock
; i just didnt post the key which is

(key info removed by Michel K-17 - not sure if it was a demo key or not)

about QP.Encrypted : I quite kept looking for this function and didnt see it, until I saw "EncryptionStatus" ; Encrypted was renamed inversion 7.11 ..... And btw , the file is NOT encrypted : the status was 0.
 
Any other clues why this shouldnt work? Otherwise we'll continue to check out other products.
 
Here is the changed code, including active key, and check for encryption:
 

PDFLibrary QP = new PDFLibrary("C:\\QuickPDFDLL0717.dll");

long lngPDF;

// Check if the DLL was loaded successfully

if (QP.LibraryLoaded())

{

// Include and check the validity of the license key

if (QP.UnlockKey("...license_key...") == 1)

{

lngPDF =QP.DAOpenFile("C:\\TEST1.PDF","");

if (lngPDF == 0)

{

//coult not be opened

MessageBox.Show("err");

}

//QP.SetPassword("");

try

{

if (QP.EncryptionStatus() > 0)

{

QP.SetPassword("");

if (QP.Decrypt() == 0)

{

MessageBox.Show("could not be decrypted");

}

}

}

catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

if(QP.CompressFonts(1)==0)

{

//not succeeeded

MessageBox.Show("err");

}

if (QP.CompressImages(1) == 0)

{

//not succeeded

MessageBox.Show("err");

}

if (QP.CompressContent() == 0)

{

//not succeeded

MessageBox.Show("err");

}

if (QP.SaveToFile("c:\\pdftestdone.pdf") == 0)

{

//could not be saved ok

}

QP.DACloseFile(Convert.ToInt32(lngPDF));

}

}

}

}



Edited by Rowan - 01 Dec 09 at 11:40PM
Back to Top
Rowan View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 10 Jan 09
Status: Offline
Points: 398
Post Options Post Options   Thanks (0) Thanks(0)   Quote Rowan Quote  Post ReplyReply Direct Link To This Post Posted: 30 Nov 09 at 7:34PM
The problem is that you're trying to mix Direct Aaccess (DA) and regular functions. Instead of using SaveToFile to save the file, use the DASaveAsFile instead. However, you're using the compress functions, which aren't available in DA mode, so you'll won't be able to us the DA functions.

Instead try this:

LoadFromFile
CompressFonts
CompressImages
CompressContent
SaveToFile

The list of DA functions can be found here:


I hope this helps.

Cheers,
- Rowan.

Back to Top
ASB View Drop Down
Beginner
Beginner
Avatar

Joined: 26 Nov 09
Location: Ramat Gan
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote ASB Quote  Post ReplyReply Direct Link To This Post Posted: 30 Nov 09 at 9:15PM
Hi,
 
Thank you for giving me the correct code I needed. At least a file is created in the end. Unfortunately the compress functions you give do not change a dime in the size of the file; it stays the same size. Do yo have any other functionality to decide about the level of compression? That is besides "1" in the compression function itself?
 
Thanks
 
Alain
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 01 Dec 09 at 6:15AM
Hi Alain!

What's the structure/content of the document?
No embedded but only referenced fonts?
Only compressed jpg-images?
If it's so then what shall the compress function do ;-)

Cheers, Ingo

 
Back to Top
ASB View Drop Down
Beginner
Beginner
Avatar

Joined: 26 Nov 09
Location: Ramat Gan
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote ASB Quote  Post ReplyReply Direct Link To This Post Posted: 01 Dec 09 at 9:10AM
Hi,
 
Until now I have been using PDF Creator. In this application I can choose to what quality to compress color/bw/monochrome jpg images, downgrade, low quality etc. This really shrinks the file, especially if inside the file you have a pic of 900k , and you can define by yourself the quality of the image, thats great. you only have option "flatten", which im not sure of does someting....
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store