Print Page | Close Window

Compress existing PDF returns blank file

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=1283
Printed Date: 04 May 24 at 2:13AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Compress existing PDF returns blank file
Posted By: ASB
Subject: Compress existing PDF returns blank file
Date 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));

}

}

}

}

}




Replies:
Posted By: Ingo
Date 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


Posted By: ASB
Date 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));

}

}

}

}



Posted By: Rowan
Date 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:

http://www.quickpdflibrary.com/help/quickpdf/DirectAccessFunctionality.php - http://www.quickpdflibrary.com/help/quickpdf/DirectAccessFunctionality.php

I hope this helps.

Cheers,
- Rowan.



Posted By: ASB
Date 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


Posted By: Ingo
Date 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

 


Posted By: ASB
Date 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....



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