Converting Doc to Pdf with problems

Hey,
I created with Aspose Words jdk 1.6 v 4.0.2 BETA the MfM.doc file.

Inserting an image with

Shape shape = builder.insertImage(this.scaleImage(images[i].getImage(), scale));

After converting the document to a PDF File I got the MfM.pdf document which is in the attachments

On opening it in Acrobat Reader 9.4 I got errors on opening it, on other reader like Okular (linux) the document opens, but it isn’t correct it has got errors you can se it in MfM.pdf

I also tried using 4.0.3 same thing.
On 10.0.0 BETA I wasn’t able to start it, there are to many thins changed in this versione!
For example PdfOptions which doesn’t exist.

I tested it also on Windows and Linux

Can you help me?

thx
Michael

Hi Michael,
Thanks for your request. I would suggest you to use 10.0.0 version. But you are right there are some changes in API so you will have to change your code a bit. If you need I can help you to resolve the problem with code.
Best regards,

Ok thx …
first of all PaperSize.A4… A3…A5 now are A_4 … A_3 …

thats not a problem because it’s the same methode to cal it. but there isn’t reverse compatibility and that’s in my opinion not good. But it’s not the thing I need help

My first problem are on save doc to pdf.
Old code

PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setCompliance(PdfCompliance.PDF_A_1_B);
pdfOptions.setTrueTypeFontsFolder("/usr/java/fonts");


doc.saveToPdf(0, doc.getPageCount(), byteArrayOutputStream, pdfOptions);

there is no PdfOption and no doc.saveToPdf

there are other problems… but first on all let us resolve this problem

thx
Michael

Hi Michael,
Thanks for your request. Now you should use FontSettings to specify folder where your fonts are installed and PdfSaveOptions instead of PdfOptions:

// Specify folder where Aspose.Words will llok for fonts.
FontSettings.setFontsFolder("C:\\Windows\\Fonts");
// Open document.
Document doc = new Document("C:\\Temp\\in.doc");
// Create PDF save optiosn.
PdfSaveOptions opt = new PdfSaveOptions();
opt.setCompliance(PdfCompliance.PDF_A_1_B);
// Save as PDF.
doc.save("C:\\Temp\\out.pdf", opt);

Also, you can find some answers here:
https://forum.aspose.com/t/71081
Best regards,

Ok first of all
thx

I have to set also the FontSettings bevor working with the document and merge fields. On previous versions I set it bevor converting to PDF.

On using now 10.0.0.BETA and testing it, I have to say I had the same issue on the document. or even worser, now the .DOC document is also not right.

Hi Michael,
Thank you for additional information. I managed to reproduce the problem with PDF. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.
Could you also provide source files and code that will allow me to reproduce the problem with DOC?
Best regards,

Hey,

so I extract the logic from my APP and make an external Eclipse Project what does only what have to do for testing.

The app loads the Image.jpg from the resources, converts it to an RenderedOp put it to 150dpi and scale it to the perfekt size to put the image in an A4 with now border.
After that I convert the DOC to an PDF File.

So with AsposeWords 4.0.2BETA opening the WORD file is PERFECT.
With AsposeWords 10.0.0. the Image is bigger then the A4Document!

Converting it to an PDF File you can see, opening it with AdobeAcrobat Reader doesn’t works.
open it with okular under Linux works, but the file is wrong!

I’m using Ubuntu x64 with JEE6u24 but It also doesn’t works on a Windows machine.

Can you help me?
The problem is we have to go in production as soon as possible, and so If you can help me with the 10.0.0 Version which should released in april we are very happy.
It’s also possible I do something wrong in the code with Aspose!!!

thx
Michael

Hi Michael,

Thank you for additional information. But I cannot reproduce the problem with DOC on my side. Image looks perfectly in the generated DOC file. Most probably the problem occur on your side because different screen resolution.

Have you tried explicitly specifying size of an image when you insert it into the document? If you will specify size of shape instead of resizing your image, you will be able completely avoid these complex image manipulations. You will need to know only original size of the image and size of the container. I created a simple code example for you:

@Test
public void Test001() throws Exception
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.getPageSetup().setPaperSize(PaperSize.A_4);

    //Read image from file to Image object
    BufferedImage img = ImageIO.read(new File("C:\\Temp\\Image.jpg"));
    SizeD size = CalculateImageSize(builder, img);
    Shape shp = builder.insertImage(img, RelativeHorizontalPosition.PAGE, 0, RelativeVerticalPosition.PAGE, 0, size.getWidth(), size.getHeight(), WrapType.NONE);

    shp.setVerticalAlignment(VerticalAlignment.CENTER);
    shp.setHorizontalAlignment(HorizontalAlignment.CENTER);

    //Save document
    doc.save("C:\\Temp\\out.doc");
    doc.save("C:\\Temp\\out.pdf");
}


///
/// Calculates size of Image
///
/// DocumentBuilder is used to determine Height and Width of current Page
/// Original image
private SizeD CalculateImageSize(DocumentBuilder builder, BufferedImage img)
{
    double targetHeight;
    double targetWidth;

    //Calculate width and height of the page
    PageSetup ps = builder.getCurrentSection().getPageSetup();
    targetHeight = ps.getPageHeight();
    targetWidth = ps.getPageWidth();

    //Get size of an image
    double imgHeight = ConvertUtil.pixelToPoint(img.getHeight());
    double imgWidth = ConvertUtil.pixelToPoint(img.getWidth());

    if (imgHeight < targetHeight && imgWidth < targetWidth)
    {
        targetHeight = imgHeight;
        targetWidth = imgWidth;
    }
    else
    {
        //Calculate size of an image in the document
        double ratioWidth = imgWidth / targetWidth;
        double ratioHeight = imgHeight / targetHeight;

        if (ratioWidth > ratioHeight)
            targetHeight = (targetHeight * (ratioHeight / ratioWidth));
        else
            targetWidth = (targetWidth * (ratioWidth / ratioHeight));
    }

    return new SizeD(targetWidth, targetHeight);
}

private class SizeD
{
    public SizeD(double widht, double height)
    {
        mWidth = widht;
        mHeight = height;
    }

    public double getWidth()
    {
        return mWidth;
    }

    public double getHeight()
    {
        return mHeight;
    }
}

Hope this helps.

Best regards,

Yeah I know about that method, but I tested It and don’t works for me …

I’ll try it again with your code!

Can you send me the .doc and .pdf file you created with my code on your machine?

wich jvm do you use?

thx for now

Hi
Thanks for your request. I use java version “1.6.0_24”. I attached DOC and PDF documents produced on my side using your code (PDF is still corrupted).
Best regards,

Your DOC also is corrupted, in the JPG file you can see on the top the number 533/08 in your doc as in my doc the number isn’t there.

If I produce the document with the old Aspose Versione the DOC is right, but the PDF File has got the same problem!

You wrote … you can’t reproduce the issue, but that’s the same thing.

Should I test your code? Does it works for you?

Your DOC also is corrupted, in the JPG file you can see on the top the number 533/08 in your doc as in my doc the number isn’t there.

If I produce the document with the old Aspose Versione the DOC is right, but the PDF File has got the same problem!

You wrote … you can’t reproduce the issue, but that’s the same thing as my problem is.

Should I test your code? Does it works for you?

Hi Michael,
Yes, now I can see, I just did not notice this. In this case, problem occurs because height of the image is larger than size of page. Please try specifying size of shape explicitly in the code, this should resolve the problem.
I also attached documents produced by my code here. Both DOC and PDF seems to look ok, but size of document is quite large. Most likely because large image.
Best regards,

The issues you have found earlier (filed as 26263) have been fixed in this .NET update and in this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.