Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

PageWidth difrent from DAGetPageWidth

Question

I'm testing QuickPdf Library and i'm trying to copy one image from one pdf to another, and get an error regarding the image position. I have made same tests and got that PageWidth is difrent from DAGetPageWidth one gives me 612.0 and the other 595.35. I think that is the cause for my image to be set in a difrent location. How can I work arrond that? Here is the code (I got it from this forum..):

PDFLibrary QP = new PDFLibrary();
QP.UnlockKey(licenseKey);
int FileHandle = QP.DAOpenFile(FileName, "");
int PageRef = 0;
string PageText = "";
string Font = "";
string color = "";
string size = "";
string x1, y1, x2, y2, x3, y3, x4, y4;
string word = "";
byte[] ImageData;

for (int i = 1; i <= QP.DAGetPageCount(FileHandle); i++)
{
    // Create a emptly document in memory
    int NewId = QP.NewDocument();
    QP.CompressImages(1);
    // Get Page reference
    PageRef = QP.DAFindPage(FileHandle, i);
    // Get Page Text in CSV format. with the following Format
    //Font Name, Text Color, Text Size, X1, Y1, X2, Y2, X3, Y3, X4, Y4, Text
    PageText = QP.DAExtractPageText(FileHandle, PageRef, 4);
    string[] TextLines = PageText.Split(Environment.NewLine.ToCharArray());

    foreach (string line in TextLines)
    {
try
{
    // parse required for each line
    string[] DataFields = line.Split(",".ToCharArray());
    Font = DataFields[0];
    color = DataFields[1];
    size = DataFields[2].Trim();
    x1 = DataFields[3];
    y1 = DataFields[4];
    x2 = DataFields[5];
    y2 = DataFields[6];
    x3 = DataFields[7];
    y3 = DataFields[8];
    x4 = DataFields[9];
    y4 = DataFields[10];
    word = DataFields[11].Replace("\"", "");

    // Set text font size
    QP.SetTextSize(Convert.ToDouble(size));
    // Draw text to new docmuent
    QP.DrawText(Convert.ToDouble(x1), Convert.ToDouble(y1) - QP.GetTextDescent(), word);
}
catch
{ ;}
    }
    // Get image list reference
    int ImageListId = QP.DAGetPageImageList(FileHandle, PageRef);

    for (int j = 1; j <= QP.DAGetImageListCount(FileHandle, ImageListId); j++)
    {
// Convet image data into byte array
QP.AddImageFromVariant(ImageData, 0);
// Retrieve images top,left, height and width


    ------->    double pw = QP.PageWidth();
double pH = QP.PageHeight();

int pageHandle = QP.DAFindPage(FileHandle, 1);
    ------->    double pwd = QP.DAGetPageWidth(FileHandle, pageHandle);
double pHd = QP.DAGetPageHeight(FileHandle, pageHandle);
double imgLeft = QP.DAGetImageDblProperty(FileHandle, ImageListId, j, 501);
double imgTop = QP.DAGetImageDblProperty(FileHandle, ImageListId, j, 502);
double imgWidth = QP.DAGetImageDblProperty(FileHandle, ImageListId, j, 503) - 
QP.DAGetImageDblProperty(FileHandle, ImageListId, j, 501);
double imgHeight = QP.DAGetImageDblProperty(FileHandle, ImageListId, j, 502) - 
QP.DAGetImageDblProperty(FileHandle, ImageListId, j, 508);

// Draw image to new document
QP.DrawImage(imgLeft, imgTop, imgWidth, imgHeight);
    }

    // Save each page to new file increment by one
    QP.SaveToFile("C:\\XPod" + Convert.ToString(i) + ".pdf");
Answer

This issue has been resolved in the latest version of Quick PDF Library. You can update to the latest version on our Product Updates page.


© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum