PDF to HTML result is too small

I am converting PDF files to HTML and the output result is too small. Meaning that when displayed in the browser, the fonts are smaller than are comfortable, and I have a lot of extra real estate on the screen. I’d like to provide some kind of a scale factor to increase the size by 1.25, or 1.5x so that the result is more readable. I am embedding this content in another webpage, so I do not want the user of my application to be scaling up the size using the browser’s Zoom In/ Zoom Out functionality.

Is there functionality in Aspose PDF (for Java) that allows me to control the conversion size ratio?

@mangr3n

Could you please share a sample PDF document with us. We will further test the scenario in our environment and address it accordingly.

That feels like a bit of overkill, the question is pretty straightforward.

And after poking around, the solution is non-obvious but is hinted at by another answer here on the forum for the .NET API. It’s this line

doc.setOpenAction(new GoToAction(new XYZExplicitDestination(1, 0, 0, 0.5)));

and here’s the complete function.

public static String toHtml(String inputFilePath) {
    String tName = "FromPdf.toHtml";
    Timers.start(tName);
    String outputFilePath = inputFilePath + ".html";
    Document doc = new Document(inputFilePath);
    doc.setOpenAction(new GoToAction(new XYZExplicitDestination(1, 0, 0, 0.5)));

    HtmlSaveOptions newOptions = new HtmlSaveOptions(HtmlDocumentType.Html5, true);
    newOptions.CssClassNamesPrefix = "aspose_";
    newOptions.PageBorderIfAny = getPageBorder();
    newOptions.AntialiasingProcessing = AntialiasingProcessingType.NoAdditionalProcessing;
    newOptions.RasterImagesSavingMode = 
        RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
    newOptions.FontSavingMode = FontSavingModes.AlwaysSaveAsWOFF;
    newOptions.PartsEmbeddingMode = PartsEmbeddingModes.EmbedCssOnly;
    newOptions.LettersPositioningMethod = 
        LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;

    doc.save(outputFilePath, newOptions);
    Timers.log(logger, tName, inputFilePath);
    return outputFilePath;
}

The final Argument of the constructor for XYZExplicitDestination is a Zoom factor. A value less than 1 makes it bigger, whereas values larger than 1 make the output smaller.

@mangr3n

We apologize if our previous response felt unpleasant. However, please note that we try our best to test the scenario and address it with the files provided by our customers because, every PDF file has different structure and complexity.

Nevertheless, we have tested the scenario with one of our sample PDF documents and noticed the similar behavior that you have mentioned. We are afraid that there is no direct way to set/increase font size while converting PDF to HTML. The method you found in other discussions over forum, is used to set zoom factor inside a PDF document.

Furthermore, an investigation ticket as PDFJAVA-38552 has been logged in our issue tracking system to look deep into this matter. We will definitely investigate your requirements in details and as soon as we have definite updates regarding ticket resolution, we will let you know. Please spare us little time.

We are sorry for the inconvenience.

So, “zoom factor inside a PDF document”. Does this mean that it doesn’t actually change the size of the resulting output? And the “zoom factor” isn’t well documented. There should be some kind of text explanation of a value like 0.5 = 50% of the original size. Or 1.5 = 150% of the original size.
If it’s “zoom factor inside a PDF document” what does that mean? Is that zooming into a region of the document, but keeping the resulting output dimensions the same? Meaning that I could somehow output only the bottom left quadrant of the document but have it render at 2x the original size?

@mangr3n

Setting Zoom-Factors allows PDF viewers to display PDF with specified zoom value. The Parameter which is used for zoom value corresponds to 100% if set to 1. Decreasing and increasing value will change zoom percentage accordingly e.g. 0.5 = 50% and 1.5 = 150%.

Thanks for highlighting this missing information. We will surely take care of your concerns and will add this information in API references as well as API documentation.

The zooming is only related to PDF viewers, as shared above. However, if you want to resize PDF content, you can use PdfFileEditor.resizeContents() method before converting it into HTML. Please try to use following code snippet:

Document doc = new Document(dataDir + "sample.pdf");
PdfFileEditor fileEditor = new PdfFileEditor();
int scaleFactor = 2;
PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
PdfFileEditor.ContentsResizeValue.percents(scaleFactor * 0), // Left margin
PdfFileEditor.ContentsResizeValue.percents(scaleFactor * 100), // Width
PdfFileEditor.ContentsResizeValue.percents(scaleFactor * 0), // Right margin
PdfFileEditor.ContentsResizeValue.percents(scaleFactor * 0), // Top margin 
PdfFileEditor.ContentsResizeValue.percents(scaleFactor * 100), // Height
PdfFileEditor.ContentsResizeValue.percents(scaleFactor * 0));  // Bottom margin

fileEditor.resizeContents(doc, parameters);

HtmlSaveOptions newOptions = new HtmlSaveOptions(HtmlDocumentType.Html5, true);
newOptions.CssClassNamesPrefix = "aspose_";
newOptions.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
doc.save(dataDir + "sample.html", newOptions);

In case you need further assistance, please feel free to let us know.