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!
Compress existing PDF returns blank file |
Post Reply |
Author | |
ASB
Beginner Joined: 26 Nov 09 Location: Ramat Gan Status: Offline Points: 4 |
Post Options
Thanks(0)
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 |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
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 |
|
ASB
Beginner Joined: 26 Nov 09 Location: Ramat Gan Status: Offline Points: 4 |
Post Options
Thanks(0)
|
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 |
|
Rowan
Moderator Group Joined: 10 Jan 09 Status: Offline Points: 398 |
Post Options
Thanks(0)
|
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. |
|
ASB
Beginner Joined: 26 Nov 09 Location: Ramat Gan Status: Offline Points: 4 |
Post Options
Thanks(0)
|
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
|
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
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 |
|
ASB
Beginner Joined: 26 Nov 09 Location: Ramat Gan Status: Offline Points: 4 |
Post Options
Thanks(0)
|
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....
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store